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}")
sub_expr2 = Neg(t)
sub_expr3 = frac(one, sqrt(two))
expr = Qcircuit(vert_expr_array = VertExprArray([Output(state = ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(Add(sub_expr2, one))), _phase)), ket1)))), ExprRange(sub_expr1, Output(state = ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))), Add(sub_expr2, two), 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).with_wrapping_at(2,6)]))
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^{-\left(-t + 1\right)} \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{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 3} \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, 6
4Operationoperator: 25
operands: 7
5ExprRangelambda_map: 8
start_index: 9
end_index: 53
6ExprRangelambda_map: 10
start_index: 83
end_index: 45
7NamedExprsstate: 11
8Lambdaparameter: 84
body: 12
9Operationoperator: 79
operands: 13
10Lambdaparameter: 84
body: 14
11Operationoperator: 49
operands: 15
12Operationoperator: 25
operands: 16
13ExprTuple82, 77
14Operationoperator: 17
operands: 18
15ExprTuple30, 19
16NamedExprsstate: 20
17Literal
18NamedExprselement: 21
targets: 22
19Operationoperator: 37
operands: 23
20Operationoperator: 49
operands: 24
21Operationoperator: 25
operands: 26
22Operationoperator: 27
operands: 28
23ExprTuple43, 29
24ExprTuple30, 31
25Literal
26NamedExprsstate: 32
part: 84
27Literal
28ExprTuple33, 34
29Operationoperator: 49
operands: 35
30Operationoperator: 57
operands: 36
31Operationoperator: 37
operands: 38
32Literal
33Operationoperator: 79
operands: 39
34Operationoperator: 79
operands: 40
35ExprTuple41, 55
36ExprTuple83, 42
37Literal
38ExprTuple43, 44
39ExprTuple87, 83
40ExprTuple87, 45
41Operationoperator: 74
operands: 46
42Operationoperator: 74
operands: 47
43Operationoperator: 60
operand: 53
44Operationoperator: 49
operands: 50
45Literal
46ExprTuple63, 51
47ExprTuple77, 52
48ExprTuple53
49Literal
50ExprTuple54, 55
51Operationoperator: 66
operands: 56
52Operationoperator: 57
operands: 58
53Literal
54Operationoperator: 74
operands: 59
55Operationoperator: 60
operand: 83
56ExprTuple77, 69, 70, 62, 72
57Literal
58ExprTuple83, 77
59ExprTuple63, 64
60Literal
61ExprTuple83
62Operationoperator: 74
operands: 65
63Literal
64Operationoperator: 66
operands: 67
65ExprTuple77, 68
66Literal
67ExprTuple77, 69, 70, 71, 72
68Operationoperator: 85
operand: 76
69Literal
70Literal
71Operationoperator: 74
operands: 75
72Literal
73ExprTuple76
74Literal
75ExprTuple77, 78
76Operationoperator: 79
operands: 80
77Literal
78Operationoperator: 85
operand: 84
79Literal
80ExprTuple82, 83
81ExprTuple84
82Operationoperator: 85
operand: 87
83Literal
84Variable
85Literal
86ExprTuple87
87Variable