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, m
from proveit.numbers import Interval, one
from proveit.physics.quantum import NumKet, Z
from proveit.physics.quantum.QPE import _Psi_ket, _alpha_m_sqrd, _t
from proveit.physics.quantum.circuits import Input, Measure, 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 = Interval(one, _t)
expr = ExprTuple(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _Psi_ket, part = sub_expr1), targets = sub_expr2), one, _t)], [ExprRange(sub_expr1, Measure(basis = Z), one, _t)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, _t), part = sub_expr1), targets = sub_expr2), one, _t)]))), _alpha_m_sqrd)
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{
\multiqin{3}{\lvert \Psi \rangle} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert m \rangle_{t}} \\
\ghostqin{\lvert \Psi \rangle} & \meter & \ghostqout{\lvert m \rangle_{t}}
} \end{array}\right), \left|\alpha_{m}\right|^{2}\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: 3
operand: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8, 9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operand: 17
9Literal
10Literal
11ExprTuple14, 15, 16
12Literal
13ExprTuple17
14ExprTuple18
15ExprTuple19
16ExprTuple20
17Operationoperator: 21
operand: 51
18ExprRangelambda_map: 23
start_index: 48
end_index: 52
19ExprRangelambda_map: 24
start_index: 48
end_index: 52
20ExprRangelambda_map: 25
start_index: 48
end_index: 52
21Literal
22ExprTuple51
23Lambdaparameter: 47
body: 26
24Lambdaparameter: 47
body: 27
25Lambdaparameter: 47
body: 29
26Operationoperator: 33
operands: 30
27Operationoperator: 31
operands: 32
28ExprTuple47
29Operationoperator: 33
operands: 34
30NamedExprselement: 35
targets: 38
31Literal
32NamedExprsbasis: 36
33Literal
34NamedExprselement: 37
targets: 38
35Operationoperator: 39
operands: 40
36Literal
37Operationoperator: 41
operands: 42
38Operationoperator: 43
operands: 44
39Literal
40NamedExprsstate: 45
part: 47
41Literal
42NamedExprsstate: 46
part: 47
43Literal
44ExprTuple48, 52
45Literal
46Operationoperator: 49
operands: 50
47Variable
48Literal
49Literal
50ExprTuple51, 52
51Variable
52Literal