Qubits ​
Qubits are the fundamental unit of quantum information. Unlike classical bits that are either 0 or 1, qubits can exist in a superposition of both states.
Creating Qubits ​
Use qubit() to create a single qubit, or qubits(n) to create multiple:
Qubits as Linear Types ​
In Kettle, qubits are linear types. This means each qubit must be used exactly once - you cannot copy it or forget about it.
This design enforces the no-cloning theorem from quantum physics: it's impossible to create an exact copy of an unknown quantum state. Kettle catches violations at compile time:
The correct approach - use each qubit exactly once:
Why Linearity Matters ​
Linear types provide three guarantees:
- No accidental cloning - The no-cloning theorem is enforced by the compiler
- No forgotten qubits - Every qubit must be measured or explicitly discarded
- Clear resource tracking - You always know which qubits are still "live"
If you need to discard a qubit without measuring it, use discard():
Initial State ​
Qubits always start in the |0> state. To initialize a qubit to |1>, apply the pauli_x gate: