logo

Expression of type Qcircuit

from the theory of proveit.physics.quantum.QPE

In [1]:
import proveit
# Automation is not needed when building an expression:
proveit.defaults.automation = False # This will speed things up.
proveit.defaults.inline_pngs = False # Makes files smaller.
%load_expr # Load the stored expression as 'stored_expr'
# import Expression classes needed to build the expression
from proveit import ExprRange, Variable, VertExprArray, t
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _ket_u, _phase, _s
from proveit.physics.quantum.circuits import MultiQubitElem, Output, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))), Add(Neg(t), one), zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(Add(t, one), Add(t, _s))), one, _s)]))
expr:
In [3]:
# check that the built expression is the same as the stored expression
assert expr == stored_expr
assert expr._style_id == stored_expr._style_id
print("Passed sanity check: expr matches stored_expr")
Passed sanity check: expr matches stored_expr
In [4]:
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 1} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
& \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 2} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
& \qout{\vdots} \\
& \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{0} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
& \qout{\lvert u \rangle}
} \end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
spacingchange the spacing of a circuit using the format '@C=1em @R=.7em' where C is the column spacing and R is the row spacing@C=1em @R=.7em@C=1em @R=.7em
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3ExprTuple4, 5
4ExprRangelambda_map: 6
start_index: 7
end_index: 46
5ExprRangelambda_map: 8
start_index: 56
end_index: 40
6Lambdaparameter: 69
body: 9
7Operationoperator: 34
operands: 10
8Lambdaparameter: 69
body: 11
9Operationoperator: 21
operands: 12
10ExprTuple13, 56
11Operationoperator: 14
operands: 15
12NamedExprsstate: 16
13Operationoperator: 67
operand: 39
14Literal
15NamedExprselement: 18
targets: 19
16Operationoperator: 43
operands: 20
17ExprTuple39
18Operationoperator: 21
operands: 22
19Operationoperator: 23
operands: 24
20ExprTuple25, 26
21Literal
22NamedExprsstate: 27
part: 69
23Literal
24ExprTuple28, 29
25Operationoperator: 49
operands: 30
26Operationoperator: 31
operands: 32
27Literal
28Operationoperator: 34
operands: 33
29Operationoperator: 34
operands: 35
30ExprTuple56, 36
31Literal
32ExprTuple37, 38
33ExprTuple39, 56
34Literal
35ExprTuple39, 40
36Operationoperator: 63
operands: 41
37Operationoperator: 52
operand: 46
38Operationoperator: 43
operands: 44
39Variable
40Literal
41ExprTuple65, 45
42ExprTuple46
43Literal
44ExprTuple47, 48
45Operationoperator: 49
operands: 50
46Literal
47Operationoperator: 63
operands: 51
48Operationoperator: 52
operand: 56
49Literal
50ExprTuple56, 65
51ExprTuple54, 55
52Literal
53ExprTuple56
54Literal
55Operationoperator: 57
operands: 58
56Literal
57Literal
58ExprTuple65, 59, 60, 61, 62
59Literal
60Literal
61Operationoperator: 63
operands: 64
62Literal
63Literal
64ExprTuple65, 66
65Literal
66Operationoperator: 67
operand: 69
67Literal
68ExprTuple69
69Variable