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, U, Variable, VertExprArray, eps, m, n, s, t
from proveit.logic import And, InSet
from proveit.numbers import Add, Ceil, Exp, Interval, LessEq, Log, ModAbs, Mult, NaturalPos, Neg, frac, greater_eq, one, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import ProbOfAll
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(Lambda(t, Conditional(greater_eq(ProbOfAll(instance_param_or_params = [m], instance_element = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_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), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)])), domain = Interval(zero, subtract(two_pow_t, one)), condition = LessEq(ModAbs(subtract(frac(m, two_pow_t), phase), one), Exp(two, Neg(n)))).with_wrapping(), subtract(one, eps)), And(InSet(t, NaturalPos), greater_eq(t, Add(n, Ceil(Log(two, Add(two, frac(one, Mult(two, eps)))))))))))
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(t \mapsto \left\{\left[\begin{array}{l}\textrm{Prob}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}~|~\left|\frac{m}{2^{t}} - \varphi\right|_{\textup{mod}\thinspace 1} \leq 2^{-n}}~\\
\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)\end{array}\right] \geq \left(1 - \epsilon\right) \textrm{ if } t \in \mathbb{N}^+ ,  t \geq \left(n + \left\lceil \textrm{log}_2\left(2 + \frac{1}{2 \cdot \epsilon}\right)\right\rceil\right)\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 155
body: 3
2ExprTuple155
3Conditionalvalue: 4
condition: 5
4Operationoperator: 51
operands: 6
5Operationoperator: 30
operands: 7
6ExprTuple8, 9
7ExprTuple10, 11
8Operationoperator: 143
operands: 12
9Operationoperator: 13
operand: 18
10Operationoperator: 49
operands: 15
11Operationoperator: 51
operands: 16
12ExprTuple150, 17
13Literal
14ExprTuple18
15ExprTuple155, 19
16ExprTuple20, 155
17Operationoperator: 134
operand: 147
18Lambdaparameter: 149
body: 23
19Literal
20Operationoperator: 143
operands: 24
21ExprTuple147
22ExprTuple149
23Conditionalvalue: 25
condition: 26
24ExprTuple122, 27
25Operationoperator: 28
operands: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operand: 40
28Literal
29ExprTuple34, 35, 36, 37
30Literal
31ExprTuple38, 39
32Literal
33ExprTuple40
34ExprTuple41, 42
35ExprTuple43, 44
36ExprTuple45, 46
37ExprTuple47, 48
38Operationoperator: 49
operands: 50
39Operationoperator: 51
operands: 52
40Operationoperator: 53
operands: 54
41ExprRangelambda_map: 55
start_index: 150
end_index: 155
42ExprRangelambda_map: 56
start_index: 150
end_index: 151
43ExprRangelambda_map: 57
start_index: 150
end_index: 155
44ExprRangelambda_map: 57
start_index: 129
end_index: 130
45ExprRangelambda_map: 58
start_index: 150
end_index: 155
46ExprRangelambda_map: 59
start_index: 150
end_index: 151
47ExprRangelambda_map: 60
start_index: 150
end_index: 155
48ExprRangelambda_map: 61
start_index: 150
end_index: 151
49Literal
50ExprTuple149, 62
51Literal
52ExprTuple63, 64
53Literal
54ExprTuple154, 65
55Lambdaparameter: 128
body: 66
56Lambdaparameter: 128
body: 67
57Lambdaparameter: 128
body: 68
58Lambdaparameter: 128
body: 69
59Lambdaparameter: 128
body: 70
60Lambdaparameter: 128
body: 71
61Lambdaparameter: 128
body: 73
62Operationoperator: 117
operands: 74
63Operationoperator: 75
operands: 76
64Operationoperator: 152
operands: 77
65Operationoperator: 143
operands: 78
66Operationoperator: 109
operands: 79
67Operationoperator: 86
operands: 80
68Operationoperator: 86
operands: 81
69Operationoperator: 82
operands: 83
70Operationoperator: 110
operands: 84
71Operationoperator: 86
operands: 85
72ExprTuple128
73Operationoperator: 86
operands: 87
74ExprTuple88, 89
75Literal
76ExprTuple90, 150
77ExprTuple154, 91
78ExprTuple154, 92
79NamedExprsstate: 93
80NamedExprselement: 94
targets: 102
81NamedExprselement: 95
targets: 96
82Literal
83NamedExprsbasis: 97
84NamedExprsoperation: 98
85NamedExprselement: 99
targets: 100
86Literal
87NamedExprselement: 101
targets: 102
88Literal
89Operationoperator: 143
operands: 103
90Operationoperator: 143
operands: 104
91Operationoperator: 134
operand: 122
92Operationoperator: 132
operands: 106
93Operationoperator: 107
operand: 124
94Operationoperator: 109
operands: 116
95Operationoperator: 110
operands: 111
96Operationoperator: 117
operands: 112
97Literal
98Literal
99Operationoperator: 115
operands: 113
100Operationoperator: 117
operands: 114
101Operationoperator: 115
operands: 116
102Operationoperator: 117
operands: 118
103ExprTuple145, 119
104ExprTuple120, 121
105ExprTuple122
106ExprTuple150, 123
107Literal
108ExprTuple124
109Literal
110Literal
111NamedExprsoperation: 125
part: 128
112ExprTuple150, 130
113NamedExprsstate: 126
part: 128
114ExprTuple150, 155
115Literal
116NamedExprsstate: 127
part: 128
117Literal
118ExprTuple129, 130
119Operationoperator: 134
operand: 150
120Operationoperator: 132
operands: 133
121Operationoperator: 134
operand: 146
122Variable
123Operationoperator: 136
operands: 137
124Literal
125Operationoperator: 138
operands: 139
126Operationoperator: 140
operands: 141
127Variable
128Variable
129Operationoperator: 143
operands: 142
130Operationoperator: 143
operands: 144
131ExprTuple150
132Literal
133ExprTuple149, 145
134Literal
135ExprTuple146
136Literal
137ExprTuple154, 147
138Literal
139ExprTuple148, 155
140Literal
141ExprTuple149, 155
142ExprTuple155, 150
143Literal
144ExprTuple155, 151
145Operationoperator: 152
operands: 153
146Variable
147Variable
148Variable
149Variable
150Literal
151Variable
152Literal
153ExprTuple154, 155
154Literal
155Variable