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, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, IntervalCO, Mod, Mult, Real, Round, e, four, frac, greater, i, one, pi, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, normalized_var_ket_u, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, s_ket_domain, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
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 = [var_ket_u], instance_expr = Forall(instance_param_or_params = [phase], instance_expr = greater(Prob(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(Mod(Round(Mult(two_pow_t, phase)), two_pow_t), 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)]))), frac(four, Exp(pi, two))), domain = Real, conditions = [InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), var_ket_u))]).with_wrapping(), domain = s_ket_domain, condition = normalized_var_ket_u).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_{\lvert u \rangle \in \mathbb{C}^{2^{s}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\left[\begin{array}{l}\forall_{\varphi \in \mathbb{R}~|~\varphi \in \left[0,1\right), \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \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 round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) > \frac{4}{\pi^{2}}\right)\end{array}\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: 6
operand: 2
1ExprTuple2
2Lambdaparameter: 130
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 22
operands: 8
6Literal
7ExprTuple9
8ExprTuple10, 11
9Lambdaparameter: 154
body: 13
10Operationoperator: 40
operands: 14
11Operationoperator: 42
operands: 15
12ExprTuple154
13Conditionalvalue: 16
condition: 17
14ExprTuple130, 18
15ExprTuple19, 143
16Operationoperator: 20
operands: 21
17Operationoperator: 22
operands: 23
18Operationoperator: 24
operands: 25
19Operationoperator: 26
operand: 130
20Literal
21ExprTuple28, 29
22Literal
23ExprTuple30, 31, 32
24Literal
25ExprTuple33, 34
26Literal
27ExprTuple130
28Operationoperator: 35
operands: 36
29Operationoperator: 37
operand: 47
30Operationoperator: 40
operands: 39
31Operationoperator: 40
operands: 41
32Operationoperator: 42
operands: 43
33Literal
34Operationoperator: 155
operands: 44
35Literal
36ExprTuple45, 46
37Literal
38ExprTuple47
39ExprTuple154, 48
40Literal
41ExprTuple154, 49
42Literal
43ExprTuple50, 51
44ExprTuple157, 144
45Literal
46Operationoperator: 155
operands: 52
47Operationoperator: 53
operands: 54
48Literal
49Operationoperator: 55
operands: 56
50Operationoperator: 57
operands: 58
51Operationoperator: 59
operands: 60
52ExprTuple103, 157
53Literal
54ExprTuple61, 62, 63, 64
55Literal
56ExprTuple65, 143
57Literal
58ExprTuple141, 130
59Literal
60ExprTuple66, 130
61ExprTuple67, 68
62ExprTuple69, 70
63ExprTuple71, 72
64ExprTuple73, 74
65Literal
66Operationoperator: 155
operands: 75
67ExprRangelambda_map: 76
start_index: 143
end_index: 158
68ExprRangelambda_map: 77
start_index: 143
end_index: 144
69ExprRangelambda_map: 78
start_index: 143
end_index: 158
70ExprRangelambda_map: 78
start_index: 132
end_index: 133
71ExprRangelambda_map: 79
start_index: 143
end_index: 158
72ExprRangelambda_map: 80
start_index: 143
end_index: 144
73ExprRangelambda_map: 81
start_index: 143
end_index: 158
74ExprRangelambda_map: 82
start_index: 143
end_index: 144
75ExprTuple83, 84
76Lambdaparameter: 131
body: 85
77Lambdaparameter: 131
body: 86
78Lambdaparameter: 131
body: 87
79Lambdaparameter: 131
body: 88
80Lambdaparameter: 131
body: 89
81Lambdaparameter: 131
body: 90
82Lambdaparameter: 131
body: 92
83Literal
84Operationoperator: 151
operands: 93
85Operationoperator: 117
operands: 94
86Operationoperator: 101
operands: 95
87Operationoperator: 101
operands: 96
88Operationoperator: 97
operands: 98
89Operationoperator: 118
operands: 99
90Operationoperator: 101
operands: 100
91ExprTuple131
92Operationoperator: 101
operands: 102
93ExprTuple157, 103, 104, 154
94NamedExprsstate: 105
95NamedExprselement: 106
targets: 114
96NamedExprselement: 107
targets: 108
97Literal
98NamedExprsbasis: 109
99NamedExprsoperation: 110
100NamedExprselement: 111
targets: 112
101Literal
102NamedExprselement: 113
targets: 114
103Literal
104Literal
105Operationoperator: 115
operand: 127
106Operationoperator: 117
operands: 124
107Operationoperator: 118
operands: 119
108Operationoperator: 125
operands: 120
109Literal
110Literal
111Operationoperator: 123
operands: 121
112Operationoperator: 125
operands: 122
113Operationoperator: 123
operands: 124
114Operationoperator: 125
operands: 126
115Literal
116ExprTuple127
117Literal
118Literal
119NamedExprsoperation: 128
part: 131
120ExprTuple143, 133
121NamedExprsstate: 129
part: 131
122ExprTuple143, 158
123Literal
124NamedExprsstate: 130
part: 131
125Literal
126ExprTuple132, 133
127Literal
128Operationoperator: 134
operands: 135
129Operationoperator: 136
operands: 137
130Variable
131Variable
132Operationoperator: 139
operands: 138
133Operationoperator: 139
operands: 140
134Literal
135ExprTuple141, 158
136Literal
137ExprTuple142, 158
138ExprTuple158, 143
139Literal
140ExprTuple158, 144
141Variable
142Operationoperator: 145
operands: 146
143Literal
144Variable
145Literal
146ExprTuple147, 153
147Operationoperator: 148
operand: 150
148Literal
149ExprTuple150
150Operationoperator: 151
operands: 152
151Literal
152ExprTuple153, 154
153Operationoperator: 155
operands: 156
154Variable
155Literal
156ExprTuple157, 158
157Literal
158Variable