logo

Expression of type Conditional

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, f, i, n
from proveit.core_expr_types import a_1_to_n, a_i, 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 = 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\{\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()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 19
operand: 5
2Operationoperator: 67
operands: 4
3ExprTuple5
4ExprTuple6, 7
5Lambdaparameters: 8
body: 9
6Operationoperator: 23
operand: 16
7Operationoperator: 11
operand: 17
8ExprTuple13
9Conditionalvalue: 14
condition: 15
10ExprTuple16
11Literal
12ExprTuple17
13ExprRangelambda_map: 18
start_index: 81
end_index: 82
14Operationoperator: 19
operand: 25
15Operationoperator: 21
operands: 22
16Operationoperator: 23
operands: 24
17Variable
18Lambdaparameter: 54
body: 44
19Literal
20ExprTuple25
21Literal
22ExprTuple26
23Literal
24ExprTuple27
25Lambdaparameter: 69
body: 29
26ExprRangelambda_map: 30
start_index: 81
end_index: 82
27ExprRangelambda_map: 31
start_index: 81
end_index: 82
28ExprTuple69
29Conditionalvalue: 32
condition: 33
30Lambdaparameter: 54
body: 34
31Lambdaparameter: 54
body: 35
32Operationoperator: 36
operands: 37
33Operationoperator: 67
operands: 38
34Operationoperator: 67
operands: 39
35Operationoperator: 83
operand: 45
36Literal
37ExprTuple41, 42
38ExprTuple69, 43
39ExprTuple44, 53
40ExprTuple45
41Operationoperator: 69
operand: 51
42Operationoperator: 55
operand: 52
43Operationoperator: 48
operands: 49
44IndexedVarvariable: 78
index: 54
45IndexedVarvariable: 87
index: 54
46ExprTuple51
47ExprTuple52
48Literal
49ExprTuple53, 53
50ExprTuple54
51Operationoperator: 55
operand: 58
52Lambdaparameter: 89
body: 57
53Literal
54Variable
55Literal
56ExprTuple58
57Conditionalvalue: 59
condition: 63
58Lambdaparameter: 89
body: 60
59Operationoperator: 65
operands: 61
60Conditionalvalue: 62
condition: 63
61ExprTuple64, 71
62Operationoperator: 65
operands: 66
63Operationoperator: 67
operands: 68
64Operationoperator: 69
operand: 73
65Literal
66ExprTuple73, 71
67Literal
68ExprTuple89, 72
69Variable
70ExprTuple73
71Operationoperator: 74
operands: 75
72Operationoperator: 76
operands: 77
73IndexedVarvariable: 78
index: 89
74Literal
75ExprTuple79, 80
76Literal
77ExprTuple81, 82
78Variable
79Operationoperator: 83
operand: 86
80Operationoperator: 84
operand: 86
81Literal
82Variable
83Literal
84Literal
85ExprTuple86
86IndexedVarvariable: 87
index: 89
87Variable
88ExprTuple89
89Variable