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 A, B, Conditional, Lambda, i, n
from proveit.core_expr_types import a_1_to_n, a_i, b_1_to_n, b_i, v_1_to_n, v_i
from proveit.linear_algebra import OrthoNormBases, ScalarMult, VecSum
from proveit.logic import And, CartExp, Equals, Exists, InSet, Set
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 = [i]
sub_expr2 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = Lambda([v_1_to_n], Conditional(Exists(instance_param_or_params = [a_1_to_n, b_1_to_n], instance_expr = And(Equals(A, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(a_i, sub_expr3), domain = sub_expr2)), Equals(B, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(b_i, sub_expr3), domain = sub_expr2))).with_wrapping_at(2), domain = Complex).with_wrapping(), InSet(Set(v_1_to_n), 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(v_{1}, v_{2}, \ldots, v_{n}\right) \mapsto \left\{\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{n}, b_{1}, b_{2}, \ldots, b_{n} \in \mathbb{C}}~\\
\left(\begin{array}{c} \left(A = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \land  \\ \left(B = \left(\sum_{i=1}^{n} \left(b_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \end{array}\right)\end{array} \textrm{ if } \left\{v_{1}, v_{2}, \ldots, v_{n}\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: 13
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 66
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameters: 10
body: 11
8Operationoperator: 12
operands: 13
9Operationoperator: 14
operand: 21
10ExprTuple16, 17
11Conditionalvalue: 18
condition: 19
12Literal
13ExprTuple20
14Literal
15ExprTuple21
16ExprRangelambda_map: 22
start_index: 80
end_index: 81
17ExprRangelambda_map: 23
start_index: 80
end_index: 81
18Operationoperator: 25
operands: 24
19Operationoperator: 25
operands: 26
20ExprRangelambda_map: 27
start_index: 80
end_index: 81
21Operationoperator: 28
operands: 29
22Lambdaparameter: 62
body: 53
23Lambdaparameter: 62
body: 54
24ExprTuple30, 31
25Literal
26ExprTuple32, 33
27Lambdaparameter: 62
body: 34
28Literal
29ExprTuple55, 81
30Operationoperator: 36
operands: 35
31Operationoperator: 36
operands: 37
32ExprRangelambda_map: 38
start_index: 80
end_index: 81
33ExprRangelambda_map: 39
start_index: 80
end_index: 81
34IndexedVarvariable: 86
index: 62
35ExprTuple40, 41
36Literal
37ExprTuple42, 43
38Lambdaparameter: 62
body: 44
39Lambdaparameter: 62
body: 45
40Variable
41Operationoperator: 47
operand: 51
42Variable
43Operationoperator: 47
operand: 52
44Operationoperator: 66
operands: 49
45Operationoperator: 66
operands: 50
46ExprTuple51
47Literal
48ExprTuple52
49ExprTuple53, 55
50ExprTuple54, 55
51Lambdaparameter: 88
body: 56
52Lambdaparameter: 88
body: 57
53IndexedVarvariable: 72
index: 62
54IndexedVarvariable: 73
index: 62
55Literal
56Conditionalvalue: 59
condition: 61
57Conditionalvalue: 60
condition: 61
58ExprTuple62
59Operationoperator: 64
operands: 63
60Operationoperator: 64
operands: 65
61Operationoperator: 66
operands: 67
62Variable
63ExprTuple68, 70
64Literal
65ExprTuple69, 70
66Literal
67ExprTuple88, 71
68IndexedVarvariable: 72
index: 88
69IndexedVarvariable: 73
index: 88
70Operationoperator: 74
operands: 75
71Operationoperator: 76
operands: 77
72Variable
73Variable
74Literal
75ExprTuple78, 79
76Literal
77ExprTuple80, 81
78Operationoperator: 82
operand: 85
79Operationoperator: 83
operand: 85
80Literal
81Variable
82Literal
83Literal
84ExprTuple85
85IndexedVarvariable: 86
index: 88
86Variable
87ExprTuple88
88Variable