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_1_to_n, v_i
from proveit.linear_algebra import Dim, HilbertSpaces, Hspace, OrthoNormBases, ScalarMult, VecSum
from proveit.logic import And, Equals, Forall, Functions, InClass, 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 = [v_1_to_n], instance_expr = 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), condition = InSet(Set(v_1_to_n_kets), OrthoNormBases(Hspace))).with_wrapping(), And(InClass(Hspace, HilbertSpaces), Equals(Dim(Hspace), 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\{\begin{array}{l}\forall_{v_{1}, v_{2}, \ldots, v_{n}~|~\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)}~\\
\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]\right]\end{array} \textrm{ if } \mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces} ,  \textrm{Dim}\left(\mathcal{H}\right) = n\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: 36
operand: 5
2Operationoperator: 38
operands: 4
3ExprTuple5
4ExprTuple6, 7
5Lambdaparameters: 8
body: 9
6Operationoperator: 10
operands: 11
7Operationoperator: 53
operands: 12
8ExprTuple13
9Conditionalvalue: 14
condition: 15
10Literal
11ExprTuple34, 16
12ExprTuple17, 99
13ExprRangelambda_map: 18
start_index: 98
end_index: 99
14Operationoperator: 36
operand: 22
15Operationoperator: 84
operands: 20
16Literal
17Operationoperator: 21
operand: 34
18Lambdaparameter: 71
body: 62
19ExprTuple22
20ExprTuple23, 24
21Literal
22Lambdaparameters: 25
body: 26
23Operationoperator: 40
operand: 33
24Operationoperator: 28
operand: 34
25ExprTuple30
26Conditionalvalue: 31
condition: 32
27ExprTuple33
28Literal
29ExprTuple34
30ExprRangelambda_map: 35
start_index: 98
end_index: 99
31Operationoperator: 36
operand: 42
32Operationoperator: 38
operands: 39
33Operationoperator: 40
operands: 41
34Variable
35Lambdaparameter: 71
body: 61
36Literal
37ExprTuple42
38Literal
39ExprTuple43
40Literal
41ExprTuple44
42Lambdaparameter: 86
body: 46
43ExprRangelambda_map: 47
start_index: 98
end_index: 99
44ExprRangelambda_map: 48
start_index: 98
end_index: 99
45ExprTuple86
46Conditionalvalue: 49
condition: 50
47Lambdaparameter: 71
body: 51
48Lambdaparameter: 71
body: 52
49Operationoperator: 53
operands: 54
50Operationoperator: 84
operands: 55
51Operationoperator: 84
operands: 56
52Operationoperator: 100
operand: 62
53Literal
54ExprTuple58, 59
55ExprTuple86, 60
56ExprTuple61, 70
57ExprTuple62
58Operationoperator: 86
operand: 68
59Operationoperator: 72
operand: 69
60Operationoperator: 65
operands: 66
61IndexedVarvariable: 95
index: 71
62IndexedVarvariable: 104
index: 71
63ExprTuple68
64ExprTuple69
65Literal
66ExprTuple70, 70
67ExprTuple71
68Operationoperator: 72
operand: 75
69Lambdaparameter: 106
body: 74
70Literal
71Variable
72Literal
73ExprTuple75
74Conditionalvalue: 76
condition: 80
75Lambdaparameter: 106
body: 77
76Operationoperator: 82
operands: 78
77Conditionalvalue: 79
condition: 80
78ExprTuple81, 88
79Operationoperator: 82
operands: 83
80Operationoperator: 84
operands: 85
81Operationoperator: 86
operand: 90
82Literal
83ExprTuple90, 88
84Literal
85ExprTuple106, 89
86Variable
87ExprTuple90
88Operationoperator: 91
operands: 92
89Operationoperator: 93
operands: 94
90IndexedVarvariable: 95
index: 106
91Literal
92ExprTuple96, 97
93Literal
94ExprTuple98, 99
95Variable
96Operationoperator: 100
operand: 103
97Operationoperator: 101
operand: 103
98Literal
99Variable
100Literal
101Literal
102ExprTuple103
103IndexedVarvariable: 104
index: 106
104Variable
105ExprTuple106
106Variable