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 Conditional, ExprTuple, Lambda, m, n
from proveit.logic import And, Equals, InSet
from proveit.numbers import Abs, Exp, two
from proveit.physics.quantum import NumBra, Qmult, m_ket_domain, normalized_var_ket_psi, 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(Lambda(var_ket_psi, Conditional(Equals(Prob(register_meas), Exp(Abs(Qmult(NumBra(n, m), var_ket_psi)), two)), And(InSet(var_ket_psi, m_ket_domain), normalized_var_ket_psi))))
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(\lvert \psi \rangle \mapsto \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} \textrm{ if } \lvert \psi \rangle \in \mathbb{C}^{2^{m}} ,  \left \|\lvert \psi \rangle\right \| = 1\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 69
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 17
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 9
6Literal
7ExprTuple10, 11
8Operationoperator: 12
operand: 19
9Operationoperator: 42
operands: 14
10Operationoperator: 15
operands: 16
11Operationoperator: 17
operands: 18
12Literal
13ExprTuple19
14ExprTuple20, 48
15Literal
16ExprTuple69, 21
17Literal
18ExprTuple22, 72
19Operationoperator: 23
operands: 24
20Operationoperator: 25
operand: 34
21Operationoperator: 27
operands: 28
22Operationoperator: 29
operand: 69
23Literal
24ExprTuple31, 32, 33
25Literal
26ExprTuple34
27Literal
28ExprTuple35, 36
29Literal
30ExprTuple69
31ExprTuple37
32ExprTuple38
33ExprTuple39
34Operationoperator: 40
operands: 41
35Literal
36Operationoperator: 42
operands: 43
37ExprRangelambda_map: 44
start_index: 72
end_index: 76
38ExprRangelambda_map: 45
start_index: 72
end_index: 76
39ExprRangelambda_map: 46
start_index: 72
end_index: 76
40Literal
41ExprTuple47, 69
42Literal
43ExprTuple48, 76
44Lambdaparameter: 71
body: 49
45Lambdaparameter: 71
body: 50
46Lambdaparameter: 71
body: 52
47Operationoperator: 53
operands: 74
48Literal
49Operationoperator: 57
operands: 54
50Operationoperator: 55
operands: 56
51ExprTuple71
52Operationoperator: 57
operands: 58
53Literal
54NamedExprselement: 59
targets: 62
55Literal
56NamedExprsbasis: 60
57Literal
58NamedExprselement: 61
targets: 62
59Operationoperator: 63
operands: 64
60Literal
61Operationoperator: 65
operands: 66
62Operationoperator: 67
operands: 68
63Literal
64NamedExprsstate: 69
part: 71
65Literal
66NamedExprsstate: 70
part: 71
67Literal
68ExprTuple72, 76
69Variable
70Operationoperator: 73
operands: 74
71Variable
72Literal
73Literal
74ExprTuple75, 76
75Variable
76Variable