truth-table: Method truth.table

Description Usage Arguments Details Value Examples

Description

Method truth.table

Usage

1
truth.table(e1, nbits, bits, ...)

Arguments

e1

gate to measure.

nbits

number of bits the gate acts on.

bits

optional vector of length nbits containing the qubit order in the gate.

...

additional parameters to passed be on to 'e1'

Details

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'.

Value

returns a data.frame containing the truth table. Each row corresponds to one input-output combination. Each column to one specific bit.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## 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)

qsimulatR documentation built on Jan. 13, 2021, 3:13 p.m.