logo

Expression of type ExprTuple

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 Conditional, ExprRange, ExprTuple, Lambda, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import And, 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 = ExprTuple(Lambda(var_ket_u, Conditional(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(), And(InSet(var_ket_u, s_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 \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} \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{s}} ,  \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: 126
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 20
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameter: 144
body: 12
9Operationoperator: 35
operands: 13
10Operationoperator: 37
operands: 14
11ExprTuple144
12Conditionalvalue: 15
condition: 16
13ExprTuple126, 17
14ExprTuple18, 139
15Operationoperator: 37
operands: 19
16Operationoperator: 20
operands: 21
17Operationoperator: 22
operands: 23
18Operationoperator: 24
operand: 126
19ExprTuple26, 139
20Literal
21ExprTuple27, 28, 29
22Literal
23ExprTuple30, 31
24Literal
25ExprTuple126
26Operationoperator: 32
operand: 40
27Operationoperator: 35
operands: 34
28Operationoperator: 35
operands: 36
29Operationoperator: 37
operands: 38
30Literal
31Operationoperator: 145
operands: 39
32Literal
33ExprTuple40
34ExprTuple144, 41
35Literal
36ExprTuple138, 42
37Literal
38ExprTuple43, 44
39ExprTuple147, 140
40Operationoperator: 45
operands: 46
41Literal
42Operationoperator: 121
operands: 47
43Operationoperator: 48
operands: 49
44Operationoperator: 50
operands: 51
45Literal
46ExprTuple52, 53, 54, 55
47ExprTuple56, 57
48Literal
49ExprTuple137, 126
50Literal
51ExprTuple58, 126
52ExprTuple59, 60
53ExprTuple61, 62
54ExprTuple63, 64
55ExprTuple65, 66
56Literal
57Operationoperator: 135
operands: 67
58Operationoperator: 145
operands: 68
59ExprRangelambda_map: 69
start_index: 139
end_index: 148
60ExprRangelambda_map: 70
start_index: 139
end_index: 140
61ExprRangelambda_map: 71
start_index: 139
end_index: 148
62ExprRangelambda_map: 71
start_index: 128
end_index: 129
63ExprRangelambda_map: 72
start_index: 139
end_index: 148
64ExprRangelambda_map: 73
start_index: 139
end_index: 140
65ExprRangelambda_map: 74
start_index: 139
end_index: 148
66ExprRangelambda_map: 75
start_index: 139
end_index: 140
67ExprTuple143, 76
68ExprTuple77, 78
69Lambdaparameter: 127
body: 79
70Lambdaparameter: 127
body: 80
71Lambdaparameter: 127
body: 81
72Lambdaparameter: 127
body: 82
73Lambdaparameter: 127
body: 83
74Lambdaparameter: 127
body: 84
75Lambdaparameter: 127
body: 86
76Operationoperator: 87
operand: 139
77Literal
78Operationoperator: 141
operands: 89
79Operationoperator: 113
operands: 90
80Operationoperator: 97
operands: 91
81Operationoperator: 97
operands: 92
82Operationoperator: 93
operands: 94
83Operationoperator: 114
operands: 95
84Operationoperator: 97
operands: 96
85ExprTuple127
86Operationoperator: 97
operands: 98
87Literal
88ExprTuple139
89ExprTuple147, 99, 100, 144
90NamedExprsstate: 101
91NamedExprselement: 102
targets: 110
92NamedExprselement: 103
targets: 104
93Literal
94NamedExprsbasis: 105
95NamedExprsoperation: 106
96NamedExprselement: 107
targets: 108
97Literal
98NamedExprselement: 109
targets: 110
99Literal
100Literal
101Operationoperator: 111
operand: 123
102Operationoperator: 113
operands: 120
103Operationoperator: 114
operands: 115
104Operationoperator: 121
operands: 116
105Literal
106Literal
107Operationoperator: 119
operands: 117
108Operationoperator: 121
operands: 118
109Operationoperator: 119
operands: 120
110Operationoperator: 121
operands: 122
111Literal
112ExprTuple123
113Literal
114Literal
115NamedExprsoperation: 124
part: 127
116ExprTuple139, 129
117NamedExprsstate: 125
part: 127
118ExprTuple139, 148
119Literal
120NamedExprsstate: 126
part: 127
121Literal
122ExprTuple128, 129
123Literal
124Operationoperator: 130
operands: 131
125Operationoperator: 132
operands: 133
126Variable
127Variable
128Operationoperator: 135
operands: 134
129Operationoperator: 135
operands: 136
130Literal
131ExprTuple137, 148
132Literal
133ExprTuple138, 148
134ExprTuple148, 139
135Literal
136ExprTuple148, 140
137Variable
138Operationoperator: 141
operands: 142
139Literal
140Variable
141Literal
142ExprTuple143, 144
143Operationoperator: 145
operands: 146
144Variable
145Literal
146ExprTuple147, 148
147Literal
148Variable