logo

Expression of type ExprTuple

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 Conditional, ExprRange, ExprTuple, IndexedVar, Lambda, U, Variable, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import And, Equals, Forall, InSet
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 = ExprTuple(Lambda(var_ket_u, Conditional(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(), And(InSet(var_ket_u, m_ket_domain), normalized_var_ket_u))))
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())
\left(\lvert u \rangle \mapsto \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} \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{m}} ,  \left \|\lvert u \rangle\right \| = 1\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 94
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 23
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameters: 11
body: 12
9Operationoperator: 13
operands: 14
10Operationoperator: 107
operands: 15
11ExprTuple16
12Conditionalvalue: 17
condition: 18
13Literal
14ExprTuple94, 19
15ExprTuple20, 147
16ExprRangelambda_map: 21
start_index: 147
end_index: 146
17Operationoperator: 107
operands: 22
18Operationoperator: 23
operands: 24
19Operationoperator: 25
operands: 26
20Operationoperator: 27
operand: 94
21Lambdaparameter: 156
body: 153
22ExprTuple29, 147
23Literal
24ExprTuple30
25Literal
26ExprTuple31, 32
27Literal
28ExprTuple94
29Operationoperator: 33
operand: 37
30ExprRangelambda_map: 35
start_index: 147
end_index: 146
31Literal
32Operationoperator: 138
operands: 36
33Literal
34ExprTuple37
35Lambdaparameter: 156
body: 38
36ExprTuple150, 130
37Operationoperator: 39
operands: 40
38Operationoperator: 107
operands: 41
39Literal
40ExprTuple42, 43, 44
41ExprTuple45, 46
42ExprTuple47, 48
43ExprRangelambda_map: 49
start_index: 147
end_index: 146
44ExprTuple50, 51
45Operationoperator: 52
operands: 53
46Operationoperator: 125
operands: 54
47ExprRangelambda_map: 55
start_index: 147
end_index: 146
48ExprRangelambda_map: 56
start_index: 147
end_index: 130
49Lambdaparameter: 129
body: 57
50ExprRangelambda_map: 58
start_index: 147
end_index: 146
51ExprRangelambda_map: 59
start_index: 147
end_index: 130
52Literal
53ExprTuple60, 94
54ExprTuple133, 94
55Lambdaparameter: 156
body: 61
56Lambdaparameter: 156
body: 62
57ExprTuple63, 64
58Lambdaparameter: 156
body: 65
59Lambdaparameter: 156
body: 66
60IndexedVarvariable: 120
index: 156
61Operationoperator: 80
operands: 67
62Operationoperator: 105
operands: 68
63ExprRangelambda_map: 69
start_index: 147
end_index: 146
64ExprRangelambda_map: 70
start_index: 147
end_index: 130
65Operationoperator: 85
operands: 71
66Operationoperator: 105
operands: 72
67NamedExprsstate: 73
68NamedExprselement: 74
targets: 91
69Lambdaparameter: 156
body: 75
70Lambdaparameter: 156
body: 76
71NamedExprsstate: 77
72NamedExprselement: 78
targets: 91
73Operationoperator: 140
operand: 87
74Operationoperator: 80
operands: 86
75Operationoperator: 81
operands: 82
76Operationoperator: 105
operands: 83
77Operationoperator: 125
operands: 84
78Operationoperator: 85
operands: 86
79ExprTuple87
80Literal
81Literal
82ExprTuple88, 89
83NamedExprselement: 90
targets: 91
84ExprTuple92, 93
85Literal
86NamedExprsstate: 94
part: 156
87Literal
88Conditionalvalue: 95
condition: 96
89Conditionalvalue: 97
condition: 98
90Operationoperator: 108
operands: 99
91Operationoperator: 100
operands: 101
92Operationoperator: 136
operands: 102
93Operationoperator: 103
operands: 104
94Variable
95Operationoperator: 105
operands: 106
96Operationoperator: 107
operands: 111
97Operationoperator: 108
operands: 109
98Operationoperator: 110
operands: 111
99NamedExprsoperation: 112
part: 156
100Literal
101ExprTuple135, 113
102ExprTuple147, 114
103Literal
104ExprTuple115, 116
105Literal
106NamedExprselement: 117
targets: 118
107Literal
108Literal
109NamedExprsoperation: 119
110Literal
111ExprTuple129, 156
112IndexedVarvariable: 120
index: 129
113Operationoperator: 142
operands: 122
114Operationoperator: 138
operands: 123
115Operationoperator: 140
operand: 132
116Operationoperator: 125
operands: 126
117Literal
118Operationoperator: 127
operand: 135
119Literal
120Variable
121ExprTuple129
122ExprTuple146, 130
123ExprTuple150, 131
124ExprTuple132
125Literal
126ExprTuple133, 134
127Literal
128ExprTuple135
129Variable
130Variable
131Operationoperator: 136
operands: 137
132Literal
133Operationoperator: 138
operands: 139
134Operationoperator: 140
operand: 147
135Operationoperator: 142
operands: 143
136Literal
137ExprTuple147, 150
138Literal
139ExprTuple144, 145
140Literal
141ExprTuple147
142Literal
143ExprTuple146, 147
144Literal
145Operationoperator: 148
operands: 149
146Variable
147Literal
148Literal
149ExprTuple150, 151, 152, 153
150Literal
151Literal
152Literal
153IndexedVarvariable: 154
index: 156
154Variable
155ExprTuple156
156Variable