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 ExprTuple, Lambda, Variable, m
from proveit.linear_algebra import TensorProd
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import I, NumKet, Z
from proveit.physics.quantum.QPE import _Psi_ket, _ket_u, _s, _t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(_t, _s)
sub_expr3 = Lambda(sub_expr1, MultiQubitElem(element = Input(state = TensorProd(_Psi_ket, _ket_u), part = sub_expr1), targets = Interval(one, sub_expr2)))
expr = ExprTuple(sub_expr3, sub_expr3, Lambda(sub_expr1, Measure(basis = Z)), Lambda(sub_expr1, Gate(operation = I).with_implicit_representation()), Lambda(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, _t), part = sub_expr1), targets = Interval(one, _t))), Lambda(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(Add(_t, one), sub_expr2))))
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({_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \Psi \rangle {\otimes} \lvert u \rangle~\mbox{part}~{_{-}a}~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, {_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \Psi \rangle {\otimes} \lvert u \rangle~\mbox{part}~{_{-}a}~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, {_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array}, {_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, {_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert m \rangle_{t}~\mbox{part}~{_{-}a}~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array}, {_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~{_{-}a}~\mbox{on}~\{t + 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, 1, 2, 3, 4, 5
1Lambdaparameter: 39
body: 6
2Lambdaparameter: 39
body: 7
3Lambdaparameter: 39
body: 8
4Lambdaparameter: 39
body: 9
5Lambdaparameter: 39
body: 11
6Operationoperator: 18
operands: 12
7Operationoperator: 13
operands: 14
8Operationoperator: 15
operands: 16
9Operationoperator: 18
operands: 17
10ExprTuple39
11Operationoperator: 18
operands: 19
12NamedExprselement: 20
targets: 21
13Literal
14NamedExprsbasis: 22
15Literal
16NamedExprsoperation: 23
17NamedExprselement: 24
targets: 25
18Literal
19NamedExprselement: 26
targets: 27
20Operationoperator: 28
operands: 29
21Operationoperator: 35
operands: 30
22Literal
23Literal
24Operationoperator: 33
operands: 31
25Operationoperator: 35
operands: 32
26Operationoperator: 33
operands: 34
27Operationoperator: 35
operands: 36
28Literal
29NamedExprsstate: 37
part: 39
30ExprTuple52, 41
31NamedExprsstate: 38
part: 39
32ExprTuple52, 53
33Literal
34NamedExprsstate: 50
part: 39
35Literal
36ExprTuple40, 41
37Operationoperator: 42
operands: 43
38Operationoperator: 44
operands: 45
39Variable
40Operationoperator: 47
operands: 46
41Operationoperator: 47
operands: 48
42Literal
43ExprTuple49, 50
44Literal
45ExprTuple51, 53
46ExprTuple53, 52
47Literal
48ExprTuple53, 54
49Literal
50Literal
51Variable
52Literal
53Literal
54Literal