logo

Expression of type Lambda

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, 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 = 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())
\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..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 68
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 16
operands: 4
3Operationoperator: 5
operands: 6
4ExprTuple7, 8
5Literal
6ExprTuple9, 10
7Operationoperator: 11
operand: 18
8Operationoperator: 41
operands: 13
9Operationoperator: 14
operands: 15
10Operationoperator: 16
operands: 17
11Literal
12ExprTuple18
13ExprTuple19, 47
14Literal
15ExprTuple68, 20
16Literal
17ExprTuple21, 71
18Operationoperator: 22
operands: 23
19Operationoperator: 24
operand: 33
20Operationoperator: 26
operands: 27
21Operationoperator: 28
operand: 68
22Literal
23ExprTuple30, 31, 32
24Literal
25ExprTuple33
26Literal
27ExprTuple34, 35
28Literal
29ExprTuple68
30ExprTuple36
31ExprTuple37
32ExprTuple38
33Operationoperator: 39
operands: 40
34Literal
35Operationoperator: 41
operands: 42
36ExprRangelambda_map: 43
start_index: 71
end_index: 75
37ExprRangelambda_map: 44
start_index: 71
end_index: 75
38ExprRangelambda_map: 45
start_index: 71
end_index: 75
39Literal
40ExprTuple46, 68
41Literal
42ExprTuple47, 75
43Lambdaparameter: 70
body: 48
44Lambdaparameter: 70
body: 49
45Lambdaparameter: 70
body: 51
46Operationoperator: 52
operands: 73
47Literal
48Operationoperator: 56
operands: 53
49Operationoperator: 54
operands: 55
50ExprTuple70
51Operationoperator: 56
operands: 57
52Literal
53NamedExprselement: 58
targets: 61
54Literal
55NamedExprsbasis: 59
56Literal
57NamedExprselement: 60
targets: 61
58Operationoperator: 62
operands: 63
59Literal
60Operationoperator: 64
operands: 65
61Operationoperator: 66
operands: 67
62Literal
63NamedExprsstate: 68
part: 70
64Literal
65NamedExprsstate: 69
part: 70
66Literal
67ExprTuple71, 75
68Variable
69Operationoperator: 72
operands: 73
70Variable
71Literal
72Literal
73ExprTuple74, 75
74Variable
75Variable