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 = Neg(t)
sub_expr3 = Add(t, one)
sub_expr4 = Add(t, _s)
sub_expr5 = TensorProd(_psi_t_ket, _ket_u)
sub_expr6 = Interval(one, sub_expr4)
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)))), Add(sub_expr2, one), zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr3, sub_expr4)), one, _s).with_wrapping_at(2,6)])), Qcircuit(vert_expr_array = VertExprArray([MultiQubitElem(element = Output(state = sub_expr5, part = one), targets = sub_expr6), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = Add(sub_expr1, t)), targets = sub_expr6), Add(sub_expr2, two), zero), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr5, part = sub_expr1), targets = sub_expr6), sub_expr3, sub_expr4).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{2}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\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, 12
8ExprRangelambda_map: 13
start_index: 14
end_index: 76
9ExprRangelambda_map: 15
start_index: 87
end_index: 68
10Operationoperator: 32
operands: 16
11ExprRangelambda_map: 17
start_index: 18
end_index: 76
12ExprRangelambda_map: 19
start_index: 50
end_index: 53
13Lambdaparameter: 100
body: 20
14Operationoperator: 61
operands: 21
15Lambdaparameter: 100
body: 22
16NamedExprselement: 23
targets: 39
17Lambdaparameter: 100
body: 24
18Operationoperator: 61
operands: 25
19Lambdaparameter: 100
body: 26
20Operationoperator: 44
operands: 27
21ExprTuple31, 87
22Operationoperator: 32
operands: 28
23Operationoperator: 44
operands: 29
24Operationoperator: 32
operands: 30
25ExprTuple31, 96
26Operationoperator: 32
operands: 33
27NamedExprsstate: 34
28NamedExprselement: 35
targets: 36
29NamedExprsstate: 52
part: 87
30NamedExprselement: 37
targets: 39
31Operationoperator: 98
operand: 79
32Literal
33NamedExprselement: 38
targets: 39
34Operationoperator: 71
operands: 40
35Operationoperator: 44
operands: 41
36Operationoperator: 46
operands: 42
37Operationoperator: 44
operands: 43
38Operationoperator: 44
operands: 45
39Operationoperator: 46
operands: 47
40ExprTuple48, 49
41NamedExprsstate: 67
part: 100
42ExprTuple50, 53
43NamedExprsstate: 52
part: 51
44Literal
45NamedExprsstate: 52
part: 100
46Literal
47ExprTuple87, 53
48Operationoperator: 80
operands: 54
49Operationoperator: 55
operands: 56
50Operationoperator: 61
operands: 57
51Operationoperator: 61
operands: 58
52Operationoperator: 59
operands: 60
53Operationoperator: 61
operands: 62
54ExprTuple87, 63
55Literal
56ExprTuple64, 65
57ExprTuple79, 87
58ExprTuple100, 79
59Literal
60ExprTuple66, 67
61Literal
62ExprTuple79, 68
63Operationoperator: 94
operands: 69
64Operationoperator: 83
operand: 76
65Operationoperator: 71
operands: 72
66Operationoperator: 73
operand: 79
67Literal
68Literal
69ExprTuple96, 75
70ExprTuple76
71Literal
72ExprTuple77, 78
73Literal
74ExprTuple79
75Operationoperator: 80
operands: 81
76Literal
77Operationoperator: 94
operands: 82
78Operationoperator: 83
operand: 87
79Variable
80Literal
81ExprTuple87, 96
82ExprTuple85, 86
83Literal
84ExprTuple87
85Literal
86Operationoperator: 88
operands: 89
87Literal
88Literal
89ExprTuple96, 90, 91, 92, 93
90Literal
91Literal
92Operationoperator: 94
operands: 95
93Literal
94Literal
95ExprTuple96, 97
96Literal
97Operationoperator: 98
operand: 100
98Literal
99ExprTuple100
100Variable