logo

Expression of type Forall

from the theory of proveit.physics.quantum.circuits

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, IndexedVar, U, Variable, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import Equals, Forall
from proveit.numbers import Exp, Mult, e, i, one, pi, two
from proveit.physics.quantum import m_ket_domain, normalized_var_ket_u, var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_on_register_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(varphi, sub_expr1)
expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr2, one, t)], instance_expr = Equals(Prob(phase_kickback_on_register_circuit), one), condition = ExprRange(sub_expr1, Equals(MatrixMult(IndexedVar(U, sub_expr1), var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, sub_expr2)), var_ket_u)), one, t)).with_wrapping(), domain = m_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^{m}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\left[\begin{array}{l}\forall_{\varphi_{1}, \varphi_{2}, \ldots, \varphi_{t}~|~\left(\left(U_{1} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert u \rangle\right)\right), \left(\left(U_{2} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert u \rangle\right)\right), \ldots, \left(\left(U_{t} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert u \rangle\right)\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U_{1}} & \gate{U_{2}} & \gate{\cdots} & \gate{U_{t}} & \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: 95
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 24
operands: 8
6Literal
7ExprTuple9
8ExprTuple10, 11
9Lambdaparameters: 12
body: 13
10Operationoperator: 14
operands: 15
11Operationoperator: 108
operands: 16
12ExprTuple17
13Conditionalvalue: 18
condition: 19
14Literal
15ExprTuple95, 20
16ExprTuple21, 148
17ExprRangelambda_map: 22
start_index: 148
end_index: 147
18Operationoperator: 108
operands: 23
19Operationoperator: 24
operands: 25
20Operationoperator: 26
operands: 27
21Operationoperator: 28
operand: 95
22Lambdaparameter: 157
body: 154
23ExprTuple30, 148
24Literal
25ExprTuple31
26Literal
27ExprTuple32, 33
28Literal
29ExprTuple95
30Operationoperator: 34
operand: 38
31ExprRangelambda_map: 36
start_index: 148
end_index: 147
32Literal
33Operationoperator: 139
operands: 37
34Literal
35ExprTuple38
36Lambdaparameter: 157
body: 39
37ExprTuple151, 131
38Operationoperator: 40
operands: 41
39Operationoperator: 108
operands: 42
40Literal
41ExprTuple43, 44, 45
42ExprTuple46, 47
43ExprTuple48, 49
44ExprRangelambda_map: 50
start_index: 148
end_index: 147
45ExprTuple51, 52
46Operationoperator: 53
operands: 54
47Operationoperator: 126
operands: 55
48ExprRangelambda_map: 56
start_index: 148
end_index: 147
49ExprRangelambda_map: 57
start_index: 148
end_index: 131
50Lambdaparameter: 130
body: 58
51ExprRangelambda_map: 59
start_index: 148
end_index: 147
52ExprRangelambda_map: 60
start_index: 148
end_index: 131
53Literal
54ExprTuple61, 95
55ExprTuple134, 95
56Lambdaparameter: 157
body: 62
57Lambdaparameter: 157
body: 63
58ExprTuple64, 65
59Lambdaparameter: 157
body: 66
60Lambdaparameter: 157
body: 67
61IndexedVarvariable: 121
index: 157
62Operationoperator: 81
operands: 68
63Operationoperator: 106
operands: 69
64ExprRangelambda_map: 70
start_index: 148
end_index: 147
65ExprRangelambda_map: 71
start_index: 148
end_index: 131
66Operationoperator: 86
operands: 72
67Operationoperator: 106
operands: 73
68NamedExprsstate: 74
69NamedExprselement: 75
targets: 92
70Lambdaparameter: 157
body: 76
71Lambdaparameter: 157
body: 77
72NamedExprsstate: 78
73NamedExprselement: 79
targets: 92
74Operationoperator: 141
operand: 88
75Operationoperator: 81
operands: 87
76Operationoperator: 82
operands: 83
77Operationoperator: 106
operands: 84
78Operationoperator: 126
operands: 85
79Operationoperator: 86
operands: 87
80ExprTuple88
81Literal
82Literal
83ExprTuple89, 90
84NamedExprselement: 91
targets: 92
85ExprTuple93, 94
86Literal
87NamedExprsstate: 95
part: 157
88Literal
89Conditionalvalue: 96
condition: 97
90Conditionalvalue: 98
condition: 99
91Operationoperator: 109
operands: 100
92Operationoperator: 101
operands: 102
93Operationoperator: 137
operands: 103
94Operationoperator: 104
operands: 105
95Variable
96Operationoperator: 106
operands: 107
97Operationoperator: 108
operands: 112
98Operationoperator: 109
operands: 110
99Operationoperator: 111
operands: 112
100NamedExprsoperation: 113
part: 157
101Literal
102ExprTuple136, 114
103ExprTuple148, 115
104Literal
105ExprTuple116, 117
106Literal
107NamedExprselement: 118
targets: 119
108Literal
109Literal
110NamedExprsoperation: 120
111Literal
112ExprTuple130, 157
113IndexedVarvariable: 121
index: 130
114Operationoperator: 143
operands: 123
115Operationoperator: 139
operands: 124
116Operationoperator: 141
operand: 133
117Operationoperator: 126
operands: 127
118Literal
119Operationoperator: 128
operand: 136
120Literal
121Variable
122ExprTuple130
123ExprTuple147, 131
124ExprTuple151, 132
125ExprTuple133
126Literal
127ExprTuple134, 135
128Literal
129ExprTuple136
130Variable
131Variable
132Operationoperator: 137
operands: 138
133Literal
134Operationoperator: 139
operands: 140
135Operationoperator: 141
operand: 148
136Operationoperator: 143
operands: 144
137Literal
138ExprTuple148, 151
139Literal
140ExprTuple145, 146
141Literal
142ExprTuple148
143Literal
144ExprTuple147, 148
145Literal
146Operationoperator: 149
operands: 150
147Variable
148Literal
149Literal
150ExprTuple151, 152, 153, 154
151Literal
152Literal
153Literal
154IndexedVarvariable: 155
index: 157
155Variable
156ExprTuple157
157Variable