logo

Expression of type ExprTuple

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 Conditional, ConditionalSet, ExprRange, ExprTuple, Variable, VertExprArray, t
from proveit.linear_algebra import MatrixExp, ScalarMult, VecAdd
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import CONTROL, ket0, ket1, ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _phase, _s
from proveit.physics.quantum.circuits import Gate, Igate, Input, MultiQubitElem, Output, Qcircuit, QcircuitEquiv
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr2 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr3 = Add(t, one)
sub_expr4 = Add(sub_expr1, t)
sub_expr5 = Add(t, _s)
sub_expr6 = Interval(sub_expr3, sub_expr5)
sub_expr7 = Add(Neg(t), one)
sub_expr8 = MultiQubitElem(element = Gate(operation = QPE1(_U, t), part = sub_expr2), targets = Interval(one, sub_expr5))
sub_expr9 = [ExprRange(sub_expr2, sub_expr8, one, t), ExprRange(sub_expr2, sub_expr8, sub_expr3, sub_expr5)]
sub_expr10 = [ExprRange(sub_expr2, Input(state = ket_plus), one, t), ExprRange(sub_expr2, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr2), targets = sub_expr6), one, _s)]
sub_expr11 = ExprRange(sub_expr1, [ExprRange(sub_expr2, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr4, sub_expr2)), Conditional(Igate, NotEquals(sub_expr4, sub_expr2))), one, t).with_case_simplification(), ExprRange(sub_expr2, MultiQubitElem(element = Gate(operation = MatrixExp(_U, Exp(two, Neg(sub_expr1))), part = sub_expr2), targets = sub_expr6), one, _s)], sub_expr7, zero).with_decreasing_order()
sub_expr12 = [ExprRange(sub_expr2, Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr2)), _phase)), ket1)))), sub_expr7, zero).with_decreasing_order(), ExprRange(sub_expr2, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr2), targets = sub_expr6), one, _s)]
expr = ExprTuple(QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray(sub_expr11)), Qcircuit(vert_expr_array = VertExprArray(sub_expr9))), QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray(sub_expr10, sub_expr11, sub_expr12)), Qcircuit(vert_expr_array = VertExprArray(sub_expr10, sub_expr9, sub_expr12))).with_wrapping_at(1))
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())
\left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qw \\
& \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qw \\
& \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}_1\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw
} \end{array}\right), \begin{array}{c} \begin{array}{l} \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \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)} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \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)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \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)} \\
\qin{\lvert u \rangle} & \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & \qout{\lvert u \rangle}
} \end{array}\right) \\  \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \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)} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\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)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \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)} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\lvert u \rangle}
} \end{array}\right) \end{array} \end{array}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 4
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9
6Operationoperator: 13
operands: 10
7Operationoperator: 13
operand: 17
8Operationoperator: 13
operands: 12
9Operationoperator: 13
operands: 14
10ExprTuple15
11ExprTuple17
12ExprTuple16, 15, 18
13Literal
14ExprTuple16, 17, 18
15ExprRangelambda_map: 19
start_index: 31
end_index: 119
16ExprTuple20, 21
17ExprTuple22, 23
18ExprTuple24, 25
19Lambdaparameter: 139
body: 26
20ExprRangelambda_map: 27
start_index: 135
end_index: 134
21ExprRangelambda_map: 28
start_index: 135
end_index: 117
22ExprRangelambda_map: 29
start_index: 135
end_index: 134
23ExprRangelambda_map: 29
start_index: 122
end_index: 97
24ExprRangelambda_map: 30
start_index: 31
end_index: 119
25ExprRangelambda_map: 32
start_index: 135
end_index: 117
26ExprTuple33, 34
27Lambdaparameter: 150
body: 35
28Lambdaparameter: 150
body: 36
29Lambdaparameter: 150
body: 37
30Lambdaparameter: 150
body: 38
31Operationoperator: 129
operands: 39
32Lambdaparameter: 150
body: 40
33ExprRangelambda_map: 41
start_index: 135
end_index: 134
34ExprRangelambda_map: 42
start_index: 135
end_index: 117
35Operationoperator: 62
operands: 43
36Operationoperator: 89
operands: 44
37Operationoperator: 89
operands: 45
38Operationoperator: 66
operands: 46
39ExprTuple47, 135
40Operationoperator: 89
operands: 48
41Lambdaparameter: 150
body: 49
42Lambdaparameter: 150
body: 50
43NamedExprsstate: 51
44NamedExprselement: 52
targets: 71
45NamedExprselement: 53
targets: 54
46NamedExprsstate: 55
47Operationoperator: 148
operand: 134
48NamedExprselement: 57
targets: 71
49Operationoperator: 58
operands: 59
50Operationoperator: 89
operands: 60
51Operationoperator: 127
operand: 72
52Operationoperator: 62
operands: 67
53Operationoperator: 92
operands: 63
54Operationoperator: 82
operands: 64
55Operationoperator: 110
operands: 65
56ExprTuple134
57Operationoperator: 66
operands: 67
58Literal
59ExprTuple68, 69
60NamedExprselement: 70
targets: 71
61ExprTuple72
62Literal
63NamedExprsoperation: 73
part: 150
64ExprTuple135, 97
65ExprTuple74, 75
66Literal
67NamedExprsstate: 76
part: 150
68Conditionalvalue: 77
condition: 78
69Conditionalvalue: 79
condition: 80
70Operationoperator: 92
operands: 81
71Operationoperator: 82
operands: 83
72Literal
73Operationoperator: 84
operands: 85
74Operationoperator: 124
operands: 86
75Operationoperator: 87
operands: 88
76Literal
77Operationoperator: 89
operands: 90
78Operationoperator: 91
operands: 95
79Operationoperator: 92
operands: 93
80Operationoperator: 94
operands: 95
81NamedExprsoperation: 96
part: 150
82Literal
83ExprTuple122, 97
84Literal
85ExprTuple115, 134
86ExprTuple135, 98
87Literal
88ExprTuple99, 100
89Literal
90NamedExprselement: 101
targets: 102
91Literal
92Literal
93NamedExprsoperation: 103
94Literal
95ExprTuple104, 150
96Operationoperator: 105
operands: 106
97Operationoperator: 129
operands: 107
98Operationoperator: 144
operands: 108
99Operationoperator: 127
operand: 119
100Operationoperator: 110
operands: 111
101Literal
102Operationoperator: 112
operand: 122
103Literal
104Operationoperator: 129
operands: 114
105Literal
106ExprTuple115, 116
107ExprTuple134, 117
108ExprTuple146, 118
109ExprTuple119
110Literal
111ExprTuple120, 121
112Literal
113ExprTuple122
114ExprTuple139, 134
115Literal
116Operationoperator: 144
operands: 123
117Literal
118Operationoperator: 124
operands: 125
119Literal
120Operationoperator: 144
operands: 126
121Operationoperator: 127
operand: 135
122Operationoperator: 129
operands: 130
123ExprTuple146, 131
124Literal
125ExprTuple135, 146
126ExprTuple132, 133
127Literal
128ExprTuple135
129Literal
130ExprTuple134, 135
131Operationoperator: 148
operand: 139
132Literal
133Operationoperator: 137
operands: 138
134Variable
135Literal
136ExprTuple139
137Literal
138ExprTuple146, 140, 141, 142, 143
139Variable
140Literal
141Literal
142Operationoperator: 144
operands: 145
143Literal
144Literal
145ExprTuple146, 147
146Literal
147Operationoperator: 148
operand: 150
148Literal
149ExprTuple150
150Variable