truth.table | R Documentation |
Method truth.table
truth.table(e1, nbits, bits, ...)
e1 |
gate to measure. |
nbits |
number of bits the gate acts on. |
bits |
optional vector of length |
... |
additional parameters to passed be on to 'e1' |
calculates the quantum truth table of the gate e1
.
If a basis state is transformed to a superposition of basis states by
the gate, the result is 'NA'.
returns a data.frame containing the truth table. Each row corresponds to one input-output combination. Each column to one specific bit.
## truth table for a single bit gate
truth.table(X, 1)
## for a 2-bit gate
truth.table(CNOT, 2)
## for a 2-bit gate with reversed controll and target bits
truth.table(CNOT, bits=2:1)
## for a general controlled gate
truth.table(cqgate, 2, gate=H(2))
## for an arbitrary circuit (here a swap implementation using only CNOTs)
myswap <- function(bits){ function(x){ CNOT(bits) * (CNOT(rev(bits)) * (CNOT(bits) * x))}}
truth.table(myswap, 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.