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, Function, Lambda, f, i, n
from proveit.core_expr_types import a_1_to_n, a_i, v_1_to_n, v_i
from proveit.linear_algebra import Dim, HilbertSpaces, Hspace, OrthoNormBases, ScalarMult, VecSum
from proveit.logic import And, Equals, Forall, Functions, InClass, InSet, Set
from proveit.numbers import Complex, Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
from proveit.physics.quantum.algebra import v_1_to_n_kets
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [i]
sub_expr2 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = Lambda(Hspace, Conditional(Forall(instance_param_or_params = [v_1_to_n], instance_expr = Forall(instance_param_or_params = [a_1_to_n], instance_expr = Forall(instance_param_or_params = [f], instance_expr = Equals(Function(f, [VecSum(index_or_indices = sub_expr1, summand = ScalarMult(a_i, sub_expr3), domain = sub_expr2)]), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(Function(f, [a_i]), sub_expr3), domain = sub_expr2)), domain = Functions(Complex, Complex)), domain = Complex), condition = InSet(Set(v_1_to_n_kets), OrthoNormBases(Hspace))).with_wrapping(), And(InClass(Hspace, HilbertSpaces), Equals(Dim(Hspace), 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())
\mathcal{H} \mapsto \left\{\begin{array}{l}\forall_{v_{1}, v_{2}, \ldots, v_{n}~|~\left\{\left\{\lvert v_{1} \rangle, \lvert v_{2} \rangle, \ldots, \lvert v_{n} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathcal{H}\right)}~\\
\left[\forall_{a_{1}, a_{2}, \ldots, a_{n} \in \mathbb{C}}~\left[\forall_{f \in \left[\mathbb{C} \rightarrow \mathbb{C}\right]}~\left(f\left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right) = \left(\sum_{i=1}^{n} \left(f\left(a_{i}\right) \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right)\right]\right]\end{array} \textrm{ if } \mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces} ,  \textrm{Dim}\left(\mathcal{H}\right) = 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: 35
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 37
operand: 6
3Operationoperator: 39
operands: 5
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameters: 9
body: 10
7Operationoperator: 11
operands: 12
8Operationoperator: 54
operands: 13
9ExprTuple14
10Conditionalvalue: 15
condition: 16
11Literal
12ExprTuple35, 17
13ExprTuple18, 100
14ExprRangelambda_map: 19
start_index: 99
end_index: 100
15Operationoperator: 37
operand: 23
16Operationoperator: 85
operands: 21
17Literal
18Operationoperator: 22
operand: 35
19Lambdaparameter: 72
body: 63
20ExprTuple23
21ExprTuple24, 25
22Literal
23Lambdaparameters: 26
body: 27
24Operationoperator: 41
operand: 34
25Operationoperator: 29
operand: 35
26ExprTuple31
27Conditionalvalue: 32
condition: 33
28ExprTuple34
29Literal
30ExprTuple35
31ExprRangelambda_map: 36
start_index: 99
end_index: 100
32Operationoperator: 37
operand: 43
33Operationoperator: 39
operands: 40
34Operationoperator: 41
operands: 42
35Variable
36Lambdaparameter: 72
body: 62
37Literal
38ExprTuple43
39Literal
40ExprTuple44
41Literal
42ExprTuple45
43Lambdaparameter: 87
body: 47
44ExprRangelambda_map: 48
start_index: 99
end_index: 100
45ExprRangelambda_map: 49
start_index: 99
end_index: 100
46ExprTuple87
47Conditionalvalue: 50
condition: 51
48Lambdaparameter: 72
body: 52
49Lambdaparameter: 72
body: 53
50Operationoperator: 54
operands: 55
51Operationoperator: 85
operands: 56
52Operationoperator: 85
operands: 57
53Operationoperator: 101
operand: 63
54Literal
55ExprTuple59, 60
56ExprTuple87, 61
57ExprTuple62, 71
58ExprTuple63
59Operationoperator: 87
operand: 69
60Operationoperator: 73
operand: 70
61Operationoperator: 66
operands: 67
62IndexedVarvariable: 96
index: 72
63IndexedVarvariable: 105
index: 72
64ExprTuple69
65ExprTuple70
66Literal
67ExprTuple71, 71
68ExprTuple72
69Operationoperator: 73
operand: 76
70Lambdaparameter: 107
body: 75
71Literal
72Variable
73Literal
74ExprTuple76
75Conditionalvalue: 77
condition: 81
76Lambdaparameter: 107
body: 78
77Operationoperator: 83
operands: 79
78Conditionalvalue: 80
condition: 81
79ExprTuple82, 89
80Operationoperator: 83
operands: 84
81Operationoperator: 85
operands: 86
82Operationoperator: 87
operand: 91
83Literal
84ExprTuple91, 89
85Literal
86ExprTuple107, 90
87Variable
88ExprTuple91
89Operationoperator: 92
operands: 93
90Operationoperator: 94
operands: 95
91IndexedVarvariable: 96
index: 107
92Literal
93ExprTuple97, 98
94Literal
95ExprTuple99, 100
96Variable
97Operationoperator: 101
operand: 104
98Operationoperator: 102
operand: 104
99Literal
100Variable
101Literal
102Literal
103ExprTuple104
104IndexedVarvariable: 105
index: 107
105Variable
106ExprTuple107
107Variable