truth-table: Method truth.table

truth.tableR Documentation

Method truth.table

Description

Method truth.table

Usage

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

## 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 Oct. 16, 2023, 5:06 p.m.