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 ExprRange, ExprTuple, Variable, VertExprArray, t
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _ket_u, _phase, _psi_t_ket, _s
from proveit.physics.quantum.circuits import MultiQubitElem, Output, Qcircuit
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 = Add(Neg(t), one)
sub_expr5 = TensorProd(_psi_t_ket, _ket_u)
sub_expr6 = Interval(one, sub_expr3)
expr = ExprTuple(Qcircuit(vert_expr_array = VertExprArray([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_expr4, zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr2, sub_expr3)), one, _s).with_wrapping_at(2,6)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = Add(sub_expr1, t)), targets = sub_expr6), sub_expr4, zero), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = sub_expr1), targets = sub_expr6), sub_expr2, sub_expr3).with_wrapping_at(2,6)])))
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{
& \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)} \\
& \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)} \\
& \qout{\vdots} \\
& \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)} \\
& \qout{\lvert u \rangle}
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multiqout{1}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \qout{\vdots} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~0 + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}}
} \end{array}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 4
operand: 6
2Operationoperator: 4
operand: 7
3ExprTuple6
4Literal
5ExprTuple7
6ExprTuple8, 9
7ExprTuple10, 11
8ExprRangelambda_map: 12
start_index: 15
end_index: 70
9ExprRangelambda_map: 13
start_index: 81
end_index: 62
10ExprRangelambda_map: 14
start_index: 15
end_index: 70
11ExprRangelambda_map: 16
start_index: 44
end_index: 47
12Lambdaparameter: 94
body: 17
13Lambdaparameter: 94
body: 18
14Lambdaparameter: 94
body: 19
15Operationoperator: 55
operands: 20
16Lambdaparameter: 94
body: 21
17Operationoperator: 38
operands: 22
18Operationoperator: 26
operands: 23
19Operationoperator: 26
operands: 24
20ExprTuple25, 81
21Operationoperator: 26
operands: 27
22NamedExprsstate: 28
23NamedExprselement: 29
targets: 30
24NamedExprselement: 31
targets: 33
25Operationoperator: 92
operand: 73
26Literal
27NamedExprselement: 32
targets: 33
28Operationoperator: 65
operands: 34
29Operationoperator: 38
operands: 35
30Operationoperator: 40
operands: 36
31Operationoperator: 38
operands: 37
32Operationoperator: 38
operands: 39
33Operationoperator: 40
operands: 41
34ExprTuple42, 43
35NamedExprsstate: 61
part: 94
36ExprTuple44, 47
37NamedExprsstate: 46
part: 45
38Literal
39NamedExprsstate: 46
part: 94
40Literal
41ExprTuple81, 47
42Operationoperator: 74
operands: 48
43Operationoperator: 49
operands: 50
44Operationoperator: 55
operands: 51
45Operationoperator: 55
operands: 52
46Operationoperator: 53
operands: 54
47Operationoperator: 55
operands: 56
48ExprTuple81, 57
49Literal
50ExprTuple58, 59
51ExprTuple73, 81
52ExprTuple94, 73
53Literal
54ExprTuple60, 61
55Literal
56ExprTuple73, 62
57Operationoperator: 88
operands: 63
58Operationoperator: 77
operand: 70
59Operationoperator: 65
operands: 66
60Operationoperator: 67
operand: 73
61Literal
62Literal
63ExprTuple90, 69
64ExprTuple70
65Literal
66ExprTuple71, 72
67Literal
68ExprTuple73
69Operationoperator: 74
operands: 75
70Literal
71Operationoperator: 88
operands: 76
72Operationoperator: 77
operand: 81
73Variable
74Literal
75ExprTuple81, 90
76ExprTuple79, 80
77Literal
78ExprTuple81
79Literal
80Operationoperator: 82
operands: 83
81Literal
82Literal
83ExprTuple90, 84, 85, 86, 87
84Literal
85Literal
86Operationoperator: 88
operands: 89
87Literal
88Literal
89ExprTuple90, 91
90Literal
91Operationoperator: 92
operand: 94
92Literal
93ExprTuple94
94Variable