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 Hspace, OrthoNormBases, ScalarMult, VecSum
from proveit.logic import Equals, Forall, Functions, 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([v_1_to_n], Conditional(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), InSet(Set(v_1_to_n_kets), OrthoNormBases(Hspace))))
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(v_{1}, v_{2}, \ldots, v_{n}\right) \mapsto \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] \textrm{ if } \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)\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: 85
end_index: 86
4Operationoperator: 23
operand: 9
5Operationoperator: 71
operands: 8
6Lambdaparameter: 58
body: 49
7ExprTuple9
8ExprTuple10, 11
9Lambdaparameters: 12
body: 13
10Operationoperator: 27
operand: 20
11Operationoperator: 15
operand: 21
12ExprTuple17
13Conditionalvalue: 18
condition: 19
14ExprTuple20
15Literal
16ExprTuple21
17ExprRangelambda_map: 22
start_index: 85
end_index: 86
18Operationoperator: 23
operand: 29
19Operationoperator: 25
operands: 26
20Operationoperator: 27
operands: 28
21Variable
22Lambdaparameter: 58
body: 48
23Literal
24ExprTuple29
25Literal
26ExprTuple30
27Literal
28ExprTuple31
29Lambdaparameter: 73
body: 33
30ExprRangelambda_map: 34
start_index: 85
end_index: 86
31ExprRangelambda_map: 35
start_index: 85
end_index: 86
32ExprTuple73
33Conditionalvalue: 36
condition: 37
34Lambdaparameter: 58
body: 38
35Lambdaparameter: 58
body: 39
36Operationoperator: 40
operands: 41
37Operationoperator: 71
operands: 42
38Operationoperator: 71
operands: 43
39Operationoperator: 87
operand: 49
40Literal
41ExprTuple45, 46
42ExprTuple73, 47
43ExprTuple48, 57
44ExprTuple49
45Operationoperator: 73
operand: 55
46Operationoperator: 59
operand: 56
47Operationoperator: 52
operands: 53
48IndexedVarvariable: 82
index: 58
49IndexedVarvariable: 91
index: 58
50ExprTuple55
51ExprTuple56
52Literal
53ExprTuple57, 57
54ExprTuple58
55Operationoperator: 59
operand: 62
56Lambdaparameter: 93
body: 61
57Literal
58Variable
59Literal
60ExprTuple62
61Conditionalvalue: 63
condition: 67
62Lambdaparameter: 93
body: 64
63Operationoperator: 69
operands: 65
64Conditionalvalue: 66
condition: 67
65ExprTuple68, 75
66Operationoperator: 69
operands: 70
67Operationoperator: 71
operands: 72
68Operationoperator: 73
operand: 77
69Literal
70ExprTuple77, 75
71Literal
72ExprTuple93, 76
73Variable
74ExprTuple77
75Operationoperator: 78
operands: 79
76Operationoperator: 80
operands: 81
77IndexedVarvariable: 82
index: 93
78Literal
79ExprTuple83, 84
80Literal
81ExprTuple85, 86
82Variable
83Operationoperator: 87
operand: 90
84Operationoperator: 88
operand: 90
85Literal
86Variable
87Literal
88Literal
89ExprTuple90
90IndexedVarvariable: 91
index: 93
91Variable
92ExprTuple93
93Variable