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 Equals, Forall, Functions, InSet, Set
from proveit.numbers import Complex, Interval, NaturalPos, 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 = [Hspace], instance_expr = 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(), domain = HilbertSpaces, condition = Equals(Dim(Hspace), n)).with_wrapping(), InSet(n, NaturalPos))
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_{\mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces}~|~\textrm{Dim}\left(\mathcal{H}\right) = n}~\\
\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}\right]\end{array} \textrm{ if } n \in \mathbb{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: 43
operand: 5
2Operationoperator: 91
operands: 4
3ExprTuple5
4ExprTuple106, 6
5Lambdaparameter: 41
body: 7
6Literal
7Conditionalvalue: 8
condition: 9
8Operationoperator: 43
operand: 12
9Operationoperator: 45
operands: 11
10ExprTuple12
11ExprTuple13, 14
12Lambdaparameters: 15
body: 16
13Operationoperator: 17
operands: 18
14Operationoperator: 60
operands: 19
15ExprTuple20
16Conditionalvalue: 21
condition: 22
17Literal
18ExprTuple41, 23
19ExprTuple24, 106
20ExprRangelambda_map: 25
start_index: 105
end_index: 106
21Operationoperator: 43
operand: 29
22Operationoperator: 91
operands: 27
23Literal
24Operationoperator: 28
operand: 41
25Lambdaparameter: 78
body: 69
26ExprTuple29
27ExprTuple30, 31
28Literal
29Lambdaparameters: 32
body: 33
30Operationoperator: 47
operand: 40
31Operationoperator: 35
operand: 41
32ExprTuple37
33Conditionalvalue: 38
condition: 39
34ExprTuple40
35Literal
36ExprTuple41
37ExprRangelambda_map: 42
start_index: 105
end_index: 106
38Operationoperator: 43
operand: 49
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operands: 48
41Variable
42Lambdaparameter: 78
body: 68
43Literal
44ExprTuple49
45Literal
46ExprTuple50
47Literal
48ExprTuple51
49Lambdaparameter: 93
body: 53
50ExprRangelambda_map: 54
start_index: 105
end_index: 106
51ExprRangelambda_map: 55
start_index: 105
end_index: 106
52ExprTuple93
53Conditionalvalue: 56
condition: 57
54Lambdaparameter: 78
body: 58
55Lambdaparameter: 78
body: 59
56Operationoperator: 60
operands: 61
57Operationoperator: 91
operands: 62
58Operationoperator: 91
operands: 63
59Operationoperator: 107
operand: 69
60Literal
61ExprTuple65, 66
62ExprTuple93, 67
63ExprTuple68, 77
64ExprTuple69
65Operationoperator: 93
operand: 75
66Operationoperator: 79
operand: 76
67Operationoperator: 72
operands: 73
68IndexedVarvariable: 102
index: 78
69IndexedVarvariable: 111
index: 78
70ExprTuple75
71ExprTuple76
72Literal
73ExprTuple77, 77
74ExprTuple78
75Operationoperator: 79
operand: 82
76Lambdaparameter: 113
body: 81
77Literal
78Variable
79Literal
80ExprTuple82
81Conditionalvalue: 83
condition: 87
82Lambdaparameter: 113
body: 84
83Operationoperator: 89
operands: 85
84Conditionalvalue: 86
condition: 87
85ExprTuple88, 95
86Operationoperator: 89
operands: 90
87Operationoperator: 91
operands: 92
88Operationoperator: 93
operand: 97
89Literal
90ExprTuple97, 95
91Literal
92ExprTuple113, 96
93Variable
94ExprTuple97
95Operationoperator: 98
operands: 99
96Operationoperator: 100
operands: 101
97IndexedVarvariable: 102
index: 113
98Literal
99ExprTuple103, 104
100Literal
101ExprTuple105, 106
102Variable
103Operationoperator: 107
operand: 110
104Operationoperator: 108
operand: 110
105Literal
106Variable
107Literal
108Literal
109ExprTuple110
110IndexedVarvariable: 111
index: 113
111Variable
112ExprTuple113
113Variable