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, Bijections, InSet, SetOfAll
from proveit.numbers import NaturalPos
from proveit.physics.quantum import m_bit_interval, m_ket_domain, normalized_var_ket_psi, var_ket_psi
from proveit.physics.quantum.circuits import register_meas
In [2]:
# build up the expression from sub-expressions
expr = Lambda([m, var_ket_psi], Conditional(InSet(Lambda(n, register_meas), Bijections(m_bit_interval, SetOfAll(instance_param_or_params = [n], instance_element = register_meas, domain = m_bit_interval))).with_wrapping_at(2), And(InSet(m, NaturalPos), 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(m, \lvert \psi \rangle\right) \mapsto \left\{\begin{array}{c} \begin{array}{l} \left[n \mapsto \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)\right] \in  \\ \left[\{0~\ldotp \ldotp~2^{m} - 1\} \xrightarrow[\text{onto}]{\text{1-to-1}} \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\}_{n \in \{0~\ldotp \ldotp~2^{m} - 1\}}\right] \end{array} \end{array} \textrm{ if } m \in \mathbb{N}^+ ,  \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
0Lambdaparameters: 1
body: 2
1ExprTuple87, 80
2Conditionalvalue: 3
condition: 4
3Operationoperator: 37
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple8, 9
6Literal
7ExprTuple10, 11, 12
8Lambdaparameter: 86
body: 33
9Operationoperator: 13
operands: 14
10Operationoperator: 37
operands: 15
11Operationoperator: 37
operands: 16
12Operationoperator: 17
operands: 18
13Literal
14ExprTuple42, 19
15ExprTuple87, 20
16ExprTuple80, 21
17Literal
18ExprTuple22, 83
19Operationoperator: 23
operand: 29
20Literal
21Operationoperator: 25
operands: 26
22Operationoperator: 27
operand: 80
23Literal
24ExprTuple29
25Literal
26ExprTuple30, 63
27Literal
28ExprTuple80
29Lambdaparameter: 86
body: 32
30Literal
31ExprTuple86
32Conditionalvalue: 33
condition: 34
33Operationoperator: 35
operands: 36
34Operationoperator: 37
operands: 38
35Literal
36ExprTuple39, 40, 41
37Literal
38ExprTuple86, 42
39ExprTuple43
40ExprTuple44
41ExprTuple45
42Operationoperator: 77
operands: 46
43ExprRangelambda_map: 47
start_index: 83
end_index: 87
44ExprRangelambda_map: 48
start_index: 83
end_index: 87
45ExprRangelambda_map: 49
start_index: 83
end_index: 87
46ExprTuple50, 51
47Lambdaparameter: 82
body: 52
48Lambdaparameter: 82
body: 53
49Lambdaparameter: 82
body: 55
50Literal
51Operationoperator: 56
operands: 57
52Operationoperator: 61
operands: 58
53Operationoperator: 59
operands: 60
54ExprTuple82
55Operationoperator: 61
operands: 62
56Literal
57ExprTuple63, 64
58NamedExprselement: 65
targets: 68
59Literal
60NamedExprsbasis: 66
61Literal
62NamedExprselement: 67
targets: 68
63Operationoperator: 69
operands: 70
64Operationoperator: 71
operand: 83
65Operationoperator: 73
operands: 74
66Literal
67Operationoperator: 75
operands: 76
68Operationoperator: 77
operands: 78
69Literal
70ExprTuple79, 87
71Literal
72ExprTuple83
73Literal
74NamedExprsstate: 80
part: 82
75Literal
76NamedExprsstate: 81
part: 82
77Literal
78ExprTuple83, 87
79Literal
80Variable
81Operationoperator: 84
operands: 85
82Variable
83Literal
84Literal
85ExprTuple86, 87
86Variable
87Variable