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 Equals, Forall, InSet
from proveit.numbers import Abs, Exp, two
from proveit.physics.quantum import NumBra, Qmult, m_bit_interval, 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(n, Conditional(Forall(instance_param_or_params = [var_ket_psi], instance_expr = Equals(Prob(register_meas), Exp(Abs(Qmult(NumBra(n, m), var_ket_psi)), two)), domain = m_ket_domain, condition = normalized_var_ket_psi), InSet(n, m_bit_interval)))
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())
n \mapsto \left\{\forall_{\lvert \psi \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert \psi \rangle\right \| = 1}~\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) \textrm{ if } n \in \{0~\ldotp \ldotp~2^{m} - 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: 91
body: 2
1ExprTuple91
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 29
operands: 7
5Literal
6ExprTuple8
7ExprTuple91, 9
8Lambdaparameter: 85
body: 10
9Operationoperator: 83
operands: 11
10Conditionalvalue: 12
condition: 13
11ExprTuple14, 15
12Operationoperator: 31
operands: 16
13Operationoperator: 17
operands: 18
14Literal
15Operationoperator: 19
operands: 20
16ExprTuple21, 22
17Literal
18ExprTuple23, 24
19Literal
20ExprTuple52, 25
21Operationoperator: 26
operand: 35
22Operationoperator: 58
operands: 28
23Operationoperator: 29
operands: 30
24Operationoperator: 31
operands: 32
25Operationoperator: 33
operand: 88
26Literal
27ExprTuple35
28ExprTuple36, 64
29Literal
30ExprTuple85, 37
31Literal
32ExprTuple38, 88
33Literal
34ExprTuple88
35Operationoperator: 39
operands: 40
36Operationoperator: 41
operand: 50
37Operationoperator: 43
operands: 44
38Operationoperator: 45
operand: 85
39Literal
40ExprTuple47, 48, 49
41Literal
42ExprTuple50
43Literal
44ExprTuple51, 52
45Literal
46ExprTuple85
47ExprTuple53
48ExprTuple54
49ExprTuple55
50Operationoperator: 56
operands: 57
51Literal
52Operationoperator: 58
operands: 59
53ExprRangelambda_map: 60
start_index: 88
end_index: 92
54ExprRangelambda_map: 61
start_index: 88
end_index: 92
55ExprRangelambda_map: 62
start_index: 88
end_index: 92
56Literal
57ExprTuple63, 85
58Literal
59ExprTuple64, 92
60Lambdaparameter: 87
body: 65
61Lambdaparameter: 87
body: 66
62Lambdaparameter: 87
body: 68
63Operationoperator: 69
operands: 90
64Literal
65Operationoperator: 73
operands: 70
66Operationoperator: 71
operands: 72
67ExprTuple87
68Operationoperator: 73
operands: 74
69Literal
70NamedExprselement: 75
targets: 78
71Literal
72NamedExprsbasis: 76
73Literal
74NamedExprselement: 77
targets: 78
75Operationoperator: 79
operands: 80
76Literal
77Operationoperator: 81
operands: 82
78Operationoperator: 83
operands: 84
79Literal
80NamedExprsstate: 85
part: 87
81Literal
82NamedExprsstate: 86
part: 87
83Literal
84ExprTuple88, 92
85Variable
86Operationoperator: 89
operands: 90
87Variable
88Literal
89Literal
90ExprTuple91, 92
91Variable
92Variable