logo

Expression of type ExprTuple

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, ExprTuple, 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 = ExprTuple(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(\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..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameters: 2
body: 3
2ExprTuple4
3Conditionalvalue: 5
condition: 6
4ExprRangelambda_map: 7
start_index: 63
end_index: 64
5Operationoperator: 8
operand: 12
6Operationoperator: 10
operands: 11
7Lambdaparameter: 36
body: 27
8Literal
9ExprTuple12
10Literal
11ExprTuple13
12Lambdaparameter: 51
body: 15
13ExprRangelambda_map: 16
start_index: 63
end_index: 64
14ExprTuple51
15Conditionalvalue: 17
condition: 18
16Lambdaparameter: 36
body: 19
17Operationoperator: 20
operands: 21
18Operationoperator: 49
operands: 22
19Operationoperator: 49
operands: 23
20Literal
21ExprTuple24, 25
22ExprTuple51, 26
23ExprTuple27, 35
24Operationoperator: 51
operand: 33
25Operationoperator: 37
operand: 34
26Operationoperator: 30
operands: 31
27IndexedVarvariable: 60
index: 36
28ExprTuple33
29ExprTuple34
30Literal
31ExprTuple35, 35
32ExprTuple36
33Operationoperator: 37
operand: 40
34Lambdaparameter: 71
body: 39
35Literal
36Variable
37Literal
38ExprTuple40
39Conditionalvalue: 41
condition: 45
40Lambdaparameter: 71
body: 42
41Operationoperator: 47
operands: 43
42Conditionalvalue: 44
condition: 45
43ExprTuple46, 53
44Operationoperator: 47
operands: 48
45Operationoperator: 49
operands: 50
46Operationoperator: 51
operand: 55
47Literal
48ExprTuple55, 53
49Literal
50ExprTuple71, 54
51Variable
52ExprTuple55
53Operationoperator: 56
operands: 57
54Operationoperator: 58
operands: 59
55IndexedVarvariable: 60
index: 71
56Literal
57ExprTuple61, 62
58Literal
59ExprTuple63, 64
60Variable
61Operationoperator: 65
operand: 68
62Operationoperator: 66
operand: 68
63Literal
64Variable
65Literal
66Literal
67ExprTuple68
68IndexedVarvariable: 69
index: 71
69Variable
70ExprTuple71
71Variable