|q⟩ Bad Qubits

beginner · Programming · Bits, Logic & Classical Computation

Logic Gates as Functions

A logic gate is just a deterministic function: the same inputs always produce the same output. NOT is a function of one bit; AND, OR, and XOR are functions of two bits. Thinking of gates as functions is the right mindset for quantum gates too — except quantum gates are functions that must be reversible and act on amplitudes, not just bits.

XOR (exclusive or, written \oplus) outputs 1 exactly when its inputs differ: 00=00\oplus0=0, 01=10\oplus1=1, 10=11\oplus0=1, 11=01\oplus1=0. It is the classical cousin of the quantum CNOT gate you will meet later.

Try it

Return 101 \oplus 0 (use JavaScript's ^ operator).

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.