logo

Expression of type ExprTuple

from the theory of proveit.physics.quantum.circuits

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, m, n
from proveit.numbers import Abs, Exp, two
from proveit.physics.quantum import NumBra, Qmult, var_ket_psi
from proveit.physics.quantum.circuits import register_meas
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = ExprTuple(Prob(register_meas), Exp(Abs(Qmult(NumBra(n, m), var_ket_psi)), two))
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 n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \measure{\begin{array}{c}:\\ \left(m - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert n \rangle_{m}} \\
\ghostqin{\lvert \psi \rangle} & \meter & \ghostqout{\lvert n \rangle_{m}}
} \end{array}\right), \left|{_{m}}\langle n \rvert \thinspace \lvert \psi \rangle\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
operands: 22
18ExprRangelambda_map: 23
start_index: 50
end_index: 54
19ExprRangelambda_map: 24
start_index: 50
end_index: 54
20ExprRangelambda_map: 25
start_index: 50
end_index: 54
21Literal
22ExprTuple26, 47
23Lambdaparameter: 49
body: 27
24Lambdaparameter: 49
body: 28
25Lambdaparameter: 49
body: 30
26Operationoperator: 31
operands: 52
27Operationoperator: 35
operands: 32
28Operationoperator: 33
operands: 34
29ExprTuple49
30Operationoperator: 35
operands: 36
31Literal
32NamedExprselement: 37
targets: 40
33Literal
34NamedExprsbasis: 38
35Literal
36NamedExprselement: 39
targets: 40
37Operationoperator: 41
operands: 42
38Literal
39Operationoperator: 43
operands: 44
40Operationoperator: 45
operands: 46
41Literal
42NamedExprsstate: 47
part: 49
43Literal
44NamedExprsstate: 48
part: 49
45Literal
46ExprTuple50, 54
47Variable
48Operationoperator: 51
operands: 52
49Variable
50Literal
51Literal
52ExprTuple53, 54
53Variable
54Variable