#Welcome to Qubit JS
Simulating qubits in JavaScript. Live example.
#Usage
var qubitSystem = _qubit.systemWithNewQubits(3);
console.log(qubitSystem.toString());
// |000>
//This will apply a Hadamard gate to qubits 1 and 3.
var qubits = [1, 3];
qubitSystem.applyHadamardGate(qubits);
console.log(qubitSystem.toString());
// 0.500 |000> + 0.500 |001> + 0.500 |100> + 0.500 |101>
//This will apply a Hadamard gate to all qubits.
qubitSystem.applyHadamardGate();
console.log(qubitSystem.toString());
// 0.354 |000> + 0.354 |001> + 0.354 |010> + 0.354 |011> + 0.354 |100> + 0.354 |101> + 0.354 |110> + 0.354 |111>
console.log(qubitSystem.toString());
// |000>
//This will apply an X Phase Shift gate to qubits 1 and 3.
var qubits = [1, 3];
qubitSystem.applyXPhaseShiftGate(qubits);
console.log(qubitSystem.toString());
// |101>
console.log(qubitSystem.toString());
// |000>
//This will apply an X Phase Shift gate to all qubits.
qubitSystem.applyXPhaseShiftGate();
console.log(qubitSystem.toString());
// |111>
console.log(qubitSystem.toString());
// 0.354 |000> + 0.354 |001> + 0.354 |010> + 0.354 |011> + 0.354 |100> + 0.354 |101> + 0.354 |110> + 0.354 |111>
//This will apply a Z Phase Shift gate to qubits 1 and 3.
var qubits = [1, 3];
qubitSystem.applyZPhaseShiftGate(qubits);
console.log(qubitSystem.toString());
// 0.354 |000> + -0.354 |001> + 0.354 |010> + -0.354 |011> + -0.354 |100> + 0.354 |101> + -0.354 |110> + 0.354 |111>
console.log(qubitSystem.toString());
// 0.354 |000> + 0.354 |001> + 0.354 |010> + 0.354 |011> + 0.354 |100> + 0.354 |101> + 0.354 |110> + 0.354 |111>
//This will apply a Z Phase Shift gate to all qubits.
qubitSystem.applyZPhaseShiftGate();
console.log(qubitSystem.toString());
// 0.354 |000> + -0.354 |001> + -0.354 |010> + 0.354 |011> + -0.354 |100> + 0.354 |101> + 0.354 |110> + -0.354 |111>
console.log(qubitSystem.toString());
// 0.354 |000> + 0.354 |001> + 0.354 |010> + 0.354 |011> + 0.354 |100> + 0.354 |101> + 0.354 |110> + 0.354 |111>
// This will measure qubits 1 and 3.
var qubits = [1, 3];
qubitSystem.measure(qubits);
console.log(qubitSystem.toString());
// 0.707 |000> + 0.707 |010>
console.log(qubitSystem.toString());
// 0.354 |000> + 0.354 |001> + 0.354 |010> + 0.354 |011> + 0.354 |100> + 0.354 |101> + 0.354 |110> + 0.354 |111>
// This will measure all of your qubits.
qubitSystem.measure();
console.log(qubitSystem.toString());
// |100>
console.log(qubitSystem.toString());
// |000>
qubitSystem.runGroversAlgorithm("011");
console.log(qubitSystem.toString());
// -0.088 |000> + -0.088 |001> + -0.088 |010> + 0.972 |011> + -0.088 |100> + -0.088 |101> + -0.088 |110> + -0.088 |111>
Qubit JS uses the Math.js library.