logo

Expression of type Forall

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, U, Variable, VertExprArray, eps, m, n, s, t
from proveit.logic import Forall
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 = Forall(instance_param_or_params = [t], instance_expr = 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)), domain = NaturalPos, condition = greater_eq(t, Add(n, Ceil(Log(two, Add(two, frac(one, Mult(two, eps)))))))).with_wrapping()
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}{l}\forall_{t \in \mathbb{N}^+~|~t \geq \left(n + \left\lceil \textrm{log}_2\left(2 + \frac{1}{2 \cdot \epsilon}\right)\right\rceil\right)}~\\
\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)\right)\end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 157
body: 5
4ExprTuple157
5Conditionalvalue: 6
condition: 7
6Operationoperator: 53
operands: 8
7Operationoperator: 32
operands: 9
8ExprTuple10, 11
9ExprTuple12, 13
10Operationoperator: 145
operands: 14
11Operationoperator: 15
operand: 20
12Operationoperator: 51
operands: 17
13Operationoperator: 53
operands: 18
14ExprTuple152, 19
15Literal
16ExprTuple20
17ExprTuple157, 21
18ExprTuple22, 157
19Operationoperator: 136
operand: 149
20Lambdaparameter: 151
body: 25
21Literal
22Operationoperator: 145
operands: 26
23ExprTuple149
24ExprTuple151
25Conditionalvalue: 27
condition: 28
26ExprTuple124, 29
27Operationoperator: 30
operands: 31
28Operationoperator: 32
operands: 33
29Operationoperator: 34
operand: 42
30Literal
31ExprTuple36, 37, 38, 39
32Literal
33ExprTuple40, 41
34Literal
35ExprTuple42
36ExprTuple43, 44
37ExprTuple45, 46
38ExprTuple47, 48
39ExprTuple49, 50
40Operationoperator: 51
operands: 52
41Operationoperator: 53
operands: 54
42Operationoperator: 55
operands: 56
43ExprRangelambda_map: 57
start_index: 152
end_index: 157
44ExprRangelambda_map: 58
start_index: 152
end_index: 153
45ExprRangelambda_map: 59
start_index: 152
end_index: 157
46ExprRangelambda_map: 59
start_index: 131
end_index: 132
47ExprRangelambda_map: 60
start_index: 152
end_index: 157
48ExprRangelambda_map: 61
start_index: 152
end_index: 153
49ExprRangelambda_map: 62
start_index: 152
end_index: 157
50ExprRangelambda_map: 63
start_index: 152
end_index: 153
51Literal
52ExprTuple151, 64
53Literal
54ExprTuple65, 66
55Literal
56ExprTuple156, 67
57Lambdaparameter: 130
body: 68
58Lambdaparameter: 130
body: 69
59Lambdaparameter: 130
body: 70
60Lambdaparameter: 130
body: 71
61Lambdaparameter: 130
body: 72
62Lambdaparameter: 130
body: 73
63Lambdaparameter: 130
body: 75
64Operationoperator: 119
operands: 76
65Operationoperator: 77
operands: 78
66Operationoperator: 154
operands: 79
67Operationoperator: 145
operands: 80
68Operationoperator: 111
operands: 81
69Operationoperator: 88
operands: 82
70Operationoperator: 88
operands: 83
71Operationoperator: 84
operands: 85
72Operationoperator: 112
operands: 86
73Operationoperator: 88
operands: 87
74ExprTuple130
75Operationoperator: 88
operands: 89
76ExprTuple90, 91
77Literal
78ExprTuple92, 152
79ExprTuple156, 93
80ExprTuple156, 94
81NamedExprsstate: 95
82NamedExprselement: 96
targets: 104
83NamedExprselement: 97
targets: 98
84Literal
85NamedExprsbasis: 99
86NamedExprsoperation: 100
87NamedExprselement: 101
targets: 102
88Literal
89NamedExprselement: 103
targets: 104
90Literal
91Operationoperator: 145
operands: 105
92Operationoperator: 145
operands: 106
93Operationoperator: 136
operand: 124
94Operationoperator: 134
operands: 108
95Operationoperator: 109
operand: 126
96Operationoperator: 111
operands: 118
97Operationoperator: 112
operands: 113
98Operationoperator: 119
operands: 114
99Literal
100Literal
101Operationoperator: 117
operands: 115
102Operationoperator: 119
operands: 116
103Operationoperator: 117
operands: 118
104Operationoperator: 119
operands: 120
105ExprTuple147, 121
106ExprTuple122, 123
107ExprTuple124
108ExprTuple152, 125
109Literal
110ExprTuple126
111Literal
112Literal
113NamedExprsoperation: 127
part: 130
114ExprTuple152, 132
115NamedExprsstate: 128
part: 130
116ExprTuple152, 157
117Literal
118NamedExprsstate: 129
part: 130
119Literal
120ExprTuple131, 132
121Operationoperator: 136
operand: 152
122Operationoperator: 134
operands: 135
123Operationoperator: 136
operand: 148
124Variable
125Operationoperator: 138
operands: 139
126Literal
127Operationoperator: 140
operands: 141
128Operationoperator: 142
operands: 143
129Variable
130Variable
131Operationoperator: 145
operands: 144
132Operationoperator: 145
operands: 146
133ExprTuple152
134Literal
135ExprTuple151, 147
136Literal
137ExprTuple148
138Literal
139ExprTuple156, 149
140Literal
141ExprTuple150, 157
142Literal
143ExprTuple151, 157
144ExprTuple157, 152
145Literal
146ExprTuple157, 153
147Operationoperator: 154
operands: 155
148Variable
149Variable
150Variable
151Variable
152Literal
153Variable
154Literal
155ExprTuple156, 157
156Literal
157Variable