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.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _psi_t_ket, _s
from proveit.physics.quantum.circuits import Gate, Input, 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 = MultiQubitElem(element = Gate(operation = QPE1(_U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = ExprTuple(Prob(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_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _psi_t_ket, part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)]))), one)
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(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \multiqout{3}{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\lvert u \rangle}
} \end{array}\right), 1\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, 68
1Operationoperator: 2
operand: 4
2Literal
3ExprTuple4
4Operationoperator: 5
operands: 6
5Literal
6ExprTuple7, 8, 9
7ExprTuple10, 11
8ExprTuple12, 13
9ExprTuple14, 15
10ExprRangelambda_map: 16
start_index: 68
end_index: 69
11ExprRangelambda_map: 17
start_index: 68
end_index: 70
12ExprRangelambda_map: 18
start_index: 68
end_index: 69
13ExprRangelambda_map: 18
start_index: 58
end_index: 59
14ExprRangelambda_map: 19
start_index: 68
end_index: 69
15ExprRangelambda_map: 20
start_index: 68
end_index: 70
16Lambdaparameter: 57
body: 21
17Lambdaparameter: 57
body: 22
18Lambdaparameter: 57
body: 23
19Lambdaparameter: 57
body: 24
20Lambdaparameter: 57
body: 26
21Operationoperator: 43
operands: 27
22Operationoperator: 31
operands: 28
23Operationoperator: 31
operands: 29
24Operationoperator: 31
operands: 30
25ExprTuple57
26Operationoperator: 31
operands: 32
27NamedExprsstate: 33
28NamedExprselement: 34
targets: 40
29NamedExprselement: 35
targets: 36
30NamedExprselement: 37
targets: 38
31Literal
32NamedExprselement: 39
targets: 40
33Operationoperator: 41
operand: 53
34Operationoperator: 43
operands: 50
35Operationoperator: 44
operands: 45
36Operationoperator: 51
operands: 46
37Operationoperator: 49
operands: 47
38Operationoperator: 51
operands: 48
39Operationoperator: 49
operands: 50
40Operationoperator: 51
operands: 52
41Literal
42ExprTuple53
43Literal
44Literal
45NamedExprsoperation: 54
part: 57
46ExprTuple68, 59
47NamedExprsstate: 55
part: 57
48ExprTuple68, 69
49Literal
50NamedExprsstate: 56
part: 57
51Literal
52ExprTuple58, 59
53Literal
54Operationoperator: 60
operands: 61
55Operationoperator: 62
operand: 69
56Literal
57Variable
58Operationoperator: 65
operands: 64
59Operationoperator: 65
operands: 66
60Literal
61ExprTuple67, 69
62Literal
63ExprTuple69
64ExprTuple69, 68
65Literal
66ExprTuple69, 70
67Literal
68Literal
69Variable
70Literal