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, Unitary
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, Mult, Real, e, i, one, pi, subtract, 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_s, 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 = Mult(two_pow_t, phase)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Forall(instance_param_or_params = [U], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [phase], instance_expr = Equals(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_expr6, one, t), ExprRange(sub_expr1, sub_expr6, 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(sub_expr5, 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)]))), one), domain = Real, conditions = [InSet(sub_expr5, Interval(zero, subtract(two_pow_t, 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(), domain = Unitary(two_pow_s)).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_{U \in \textrm{U}\left(2^{s}\right)}~\\
\left[\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}~|~\left(2^{t} \cdot \varphi\right) \in \{0~\ldotp \ldotp~2^{t} - 1\}, \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\end{array}\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: 16
operand: 2
1ExprTuple2
2Lambdaparameter: 148
body: 4
3ExprTuple148
4Conditionalvalue: 5
condition: 6
5Operationoperator: 16
operand: 9
6Operationoperator: 46
operands: 8
7ExprTuple9
8ExprTuple148, 10
9Lambdaparameter: 137
body: 11
10Operationoperator: 12
operand: 42
11Conditionalvalue: 14
condition: 15
12Literal
13ExprTuple42
14Operationoperator: 16
operand: 19
15Operationoperator: 31
operands: 18
16Literal
17ExprTuple19
18ExprTuple20, 21
19Lambdaparameter: 155
body: 23
20Operationoperator: 46
operands: 24
21Operationoperator: 48
operands: 25
22ExprTuple155
23Conditionalvalue: 26
condition: 27
24ExprTuple137, 28
25ExprTuple29, 150
26Operationoperator: 48
operands: 30
27Operationoperator: 31
operands: 32
28Operationoperator: 33
operands: 34
29Operationoperator: 35
operand: 137
30ExprTuple37, 150
31Literal
32ExprTuple38, 39, 40
33Literal
34ExprTuple41, 42
35Literal
36ExprTuple137
37Operationoperator: 43
operand: 51
38Operationoperator: 46
operands: 45
39Operationoperator: 46
operands: 47
40Operationoperator: 48
operands: 49
41Literal
42Operationoperator: 156
operands: 50
43Literal
44ExprTuple51
45ExprTuple155, 52
46Literal
47ExprTuple149, 53
48Literal
49ExprTuple54, 55
50ExprTuple158, 151
51Operationoperator: 56
operands: 57
52Literal
53Operationoperator: 132
operands: 58
54Operationoperator: 59
operands: 60
55Operationoperator: 61
operands: 62
56Literal
57ExprTuple63, 64, 65, 66
58ExprTuple67, 68
59Literal
60ExprTuple148, 137
61Literal
62ExprTuple69, 137
63ExprTuple70, 71
64ExprTuple72, 73
65ExprTuple74, 75
66ExprTuple76, 77
67Literal
68Operationoperator: 146
operands: 78
69Operationoperator: 156
operands: 79
70ExprRangelambda_map: 80
start_index: 150
end_index: 159
71ExprRangelambda_map: 81
start_index: 150
end_index: 151
72ExprRangelambda_map: 82
start_index: 150
end_index: 159
73ExprRangelambda_map: 82
start_index: 139
end_index: 140
74ExprRangelambda_map: 83
start_index: 150
end_index: 159
75ExprRangelambda_map: 84
start_index: 150
end_index: 151
76ExprRangelambda_map: 85
start_index: 150
end_index: 159
77ExprRangelambda_map: 86
start_index: 150
end_index: 151
78ExprTuple154, 87
79ExprTuple88, 89
80Lambdaparameter: 138
body: 90
81Lambdaparameter: 138
body: 91
82Lambdaparameter: 138
body: 92
83Lambdaparameter: 138
body: 93
84Lambdaparameter: 138
body: 94
85Lambdaparameter: 138
body: 95
86Lambdaparameter: 138
body: 97
87Operationoperator: 98
operand: 150
88Literal
89Operationoperator: 152
operands: 100
90Operationoperator: 124
operands: 101
91Operationoperator: 108
operands: 102
92Operationoperator: 108
operands: 103
93Operationoperator: 104
operands: 105
94Operationoperator: 125
operands: 106
95Operationoperator: 108
operands: 107
96ExprTuple138
97Operationoperator: 108
operands: 109
98Literal
99ExprTuple150
100ExprTuple158, 110, 111, 155
101NamedExprsstate: 112
102NamedExprselement: 113
targets: 121
103NamedExprselement: 114
targets: 115
104Literal
105NamedExprsbasis: 116
106NamedExprsoperation: 117
107NamedExprselement: 118
targets: 119
108Literal
109NamedExprselement: 120
targets: 121
110Literal
111Literal
112Operationoperator: 122
operand: 134
113Operationoperator: 124
operands: 131
114Operationoperator: 125
operands: 126
115Operationoperator: 132
operands: 127
116Literal
117Literal
118Operationoperator: 130
operands: 128
119Operationoperator: 132
operands: 129
120Operationoperator: 130
operands: 131
121Operationoperator: 132
operands: 133
122Literal
123ExprTuple134
124Literal
125Literal
126NamedExprsoperation: 135
part: 138
127ExprTuple150, 140
128NamedExprsstate: 136
part: 138
129ExprTuple150, 159
130Literal
131NamedExprsstate: 137
part: 138
132Literal
133ExprTuple139, 140
134Literal
135Operationoperator: 141
operands: 142
136Operationoperator: 143
operands: 144
137Variable
138Variable
139Operationoperator: 146
operands: 145
140Operationoperator: 146
operands: 147
141Literal
142ExprTuple148, 159
143Literal
144ExprTuple149, 159
145ExprTuple159, 150
146Literal
147ExprTuple159, 151
148Variable
149Operationoperator: 152
operands: 153
150Literal
151Variable
152Literal
153ExprTuple154, 155
154Operationoperator: 156
operands: 157
155Variable
156Literal
157ExprTuple158, 159
158Literal
159Variable