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 = MultiQubitElem(element = Output(state = TensorProd(_psi_t_ket, _ket_u), part = sub_expr1), targets = 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)))), Add(Neg(t), one), zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr2, sub_expr3)), one, _s)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr4, one, t), ExprRange(sub_expr1, sub_expr4, 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}
} \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: 13
end_index: 63
9ExprRangelambda_map: 14
start_index: 74
end_index: 55
10ExprRangelambda_map: 15
start_index: 74
end_index: 66
11ExprRangelambda_map: 15
start_index: 39
end_index: 41
12Lambdaparameter: 87
body: 16
13Operationoperator: 48
operands: 17
14Lambdaparameter: 87
body: 18
15Lambdaparameter: 87
body: 19
16Operationoperator: 33
operands: 20
17ExprTuple21, 74
18Operationoperator: 23
operands: 22
19Operationoperator: 23
operands: 24
20NamedExprsstate: 25
21Operationoperator: 85
operand: 66
22NamedExprselement: 26
targets: 27
23Literal
24NamedExprselement: 28
targets: 29
25Operationoperator: 58
operands: 30
26Operationoperator: 33
operands: 31
27Operationoperator: 35
operands: 32
28Operationoperator: 33
operands: 34
29Operationoperator: 35
operands: 36
30ExprTuple37, 38
31NamedExprsstate: 54
part: 87
32ExprTuple39, 41
33Literal
34NamedExprsstate: 40
part: 87
35Literal
36ExprTuple74, 41
37Operationoperator: 67
operands: 42
38Operationoperator: 43
operands: 44
39Operationoperator: 48
operands: 45
40Operationoperator: 46
operands: 47
41Operationoperator: 48
operands: 49
42ExprTuple74, 50
43Literal
44ExprTuple51, 52
45ExprTuple66, 74
46Literal
47ExprTuple53, 54
48Literal
49ExprTuple66, 55
50Operationoperator: 81
operands: 56
51Operationoperator: 70
operand: 63
52Operationoperator: 58
operands: 59
53Operationoperator: 60
operand: 66
54Literal
55Literal
56ExprTuple83, 62
57ExprTuple63
58Literal
59ExprTuple64, 65
60Literal
61ExprTuple66
62Operationoperator: 67
operands: 68
63Literal
64Operationoperator: 81
operands: 69
65Operationoperator: 70
operand: 74
66Variable
67Literal
68ExprTuple74, 83
69ExprTuple72, 73
70Literal
71ExprTuple74
72Literal
73Operationoperator: 75
operands: 76
74Literal
75Literal
76ExprTuple83, 77, 78, 79, 80
77Literal
78Literal
79Operationoperator: 81
operands: 82
80Literal
81Literal
82ExprTuple83, 84
83Literal
84Operationoperator: 85
operand: 87
85Literal
86ExprTuple87
87Variable