swapTest: swapTest

Description Usage Arguments Value Examples

View source: R/swapTest.R

Description

Encodes absolute square of inner product of two states, |<a|b>|^2, into an ancilliary qubit. It swaps the states of |a> and |b> conditioned on the ancilla which results in a state where the probability of measuring the ancilla qubit in the 0 state is equal to 1/2 - 1/2*(|<a|b>|^2). The ancilla qubit is inserted before qubit index 0, as the most significant qubit. Full explanation can be found in "Supervised Learning with Quantum Computers" <DOI:10.1007/978-3-319-96424-9>.

Usage

1
swapTest(v,a,b)

Arguments

v

Ket (column vector) that swap test is applied to. Should be a tensor product of two quantum state.

a

Vector of indices of |a> within v

b

Vector of indices of |b> within v

Value

Ket which contains the modified input ket, v, along with a leading ancillary qubit.

Examples

1
2
 swapTest(intket(3,4),a=0:1,b=2:3)
 swapTest(intket(5,4),a=0:1,b=2:3)

QuantumOps documentation built on Feb. 3, 2020, 5:07 p.m.