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_i, b_1_to_n, b_i, lambda_i
from proveit.linear_algebra import OrthoNormBases, ScalarMult, VecSum
from proveit.logic import CartExp, Equals, Exists, InSet, Set
from proveit.numbers import Complex, Interval, Min, RealNonNeg, one
from proveit.physics.quantum import Ket, Qmult, var_ket_psi
from proveit.physics.quantum.algebra import 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)
expr = Lambda([b_1_to_n], Conditional(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(), InSet(Set(b_1_to_n_kets), OrthoNormBases(CartExp(Complex, n)))))
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(b_{1}, b_{2}, \ldots, b_{n}\right) \mapsto \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} \textrm{ if } \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)\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
1ExprTuple3
2Conditionalvalue: 4
condition: 5
3ExprRangelambda_map: 6
start_index: 68
end_index: 78
4Operationoperator: 7
operand: 10
5Operationoperator: 54
operands: 9
6Lambdaparameter: 60
body: 51
7Literal
8ExprTuple10
9ExprTuple11, 12
10Lambdaparameters: 13
body: 14
11Operationoperator: 28
operand: 21
12Operationoperator: 16
operand: 22
13ExprTuple18
14Conditionalvalue: 19
condition: 20
15ExprTuple21
16Literal
17ExprTuple22
18ExprRangelambda_map: 23
start_index: 68
end_index: 69
19Operationoperator: 24
operands: 25
20Operationoperator: 26
operands: 27
21Operationoperator: 28
operands: 29
22Operationoperator: 30
operands: 31
23Lambdaparameter: 60
body: 49
24Literal
25ExprTuple32, 33
26Literal
27ExprTuple34
28Literal
29ExprTuple35
30Literal
31ExprTuple36, 78
32Variable
33Operationoperator: 37
operand: 41
34ExprRangelambda_map: 39
start_index: 68
end_index: 69
35ExprRangelambda_map: 40
start_index: 68
end_index: 78
36Literal
37Literal
38ExprTuple41
39Lambdaparameter: 60
body: 42
40Lambdaparameter: 60
body: 43
41Lambdaparameter: 82
body: 44
42Operationoperator: 54
operands: 45
43Operationoperator: 71
operand: 51
44Conditionalvalue: 47
condition: 48
45ExprTuple49, 50
46ExprTuple51
47Operationoperator: 52
operands: 53
48Operationoperator: 54
operands: 55
49IndexedVarvariable: 61
index: 60
50Literal
51IndexedVarvariable: 80
index: 60
52Literal
53ExprTuple57, 58
54Literal
55ExprTuple82, 59
56ExprTuple60
57IndexedVarvariable: 61
index: 82
58Operationoperator: 62
operands: 63
59Operationoperator: 64
operands: 65
60Variable
61Variable
62Literal
63ExprTuple66, 67
64Literal
65ExprTuple68, 69
66Operationoperator: 71
operand: 75
67Operationoperator: 71
operand: 76
68Literal
69Operationoperator: 73
operands: 74
70ExprTuple75
71Literal
72ExprTuple76
73Literal
74ExprTuple77, 78
75IndexedVarvariable: 79
index: 82
76IndexedVarvariable: 80
index: 82
77Variable
78Variable
79Variable
80Variable
81ExprTuple82
82Variable