logo

Expression of type Forall

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 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, 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 = 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()
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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 39
operand: 2
1ExprTuple2
2Lambdaparameter: 37
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 39
operand: 8
5Operationoperator: 41
operands: 7
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameters: 11
body: 12
9Operationoperator: 13
operands: 14
10Operationoperator: 56
operands: 15
11ExprTuple16
12Conditionalvalue: 17
condition: 18
13Literal
14ExprTuple37, 19
15ExprTuple20, 102
16ExprRangelambda_map: 21
start_index: 101
end_index: 102
17Operationoperator: 39
operand: 25
18Operationoperator: 87
operands: 23
19Literal
20Operationoperator: 24
operand: 37
21Lambdaparameter: 74
body: 65
22ExprTuple25
23ExprTuple26, 27
24Literal
25Lambdaparameters: 28
body: 29
26Operationoperator: 43
operand: 36
27Operationoperator: 31
operand: 37
28ExprTuple33
29Conditionalvalue: 34
condition: 35
30ExprTuple36
31Literal
32ExprTuple37
33ExprRangelambda_map: 38
start_index: 101
end_index: 102
34Operationoperator: 39
operand: 45
35Operationoperator: 41
operands: 42
36Operationoperator: 43
operands: 44
37Variable
38Lambdaparameter: 74
body: 64
39Literal
40ExprTuple45
41Literal
42ExprTuple46
43Literal
44ExprTuple47
45Lambdaparameter: 89
body: 49
46ExprRangelambda_map: 50
start_index: 101
end_index: 102
47ExprRangelambda_map: 51
start_index: 101
end_index: 102
48ExprTuple89
49Conditionalvalue: 52
condition: 53
50Lambdaparameter: 74
body: 54
51Lambdaparameter: 74
body: 55
52Operationoperator: 56
operands: 57
53Operationoperator: 87
operands: 58
54Operationoperator: 87
operands: 59
55Operationoperator: 103
operand: 65
56Literal
57ExprTuple61, 62
58ExprTuple89, 63
59ExprTuple64, 73
60ExprTuple65
61Operationoperator: 89
operand: 71
62Operationoperator: 75
operand: 72
63Operationoperator: 68
operands: 69
64IndexedVarvariable: 98
index: 74
65IndexedVarvariable: 107
index: 74
66ExprTuple71
67ExprTuple72
68Literal
69ExprTuple73, 73
70ExprTuple74
71Operationoperator: 75
operand: 78
72Lambdaparameter: 109
body: 77
73Literal
74Variable
75Literal
76ExprTuple78
77Conditionalvalue: 79
condition: 83
78Lambdaparameter: 109
body: 80
79Operationoperator: 85
operands: 81
80Conditionalvalue: 82
condition: 83
81ExprTuple84, 91
82Operationoperator: 85
operands: 86
83Operationoperator: 87
operands: 88
84Operationoperator: 89
operand: 93
85Literal
86ExprTuple93, 91
87Literal
88ExprTuple109, 92
89Variable
90ExprTuple93
91Operationoperator: 94
operands: 95
92Operationoperator: 96
operands: 97
93IndexedVarvariable: 98
index: 109
94Literal
95ExprTuple99, 100
96Literal
97ExprTuple101, 102
98Variable
99Operationoperator: 103
operand: 106
100Operationoperator: 104
operand: 106
101Literal
102Variable
103Literal
104Literal
105ExprTuple106
106IndexedVarvariable: 107
index: 109
107Variable
108ExprTuple109
109Variable