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, ExprRange, ExprTuple, Lambda, Variable, VertExprArray, l, m
from proveit.logic import And, Bijections, InSet
from proveit.numbers import Add, Interval, Mod, one
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import ModAdd, QPE, _Omega, _U, _b_floor, _full_domain, _ket_u, _m_domain, _phase_est_circuit, _s, _s_wire, _t, _two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(_t, one)
sub_expr3 = Add(_t, _s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = ExprTuple(And(InSet(Lambda(l, Mod(Add(_b_floor, l), _two_pow_t)), Bijections(_full_domain, _m_domain)), InSet(Lambda(m, _phase_est_circuit), Bijections(_m_domain, _Omega))), InSet(Lambda(l, Conditional(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, _t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, _t), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(ModAdd(_b_floor, l), _t), part = sub_expr1), targets = Interval(one, _t)), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)])), InSet(l, _full_domain))), Bijections(_full_domain, _Omega)))
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(\left[l \mapsto \left(\left(b_{\textit{f}} + l\right) ~\textup{mod}~ 2^{t}\right)\right] \in \left[\{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\} \xrightarrow[\text{onto}]{\text{1-to-1}} \{0~\ldotp \ldotp~2^{t} - 1\}\right]\right) \land \left(\left[m \mapsto \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)\right] \in \left[\{0~\ldotp \ldotp~2^{t} - 1\} \xrightarrow[\text{onto}]{\text{1-to-1}} \Omega\right]\right), \left[l \mapsto \left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array} \textrm{ if } l \in \{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\}\right..\right] \in \left[\{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\} \xrightarrow[\text{onto}]{\text{1-to-1}} \Omega\right]\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: 3
operands: 4
2Operationoperator: 28
operands: 5
3Literal
4ExprTuple6, 7
5ExprTuple8, 9
6Operationoperator: 28
operands: 10
7Operationoperator: 28
operands: 11
8Lambdaparameter: 145
body: 12
9Operationoperator: 25
operands: 13
10ExprTuple14, 15
11ExprTuple16, 17
12Conditionalvalue: 18
condition: 19
13ExprTuple37, 35
14Lambdaparameter: 145
body: 21
15Operationoperator: 25
operands: 22
16Lambdaparameter: 138
body: 24
17Operationoperator: 25
operands: 26
18Operationoperator: 32
operands: 27
19Operationoperator: 28
operands: 29
20ExprTuple145
21Operationoperator: 30
operands: 31
22ExprTuple37, 34
23ExprTuple138
24Operationoperator: 32
operands: 33
25Literal
26ExprTuple34, 35
27ExprTuple39, 40, 41, 36
28Literal
29ExprTuple145, 37
30Literal
31ExprTuple38, 76
32Literal
33ExprTuple39, 40, 41, 42
34Operationoperator: 113
operands: 43
35Literal
36ExprTuple44, 53
37Operationoperator: 113
operands: 45
38Operationoperator: 135
operands: 141
39ExprTuple46, 47
40ExprTuple48, 49
41ExprTuple50, 51
42ExprTuple52, 53
43ExprTuple54, 55
44ExprRangelambda_map: 56
start_index: 148
end_index: 142
45ExprTuple57, 102
46ExprRangelambda_map: 58
start_index: 148
end_index: 142
47ExprRangelambda_map: 59
start_index: 148
end_index: 139
48ExprRangelambda_map: 60
start_index: 148
end_index: 142
49ExprRangelambda_map: 60
start_index: 123
end_index: 124
50ExprRangelambda_map: 61
start_index: 148
end_index: 142
51ExprRangelambda_map: 62
start_index: 148
end_index: 139
52ExprRangelambda_map: 63
start_index: 148
end_index: 142
53ExprRangelambda_map: 64
start_index: 148
end_index: 139
54Literal
55Operationoperator: 135
operands: 65
56Lambdaparameter: 122
body: 66
57Operationoperator: 135
operands: 67
58Lambdaparameter: 122
body: 68
59Lambdaparameter: 122
body: 69
60Lambdaparameter: 122
body: 70
61Lambdaparameter: 122
body: 71
62Lambdaparameter: 122
body: 72
63Lambdaparameter: 122
body: 73
64Lambdaparameter: 122
body: 75
65ExprTuple76, 143
66Operationoperator: 86
operands: 77
67ExprTuple78, 148
68Operationoperator: 105
operands: 79
69Operationoperator: 86
operands: 80
70Operationoperator: 86
operands: 81
71Operationoperator: 82
operands: 83
72Operationoperator: 106
operands: 84
73Operationoperator: 86
operands: 85
74ExprTuple122
75Operationoperator: 86
operands: 87
76Operationoperator: 116
operands: 88
77NamedExprselement: 89
targets: 98
78Operationoperator: 146
operand: 102
79NamedExprsstate: 91
80NamedExprselement: 92
targets: 100
81NamedExprselement: 93
targets: 94
82Literal
83NamedExprsbasis: 95
84NamedExprsoperation: 96
85NamedExprselement: 97
targets: 98
86Literal
87NamedExprselement: 99
targets: 100
88ExprTuple126, 142
89Operationoperator: 111
operands: 101
90ExprTuple102
91Operationoperator: 103
operand: 118
92Operationoperator: 105
operands: 112
93Operationoperator: 106
operands: 107
94Operationoperator: 113
operands: 108
95Literal
96Literal
97Operationoperator: 111
operands: 109
98Operationoperator: 113
operands: 110
99Operationoperator: 111
operands: 112
100Operationoperator: 113
operands: 114
101NamedExprsstate: 115
part: 122
102Operationoperator: 116
operands: 117
103Literal
104ExprTuple118
105Literal
106Literal
107NamedExprsoperation: 119
part: 122
108ExprTuple148, 124
109NamedExprsstate: 120
part: 122
110ExprTuple148, 142
111Literal
112NamedExprsstate: 121
part: 122
113Literal
114ExprTuple123, 124
115Operationoperator: 130
operands: 125
116Literal
117ExprTuple126, 127
118Literal
119Operationoperator: 128
operands: 129
120Operationoperator: 130
operands: 131
121Literal
122Variable
123Operationoperator: 135
operands: 132
124Operationoperator: 135
operands: 133
125ExprTuple134, 142
126Literal
127Operationoperator: 135
operands: 136
128Literal
129ExprTuple137, 142
130Literal
131ExprTuple138, 142
132ExprTuple142, 148
133ExprTuple142, 139
134Operationoperator: 140
operands: 141
135Literal
136ExprTuple142, 143
137Literal
138Variable
139Literal
140Literal
141ExprTuple144, 145
142Literal
143Operationoperator: 146
operand: 148
144Literal
145Variable
146Literal
147ExprTuple148
148Literal