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, InClass, 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
from proveit.statistics import SampleSpaces
In [2]:
# build up the expression from sub-expressions
expr = Lambda([m, var_ket_psi], Conditional(InClass(SetOfAll(instance_param_or_params = [n], instance_element = register_meas, domain = m_bit_interval), SampleSpaces), 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\{\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\}} \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces} \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
1ExprTuple85, 78
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10
7Literal
8ExprTuple11, 12, 13
9Operationoperator: 14
operand: 20
10Literal
11Operationoperator: 35
operands: 16
12Operationoperator: 35
operands: 17
13Operationoperator: 18
operands: 19
14Literal
15ExprTuple20
16ExprTuple85, 21
17ExprTuple78, 22
18Literal
19ExprTuple23, 81
20Lambdaparameter: 84
body: 25
21Literal
22Operationoperator: 26
operands: 27
23Operationoperator: 28
operand: 78
24ExprTuple84
25Conditionalvalue: 30
condition: 31
26Literal
27ExprTuple32, 61
28Literal
29ExprTuple78
30Operationoperator: 33
operands: 34
31Operationoperator: 35
operands: 36
32Literal
33Literal
34ExprTuple37, 38, 39
35Literal
36ExprTuple84, 40
37ExprTuple41
38ExprTuple42
39ExprTuple43
40Operationoperator: 75
operands: 44
41ExprRangelambda_map: 45
start_index: 81
end_index: 85
42ExprRangelambda_map: 46
start_index: 81
end_index: 85
43ExprRangelambda_map: 47
start_index: 81
end_index: 85
44ExprTuple48, 49
45Lambdaparameter: 80
body: 50
46Lambdaparameter: 80
body: 51
47Lambdaparameter: 80
body: 53
48Literal
49Operationoperator: 54
operands: 55
50Operationoperator: 59
operands: 56
51Operationoperator: 57
operands: 58
52ExprTuple80
53Operationoperator: 59
operands: 60
54Literal
55ExprTuple61, 62
56NamedExprselement: 63
targets: 66
57Literal
58NamedExprsbasis: 64
59Literal
60NamedExprselement: 65
targets: 66
61Operationoperator: 67
operands: 68
62Operationoperator: 69
operand: 81
63Operationoperator: 71
operands: 72
64Literal
65Operationoperator: 73
operands: 74
66Operationoperator: 75
operands: 76
67Literal
68ExprTuple77, 85
69Literal
70ExprTuple81
71Literal
72NamedExprsstate: 78
part: 80
73Literal
74NamedExprsstate: 79
part: 80
75Literal
76ExprTuple81, 85
77Literal
78Variable
79Operationoperator: 82
operands: 83
80Variable
81Literal
82Literal
83ExprTuple84, 85
84Variable
85Variable