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, Function, IndexedVar, Lambda, Variable, a, f, i, n
from proveit.core_expr_types import a_1_to_n, a_i, v_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import And, Equals, Forall, Functions, InSet
from proveit.numbers import Complex, Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = [i]
sub_expr3 = Interval(one, n)
sub_expr4 = Qmult(Ket(v_i), Bra(v_i))
expr = Lambda([a_1_to_n], Conditional(Forall(instance_param_or_params = [f], instance_expr = Equals(Function(f, [VecSum(index_or_indices = sub_expr2, summand = ScalarMult(a_i, sub_expr4), domain = sub_expr3)]), VecSum(index_or_indices = sub_expr2, summand = ScalarMult(Function(f, [a_i]), sub_expr4), domain = sub_expr3)), domain = Functions(Complex, Complex)), And(ExprRange(sub_expr1, InSet(IndexedVar(a, sub_expr1), Complex), one, 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(a_{1}, a_{2}, \ldots, a_{n}\right) \mapsto \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) \textrm{ if } \left(a_{1} \in \mathbb{C}\right) \land  \left(a_{2} \in \mathbb{C}\right) \land  \ldots \land  \left(a_{n} \in \mathbb{C}\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: 62
end_index: 63
4Operationoperator: 7
operand: 11
5Operationoperator: 9
operands: 10
6Lambdaparameter: 35
body: 26
7Literal
8ExprTuple11
9Literal
10ExprTuple12
11Lambdaparameter: 50
body: 14
12ExprRangelambda_map: 15
start_index: 62
end_index: 63
13ExprTuple50
14Conditionalvalue: 16
condition: 17
15Lambdaparameter: 35
body: 18
16Operationoperator: 19
operands: 20
17Operationoperator: 48
operands: 21
18Operationoperator: 48
operands: 22
19Literal
20ExprTuple23, 24
21ExprTuple50, 25
22ExprTuple26, 34
23Operationoperator: 50
operand: 32
24Operationoperator: 36
operand: 33
25Operationoperator: 29
operands: 30
26IndexedVarvariable: 59
index: 35
27ExprTuple32
28ExprTuple33
29Literal
30ExprTuple34, 34
31ExprTuple35
32Operationoperator: 36
operand: 39
33Lambdaparameter: 70
body: 38
34Literal
35Variable
36Literal
37ExprTuple39
38Conditionalvalue: 40
condition: 44
39Lambdaparameter: 70
body: 41
40Operationoperator: 46
operands: 42
41Conditionalvalue: 43
condition: 44
42ExprTuple45, 52
43Operationoperator: 46
operands: 47
44Operationoperator: 48
operands: 49
45Operationoperator: 50
operand: 54
46Literal
47ExprTuple54, 52
48Literal
49ExprTuple70, 53
50Variable
51ExprTuple54
52Operationoperator: 55
operands: 56
53Operationoperator: 57
operands: 58
54IndexedVarvariable: 59
index: 70
55Literal
56ExprTuple60, 61
57Literal
58ExprTuple62, 63
59Variable
60Operationoperator: 64
operand: 67
61Operationoperator: 65
operand: 67
62Literal
63Variable
64Literal
65Literal
66ExprTuple67
67IndexedVarvariable: 68
index: 70
68Variable
69ExprTuple70
70Variable