logo

Expression of type Lambda

from the theory of proveit.physics.quantum.algebra

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, ExprRange, IndexedVar, Lambda, Variable, i, lambda_, m, n
from proveit.core_expr_types import a_1_to_m, a_i, b_1_to_n, b_i, lambda_i
from proveit.linear_algebra import OrthoNormBases, ScalarMult, TensorProd, VecSum
from proveit.logic import And, CartExp, Equals, Exists, Forall, InSet, Set
from proveit.numbers import Complex, Interval, Min, NaturalPos, RealNonNeg, one
from proveit.physics.quantum import Ket, Qmult, var_ket_psi
from proveit.physics.quantum.algebra import a_1_to_m_kets, b_1_to_n_kets
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Min(m, n)
sub_expr3 = CartExp(Complex, n)
sub_expr4 = CartExp(Complex, m)
expr = Lambda([m, n], Conditional(Forall(instance_param_or_params = [var_ket_psi], instance_expr = Exists(instance_param_or_params = [a_1_to_m], instance_expr = Exists(instance_param_or_params = [b_1_to_n], instance_expr = Exists(instance_param_or_params = [ExprRange(sub_expr1, IndexedVar(lambda_, sub_expr1), one, sub_expr2)], instance_expr = Equals(var_ket_psi, VecSum(index_or_indices = [i], summand = ScalarMult(lambda_i, Qmult(Ket(a_i), Ket(b_i))), domain = Interval(one, sub_expr2))), domain = RealNonNeg).with_wrapping(), condition = InSet(Set(b_1_to_n_kets), OrthoNormBases(sub_expr3))).with_wrapping(), condition = InSet(Set(a_1_to_m_kets), OrthoNormBases(sub_expr4))).with_wrapping(), domain = TensorProd(sub_expr4, sub_expr3)).with_wrapping(), And(InSet(m, NaturalPos), InSet(n, 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())
\left(m, n\right) \mapsto \left\{\begin{array}{l}\forall_{\lvert \psi \rangle \in \mathbb{C}^{m} {\otimes} \mathbb{C}^{n}}~\\
\left[\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{m}~|~\left\{\left\{\lvert a_{1} \rangle, \lvert a_{2} \rangle, \ldots, \lvert a_{m} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathbb{C}^{m}\right)}~\\
\left[\begin{array}{l}\exists_{b_{1}, b_{2}, \ldots, b_{n}~|~\left\{\left\{\lvert b_{1} \rangle, \lvert b_{2} \rangle, \ldots, \lvert b_{n} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathbb{C}^{n}\right)}~\\
\left[\begin{array}{l}\exists_{\lambda_{1}, \lambda_{2}, \ldots, \lambda_{{\rm Min}\left(m, n\right)} \in \mathbb{R}^{\ge 0}}~\\
\left(\lvert \psi \rangle = \left(\sum_{i=1}^{{\rm Min}\left(m, n\right)} \left(\lambda_{i} \cdot \left(\lvert a_{i} \rangle \thinspace \lvert b_{i} \rangle\right)\right)\right)\right)\end{array}\right]\end{array}\right]\end{array}\right]\end{array} \textrm{ if } m \in \mathbb{N}^+ ,  n \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
0Lambdaparameters: 118
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 68
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameter: 75
body: 11
8Operationoperator: 98
operands: 12
9Operationoperator: 98
operands: 13
10ExprTuple75
11Conditionalvalue: 14
condition: 15
12ExprTuple121, 16
13ExprTuple122, 16
14Operationoperator: 44
operand: 19
15Operationoperator: 98
operands: 18
16Literal
17ExprTuple19
18ExprTuple75, 20
19Lambdaparameters: 21
body: 22
20Operationoperator: 23
operands: 24
21ExprTuple25
22Conditionalvalue: 26
condition: 27
23Literal
24ExprTuple42, 63
25ExprRangelambda_map: 28
start_index: 112
end_index: 121
26Operationoperator: 44
operand: 31
27Operationoperator: 98
operands: 30
28Lambdaparameter: 104
body: 80
29ExprTuple31
30ExprTuple32, 33
31Lambdaparameters: 34
body: 35
32Operationoperator: 70
operand: 41
33Operationoperator: 56
operand: 42
34ExprTuple38
35Conditionalvalue: 39
condition: 40
36ExprTuple41
37ExprTuple42
38ExprRangelambda_map: 43
start_index: 112
end_index: 122
39Operationoperator: 44
operand: 49
40Operationoperator: 98
operands: 46
41Operationoperator: 70
operands: 47
42Operationoperator: 72
operands: 48
43Lambdaparameter: 104
body: 95
44Literal
45ExprTuple49
46ExprTuple50, 51
47ExprTuple52
48ExprTuple79, 121
49Lambdaparameters: 53
body: 54
50Operationoperator: 70
operand: 62
51Operationoperator: 56
operand: 63
52ExprRangelambda_map: 58
start_index: 112
end_index: 121
53ExprTuple59
54Conditionalvalue: 60
condition: 61
55ExprTuple62
56Literal
57ExprTuple63
58Lambdaparameter: 104
body: 64
59ExprRangelambda_map: 65
start_index: 112
end_index: 113
60Operationoperator: 66
operands: 67
61Operationoperator: 68
operands: 69
62Operationoperator: 70
operands: 71
63Operationoperator: 72
operands: 73
64Operationoperator: 115
operand: 80
65Lambdaparameter: 104
body: 93
66Literal
67ExprTuple75, 76
68Literal
69ExprTuple77
70Literal
71ExprTuple78
72Literal
73ExprTuple79, 122
74ExprTuple80
75Variable
76Operationoperator: 81
operand: 85
77ExprRangelambda_map: 83
start_index: 112
end_index: 113
78ExprRangelambda_map: 84
start_index: 112
end_index: 122
79Literal
80IndexedVarvariable: 123
index: 104
81Literal
82ExprTuple85
83Lambdaparameter: 104
body: 86
84Lambdaparameter: 104
body: 87
85Lambdaparameter: 126
body: 88
86Operationoperator: 98
operands: 89
87Operationoperator: 115
operand: 95
88Conditionalvalue: 91
condition: 92
89ExprTuple93, 94
90ExprTuple95
91Operationoperator: 96
operands: 97
92Operationoperator: 98
operands: 99
93IndexedVarvariable: 105
index: 104
94Literal
95IndexedVarvariable: 124
index: 104
96Literal
97ExprTuple101, 102
98Literal
99ExprTuple126, 103
100ExprTuple104
101IndexedVarvariable: 105
index: 126
102Operationoperator: 106
operands: 107
103Operationoperator: 108
operands: 109
104Variable
105Variable
106Literal
107ExprTuple110, 111
108Literal
109ExprTuple112, 113
110Operationoperator: 115
operand: 119
111Operationoperator: 115
operand: 120
112Literal
113Operationoperator: 117
operands: 118
114ExprTuple119
115Literal
116ExprTuple120
117Literal
118ExprTuple121, 122
119IndexedVarvariable: 123
index: 126
120IndexedVarvariable: 124
index: 126
121Variable
122Variable
123Variable
124Variable
125ExprTuple126
126Variable