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 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 = [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()
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_{\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}
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
3Lambdaparameters: 4
body: 5
4ExprTuple6
5Conditionalvalue: 7
condition: 8
6ExprRangelambda_map: 9
start_index: 128
end_index: 127
7Operationoperator: 88
operands: 10
8Operationoperator: 11
operands: 12
9Lambdaparameter: 137
body: 134
10ExprTuple13, 128
11Literal
12ExprTuple14
13Operationoperator: 15
operand: 18
14ExprRangelambda_map: 17
start_index: 128
end_index: 127
15Literal
16ExprTuple18
17Lambdaparameter: 137
body: 19
18Operationoperator: 20
operands: 21
19Operationoperator: 88
operands: 22
20Literal
21ExprTuple23, 24, 25
22ExprTuple26, 27
23ExprTuple28, 29
24ExprRangelambda_map: 30
start_index: 128
end_index: 127
25ExprTuple31, 32
26Operationoperator: 33
operands: 34
27Operationoperator: 106
operands: 35
28ExprRangelambda_map: 36
start_index: 128
end_index: 127
29ExprRangelambda_map: 37
start_index: 128
end_index: 111
30Lambdaparameter: 110
body: 38
31ExprRangelambda_map: 39
start_index: 128
end_index: 127
32ExprRangelambda_map: 40
start_index: 128
end_index: 111
33Literal
34ExprTuple41, 75
35ExprTuple114, 75
36Lambdaparameter: 137
body: 42
37Lambdaparameter: 137
body: 43
38ExprTuple44, 45
39Lambdaparameter: 137
body: 46
40Lambdaparameter: 137
body: 47
41IndexedVarvariable: 101
index: 137
42Operationoperator: 61
operands: 48
43Operationoperator: 86
operands: 49
44ExprRangelambda_map: 50
start_index: 128
end_index: 127
45ExprRangelambda_map: 51
start_index: 128
end_index: 111
46Operationoperator: 66
operands: 52
47Operationoperator: 86
operands: 53
48NamedExprsstate: 54
49NamedExprselement: 55
targets: 72
50Lambdaparameter: 137
body: 56
51Lambdaparameter: 137
body: 57
52NamedExprsstate: 58
53NamedExprselement: 59
targets: 72
54Operationoperator: 121
operand: 68
55Operationoperator: 61
operands: 67
56Operationoperator: 62
operands: 63
57Operationoperator: 86
operands: 64
58Operationoperator: 106
operands: 65
59Operationoperator: 66
operands: 67
60ExprTuple68
61Literal
62Literal
63ExprTuple69, 70
64NamedExprselement: 71
targets: 72
65ExprTuple73, 74
66Literal
67NamedExprsstate: 75
part: 137
68Literal
69Conditionalvalue: 76
condition: 77
70Conditionalvalue: 78
condition: 79
71Operationoperator: 89
operands: 80
72Operationoperator: 81
operands: 82
73Operationoperator: 117
operands: 83
74Operationoperator: 84
operands: 85
75Variable
76Operationoperator: 86
operands: 87
77Operationoperator: 88
operands: 92
78Operationoperator: 89
operands: 90
79Operationoperator: 91
operands: 92
80NamedExprsoperation: 93
part: 137
81Literal
82ExprTuple116, 94
83ExprTuple128, 95
84Literal
85ExprTuple96, 97
86Literal
87NamedExprselement: 98
targets: 99
88Literal
89Literal
90NamedExprsoperation: 100
91Literal
92ExprTuple110, 137
93IndexedVarvariable: 101
index: 110
94Operationoperator: 123
operands: 103
95Operationoperator: 119
operands: 104
96Operationoperator: 121
operand: 113
97Operationoperator: 106
operands: 107
98Literal
99Operationoperator: 108
operand: 116
100Literal
101Variable
102ExprTuple110
103ExprTuple127, 111
104ExprTuple131, 112
105ExprTuple113
106Literal
107ExprTuple114, 115
108Literal
109ExprTuple116
110Variable
111Variable
112Operationoperator: 117
operands: 118
113Literal
114Operationoperator: 119
operands: 120
115Operationoperator: 121
operand: 128
116Operationoperator: 123
operands: 124
117Literal
118ExprTuple128, 131
119Literal
120ExprTuple125, 126
121Literal
122ExprTuple128
123Literal
124ExprTuple127, 128
125Literal
126Operationoperator: 129
operands: 130
127Variable
128Literal
129Literal
130ExprTuple131, 132, 133, 134
131Literal
132Literal
133Literal
134IndexedVarvariable: 135
index: 137
135Variable
136ExprTuple137
137Variable