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, ExprTuple, Lambda, U, m
from proveit.linear_algebra import ScalarMult, Unitary
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Exp, Mult, NaturalPos, e, i, one, pi, two
from proveit.physics.quantum import Qmult, m_ket_domain, normalized_var_ket_u, var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = ExprTuple(Lambda(m, Conditional(Forall(instance_param_or_params = [U], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [varphi], instance_expr = Equals(Prob(phase_kickback_circuit), one), condition = Equals(Qmult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, varphi)), var_ket_u))), domain = m_ket_domain, condition = normalized_var_ket_u), domain = Unitary(Exp(two, m))), InSet(m, NaturalPos))))
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(m \mapsto \left\{\forall_{U \in \textrm{U}\left(2^{m}\right)}~\left[\forall_{\lvert u \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert u \rangle\right \| = 1}~\left[\forall_{\varphi~|~\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} & \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} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U} & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\right]\right] \textrm{ if } m \in \mathbb{N}^+\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: 127
body: 3
2ExprTuple127
3Conditionalvalue: 4
condition: 5
4Operationoperator: 23
operand: 8
5Operationoperator: 32
operands: 7
6ExprTuple8
7ExprTuple127, 9
8Lambdaparameter: 110
body: 11
9Literal
10ExprTuple110
11Conditionalvalue: 12
condition: 13
12Operationoperator: 23
operand: 16
13Operationoperator: 32
operands: 15
14ExprTuple16
15ExprTuple110, 17
16Lambdaparameter: 114
body: 18
17Operationoperator: 19
operand: 50
18Conditionalvalue: 21
condition: 22
19Literal
20ExprTuple50
21Operationoperator: 23
operand: 27
22Operationoperator: 25
operands: 26
23Literal
24ExprTuple27
25Literal
26ExprTuple28, 29
27Lambdaparameter: 142
body: 31
28Operationoperator: 32
operands: 33
29Operationoperator: 40
operands: 34
30ExprTuple142
31Conditionalvalue: 35
condition: 36
32Literal
33ExprTuple114, 37
34ExprTuple38, 136
35Operationoperator: 40
operands: 39
36Operationoperator: 40
operands: 41
37Operationoperator: 42
operands: 43
38Operationoperator: 44
operand: 114
39ExprTuple46, 136
40Literal
41ExprTuple47, 48
42Literal
43ExprTuple49, 50
44Literal
45ExprTuple114
46Operationoperator: 51
operand: 57
47Operationoperator: 53
operands: 54
48Operationoperator: 119
operands: 55
49Literal
50Operationoperator: 130
operands: 56
51Literal
52ExprTuple57
53Literal
54ExprTuple110, 114
55ExprTuple125, 114
56ExprTuple139, 127
57Operationoperator: 58
operands: 59
58Literal
59ExprTuple60, 61, 62
60ExprTuple63, 64
61ExprTuple65, 66
62ExprTuple67, 68
63Operationoperator: 100
operands: 69
64ExprRangelambda_map: 70
start_index: 136
end_index: 75
65Operationoperator: 91
operands: 71
66ExprRangelambda_map: 72
start_index: 136
end_index: 75
67Operationoperator: 106
operands: 73
68ExprRangelambda_map: 74
start_index: 136
end_index: 75
69NamedExprsstate: 76
70Lambdaparameter: 115
body: 77
71NamedExprselement: 78
targets: 79
72Lambdaparameter: 115
body: 80
73NamedExprsstate: 81
74Lambdaparameter: 115
body: 83
75Operationoperator: 121
operands: 84
76Operationoperator: 132
operand: 93
77Operationoperator: 91
operands: 86
78Literal
79Operationoperator: 87
operand: 139
80Operationoperator: 91
operands: 89
81Operationoperator: 119
operands: 90
82ExprTuple115
83Operationoperator: 91
operands: 92
84ExprTuple127, 136
85ExprTuple93
86NamedExprselement: 94
targets: 99
87Literal
88ExprTuple139
89NamedExprselement: 95
targets: 99
90ExprTuple96, 97
91Literal
92NamedExprselement: 98
targets: 99
93Literal
94Operationoperator: 100
operands: 107
95Operationoperator: 101
operands: 102
96Operationoperator: 128
operands: 103
97Operationoperator: 104
operands: 105
98Operationoperator: 106
operands: 107
99Operationoperator: 108
operands: 109
100Literal
101Literal
102NamedExprsoperation: 110
part: 115
103ExprTuple136, 111
104Literal
105ExprTuple112, 113
106Literal
107NamedExprsstate: 114
part: 115
108Literal
109ExprTuple139, 116
110Variable
111Operationoperator: 130
operands: 117
112Operationoperator: 132
operand: 124
113Operationoperator: 119
operands: 120
114Variable
115Variable
116Operationoperator: 121
operands: 122
117ExprTuple139, 123
118ExprTuple124
119Literal
120ExprTuple125, 126
121Literal
122ExprTuple127, 139
123Operationoperator: 128
operands: 129
124Literal
125Operationoperator: 130
operands: 131
126Operationoperator: 132
operand: 136
127Variable
128Literal
129ExprTuple136, 139
130Literal
131ExprTuple134, 135
132Literal
133ExprTuple136
134Literal
135Operationoperator: 137
operands: 138
136Literal
137Literal
138ExprTuple139, 140, 141, 142
139Literal
140Literal
141Literal
142Variable