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, NaturalPos, 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(m, Conditional(Forall(instance_param_or_params = [n], instance_expr = 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), domain = m_bit_interval), InSet(m, NaturalPos)))
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())
m \mapsto \left\{\forall_{n \in \{0~\ldotp \ldotp~2^{m} - 1\}}~\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)\right] \textrm{ if } m \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 100
body: 2
1ExprTuple100
2Conditionalvalue: 3
condition: 4
3Operationoperator: 13
operand: 7
4Operationoperator: 37
operands: 6
5ExprTuple7
6ExprTuple100, 8
7Lambdaparameter: 99
body: 10
8Literal
9ExprTuple99
10Conditionalvalue: 11
condition: 12
11Operationoperator: 13
operand: 16
12Operationoperator: 37
operands: 15
13Literal
14ExprTuple16
15ExprTuple99, 17
16Lambdaparameter: 93
body: 18
17Operationoperator: 91
operands: 19
18Conditionalvalue: 20
condition: 21
19ExprTuple22, 23
20Operationoperator: 39
operands: 24
21Operationoperator: 25
operands: 26
22Literal
23Operationoperator: 27
operands: 28
24ExprTuple29, 30
25Literal
26ExprTuple31, 32
27Literal
28ExprTuple60, 33
29Operationoperator: 34
operand: 43
30Operationoperator: 66
operands: 36
31Operationoperator: 37
operands: 38
32Operationoperator: 39
operands: 40
33Operationoperator: 41
operand: 96
34Literal
35ExprTuple43
36ExprTuple44, 72
37Literal
38ExprTuple93, 45
39Literal
40ExprTuple46, 96
41Literal
42ExprTuple96
43Operationoperator: 47
operands: 48
44Operationoperator: 49
operand: 58
45Operationoperator: 51
operands: 52
46Operationoperator: 53
operand: 93
47Literal
48ExprTuple55, 56, 57
49Literal
50ExprTuple58
51Literal
52ExprTuple59, 60
53Literal
54ExprTuple93
55ExprTuple61
56ExprTuple62
57ExprTuple63
58Operationoperator: 64
operands: 65
59Literal
60Operationoperator: 66
operands: 67
61ExprRangelambda_map: 68
start_index: 96
end_index: 100
62ExprRangelambda_map: 69
start_index: 96
end_index: 100
63ExprRangelambda_map: 70
start_index: 96
end_index: 100
64Literal
65ExprTuple71, 93
66Literal
67ExprTuple72, 100
68Lambdaparameter: 95
body: 73
69Lambdaparameter: 95
body: 74
70Lambdaparameter: 95
body: 76
71Operationoperator: 77
operands: 98
72Literal
73Operationoperator: 81
operands: 78
74Operationoperator: 79
operands: 80
75ExprTuple95
76Operationoperator: 81
operands: 82
77Literal
78NamedExprselement: 83
targets: 86
79Literal
80NamedExprsbasis: 84
81Literal
82NamedExprselement: 85
targets: 86
83Operationoperator: 87
operands: 88
84Literal
85Operationoperator: 89
operands: 90
86Operationoperator: 91
operands: 92
87Literal
88NamedExprsstate: 93
part: 95
89Literal
90NamedExprsstate: 94
part: 95
91Literal
92ExprTuple96, 100
93Variable
94Operationoperator: 97
operands: 98
95Variable
96Literal
97Literal
98ExprTuple99, 100
99Variable
100Variable