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, ConditionalSet, ExprRange, ExprTuple, Variable, VertExprArray, t
from proveit.linear_algebra import MatrixExp, ScalarMult, VecAdd
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import CONTROL, ket0, ket1, ket_plus
from proveit.physics.quantum.QPE import _U, _ket_u, _phase, _s
from proveit.physics.quantum.circuits import Gate, Igate, Input, MultiQubitElem, Output, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr3 = Add(t, one)
sub_expr4 = Add(sub_expr2, t)
sub_expr5 = Interval(sub_expr3, Add(t, _s))
sub_expr6 = Add(Neg(t), one)
expr = ExprTuple(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr5), one, _s)], ExprRange(sub_expr2, [ExprRange(sub_expr1, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr4, sub_expr1)), Conditional(Igate, NotEquals(sub_expr4, sub_expr1))), one, t).with_case_simplification(), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = MatrixExp(_U, Exp(two, Neg(sub_expr2))), part = sub_expr1), targets = sub_expr5), one, _s)], sub_expr6, zero).with_decreasing_order(), [ExprRange(sub_expr1, Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))), sub_expr6, zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr5), one, _s)])))
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(\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 2^{t - 1} \cdot \varphi} \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 2^{t - 2} \cdot \varphi} \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 2^{0} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & \qout{\lvert u \rangle}
} \end{array}\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Operationoperator: 2
operands: 3
2Literal
3ExprTuple4, 5, 6
4ExprTuple7, 8
5ExprRangelambda_map: 9
start_index: 16
end_index: 95
6ExprTuple10, 11
7ExprRangelambda_map: 12
start_index: 111
end_index: 110
8ExprRangelambda_map: 13
start_index: 111
end_index: 93
9Lambdaparameter: 115
body: 14
10ExprRangelambda_map: 15
start_index: 16
end_index: 95
11ExprRangelambda_map: 17
start_index: 111
end_index: 93
12Lambdaparameter: 126
body: 18
13Lambdaparameter: 126
body: 19
14ExprTuple20, 21
15Lambdaparameter: 126
body: 22
16Operationoperator: 105
operands: 23
17Lambdaparameter: 126
body: 24
18Operationoperator: 40
operands: 25
19Operationoperator: 65
operands: 26
20ExprRangelambda_map: 27
start_index: 111
end_index: 110
21ExprRangelambda_map: 28
start_index: 111
end_index: 93
22Operationoperator: 45
operands: 29
23ExprTuple30, 111
24Operationoperator: 65
operands: 31
25NamedExprsstate: 32
26NamedExprselement: 33
targets: 51
27Lambdaparameter: 126
body: 34
28Lambdaparameter: 126
body: 35
29NamedExprsstate: 36
30Operationoperator: 124
operand: 110
31NamedExprselement: 38
targets: 51
32Operationoperator: 103
operand: 47
33Operationoperator: 40
operands: 46
34Operationoperator: 41
operands: 42
35Operationoperator: 65
operands: 43
36Operationoperator: 86
operands: 44
37ExprTuple110
38Operationoperator: 45
operands: 46
39ExprTuple47
40Literal
41Literal
42ExprTuple48, 49
43NamedExprselement: 50
targets: 51
44ExprTuple52, 53
45Literal
46NamedExprsstate: 54
part: 126
47Literal
48Conditionalvalue: 55
condition: 56
49Conditionalvalue: 57
condition: 58
50Operationoperator: 68
operands: 59
51Operationoperator: 60
operands: 61
52Operationoperator: 100
operands: 62
53Operationoperator: 63
operands: 64
54Literal
55Operationoperator: 65
operands: 66
56Operationoperator: 67
operands: 71
57Operationoperator: 68
operands: 69
58Operationoperator: 70
operands: 71
59NamedExprsoperation: 72
part: 126
60Literal
61ExprTuple98, 73
62ExprTuple111, 74
63Literal
64ExprTuple75, 76
65Literal
66NamedExprselement: 77
targets: 78
67Literal
68Literal
69NamedExprsoperation: 79
70Literal
71ExprTuple80, 126
72Operationoperator: 81
operands: 82
73Operationoperator: 105
operands: 83
74Operationoperator: 120
operands: 84
75Operationoperator: 103
operand: 95
76Operationoperator: 86
operands: 87
77Literal
78Operationoperator: 88
operand: 98
79Literal
80Operationoperator: 105
operands: 90
81Literal
82ExprTuple91, 92
83ExprTuple110, 93
84ExprTuple122, 94
85ExprTuple95
86Literal
87ExprTuple96, 97
88Literal
89ExprTuple98
90ExprTuple115, 110
91Literal
92Operationoperator: 120
operands: 99
93Literal
94Operationoperator: 100
operands: 101
95Literal
96Operationoperator: 120
operands: 102
97Operationoperator: 103
operand: 111
98Operationoperator: 105
operands: 106
99ExprTuple122, 107
100Literal
101ExprTuple111, 122
102ExprTuple108, 109
103Literal
104ExprTuple111
105Literal
106ExprTuple110, 111
107Operationoperator: 124
operand: 115
108Literal
109Operationoperator: 113
operands: 114
110Variable
111Literal
112ExprTuple115
113Literal
114ExprTuple122, 116, 117, 118, 119
115Variable
116Literal
117Literal
118Operationoperator: 120
operands: 121
119Literal
120Literal
121ExprTuple122, 123
122Literal
123Operationoperator: 124
operand: 126
124Literal
125ExprTuple126
126Variable