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, 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, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, 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(phase, Conditional(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), And(InSet(phase, Real), 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))))))
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(\varphi \mapsto \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 \textrm{ if } \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)\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: 124
body: 3
2ExprTuple124
3Conditionalvalue: 4
condition: 5
4Operationoperator: 18
operands: 6
5Operationoperator: 7
operands: 8
6ExprTuple9, 119
7Literal
8ExprTuple10, 11, 12
9Operationoperator: 13
operand: 20
10Operationoperator: 16
operands: 15
11Operationoperator: 16
operands: 17
12Operationoperator: 18
operands: 19
13Literal
14ExprTuple20
15ExprTuple124, 21
16Literal
17ExprTuple118, 22
18Literal
19ExprTuple23, 24
20Operationoperator: 25
operands: 26
21Literal
22Operationoperator: 101
operands: 27
23Operationoperator: 28
operands: 29
24Operationoperator: 30
operands: 31
25Literal
26ExprTuple32, 33, 34, 35
27ExprTuple36, 37
28Literal
29ExprTuple117, 106
30Literal
31ExprTuple38, 106
32ExprTuple39, 40
33ExprTuple41, 42
34ExprTuple43, 44
35ExprTuple45, 46
36Literal
37Operationoperator: 115
operands: 47
38Operationoperator: 125
operands: 48
39ExprRangelambda_map: 49
start_index: 119
end_index: 128
40ExprRangelambda_map: 50
start_index: 119
end_index: 120
41ExprRangelambda_map: 51
start_index: 119
end_index: 128
42ExprRangelambda_map: 51
start_index: 108
end_index: 109
43ExprRangelambda_map: 52
start_index: 119
end_index: 128
44ExprRangelambda_map: 53
start_index: 119
end_index: 120
45ExprRangelambda_map: 54
start_index: 119
end_index: 128
46ExprRangelambda_map: 55
start_index: 119
end_index: 120
47ExprTuple123, 56
48ExprTuple57, 58
49Lambdaparameter: 107
body: 59
50Lambdaparameter: 107
body: 60
51Lambdaparameter: 107
body: 61
52Lambdaparameter: 107
body: 62
53Lambdaparameter: 107
body: 63
54Lambdaparameter: 107
body: 64
55Lambdaparameter: 107
body: 66
56Operationoperator: 67
operand: 119
57Literal
58Operationoperator: 121
operands: 69
59Operationoperator: 93
operands: 70
60Operationoperator: 77
operands: 71
61Operationoperator: 77
operands: 72
62Operationoperator: 73
operands: 74
63Operationoperator: 94
operands: 75
64Operationoperator: 77
operands: 76
65ExprTuple107
66Operationoperator: 77
operands: 78
67Literal
68ExprTuple119
69ExprTuple127, 79, 80, 124
70NamedExprsstate: 81
71NamedExprselement: 82
targets: 90
72NamedExprselement: 83
targets: 84
73Literal
74NamedExprsbasis: 85
75NamedExprsoperation: 86
76NamedExprselement: 87
targets: 88
77Literal
78NamedExprselement: 89
targets: 90
79Literal
80Literal
81Operationoperator: 91
operand: 103
82Operationoperator: 93
operands: 100
83Operationoperator: 94
operands: 95
84Operationoperator: 101
operands: 96
85Literal
86Literal
87Operationoperator: 99
operands: 97
88Operationoperator: 101
operands: 98
89Operationoperator: 99
operands: 100
90Operationoperator: 101
operands: 102
91Literal
92ExprTuple103
93Literal
94Literal
95NamedExprsoperation: 104
part: 107
96ExprTuple119, 109
97NamedExprsstate: 105
part: 107
98ExprTuple119, 128
99Literal
100NamedExprsstate: 106
part: 107
101Literal
102ExprTuple108, 109
103Literal
104Operationoperator: 110
operands: 111
105Operationoperator: 112
operands: 113
106Variable
107Variable
108Operationoperator: 115
operands: 114
109Operationoperator: 115
operands: 116
110Literal
111ExprTuple117, 128
112Literal
113ExprTuple118, 128
114ExprTuple128, 119
115Literal
116ExprTuple128, 120
117Variable
118Operationoperator: 121
operands: 122
119Literal
120Variable
121Literal
122ExprTuple123, 124
123Operationoperator: 125
operands: 126
124Variable
125Literal
126ExprTuple127, 128
127Literal
128Variable