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, 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_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 = [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()
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}~|~\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}
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: 127
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 21
operands: 8
6Literal
7ExprTuple9
8ExprTuple10, 11
9Lambdaparameter: 145
body: 13
10Operationoperator: 36
operands: 14
11Operationoperator: 38
operands: 15
12ExprTuple145
13Conditionalvalue: 16
condition: 17
14ExprTuple127, 18
15ExprTuple19, 140
16Operationoperator: 38
operands: 20
17Operationoperator: 21
operands: 22
18Operationoperator: 23
operands: 24
19Operationoperator: 25
operand: 127
20ExprTuple27, 140
21Literal
22ExprTuple28, 29, 30
23Literal
24ExprTuple31, 32
25Literal
26ExprTuple127
27Operationoperator: 33
operand: 41
28Operationoperator: 36
operands: 35
29Operationoperator: 36
operands: 37
30Operationoperator: 38
operands: 39
31Literal
32Operationoperator: 146
operands: 40
33Literal
34ExprTuple41
35ExprTuple145, 42
36Literal
37ExprTuple139, 43
38Literal
39ExprTuple44, 45
40ExprTuple148, 141
41Operationoperator: 46
operands: 47
42Literal
43Operationoperator: 122
operands: 48
44Operationoperator: 49
operands: 50
45Operationoperator: 51
operands: 52
46Literal
47ExprTuple53, 54, 55, 56
48ExprTuple57, 58
49Literal
50ExprTuple138, 127
51Literal
52ExprTuple59, 127
53ExprTuple60, 61
54ExprTuple62, 63
55ExprTuple64, 65
56ExprTuple66, 67
57Literal
58Operationoperator: 136
operands: 68
59Operationoperator: 146
operands: 69
60ExprRangelambda_map: 70
start_index: 140
end_index: 149
61ExprRangelambda_map: 71
start_index: 140
end_index: 141
62ExprRangelambda_map: 72
start_index: 140
end_index: 149
63ExprRangelambda_map: 72
start_index: 129
end_index: 130
64ExprRangelambda_map: 73
start_index: 140
end_index: 149
65ExprRangelambda_map: 74
start_index: 140
end_index: 141
66ExprRangelambda_map: 75
start_index: 140
end_index: 149
67ExprRangelambda_map: 76
start_index: 140
end_index: 141
68ExprTuple144, 77
69ExprTuple78, 79
70Lambdaparameter: 128
body: 80
71Lambdaparameter: 128
body: 81
72Lambdaparameter: 128
body: 82
73Lambdaparameter: 128
body: 83
74Lambdaparameter: 128
body: 84
75Lambdaparameter: 128
body: 85
76Lambdaparameter: 128
body: 87
77Operationoperator: 88
operand: 140
78Literal
79Operationoperator: 142
operands: 90
80Operationoperator: 114
operands: 91
81Operationoperator: 98
operands: 92
82Operationoperator: 98
operands: 93
83Operationoperator: 94
operands: 95
84Operationoperator: 115
operands: 96
85Operationoperator: 98
operands: 97
86ExprTuple128
87Operationoperator: 98
operands: 99
88Literal
89ExprTuple140
90ExprTuple148, 100, 101, 145
91NamedExprsstate: 102
92NamedExprselement: 103
targets: 111
93NamedExprselement: 104
targets: 105
94Literal
95NamedExprsbasis: 106
96NamedExprsoperation: 107
97NamedExprselement: 108
targets: 109
98Literal
99NamedExprselement: 110
targets: 111
100Literal
101Literal
102Operationoperator: 112
operand: 124
103Operationoperator: 114
operands: 121
104Operationoperator: 115
operands: 116
105Operationoperator: 122
operands: 117
106Literal
107Literal
108Operationoperator: 120
operands: 118
109Operationoperator: 122
operands: 119
110Operationoperator: 120
operands: 121
111Operationoperator: 122
operands: 123
112Literal
113ExprTuple124
114Literal
115Literal
116NamedExprsoperation: 125
part: 128
117ExprTuple140, 130
118NamedExprsstate: 126
part: 128
119ExprTuple140, 149
120Literal
121NamedExprsstate: 127
part: 128
122Literal
123ExprTuple129, 130
124Literal
125Operationoperator: 131
operands: 132
126Operationoperator: 133
operands: 134
127Variable
128Variable
129Operationoperator: 136
operands: 135
130Operationoperator: 136
operands: 137
131Literal
132ExprTuple138, 149
133Literal
134ExprTuple139, 149
135ExprTuple149, 140
136Literal
137ExprTuple149, 141
138Variable
139Operationoperator: 142
operands: 143
140Literal
141Variable
142Literal
143ExprTuple144, 145
144Operationoperator: 146
operands: 147
145Variable
146Literal
147ExprTuple148, 149
148Literal
149Variable