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 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 = [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()
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_{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}
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: 25
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple5
4Conditionalvalue: 6
condition: 7
5ExprRangelambda_map: 8
start_index: 87
end_index: 88
6Operationoperator: 25
operand: 11
7Operationoperator: 73
operands: 10
8Lambdaparameter: 60
body: 51
9ExprTuple11
10ExprTuple12, 13
11Lambdaparameters: 14
body: 15
12Operationoperator: 29
operand: 22
13Operationoperator: 17
operand: 23
14ExprTuple19
15Conditionalvalue: 20
condition: 21
16ExprTuple22
17Literal
18ExprTuple23
19ExprRangelambda_map: 24
start_index: 87
end_index: 88
20Operationoperator: 25
operand: 31
21Operationoperator: 27
operands: 28
22Operationoperator: 29
operands: 30
23Variable
24Lambdaparameter: 60
body: 50
25Literal
26ExprTuple31
27Literal
28ExprTuple32
29Literal
30ExprTuple33
31Lambdaparameter: 75
body: 35
32ExprRangelambda_map: 36
start_index: 87
end_index: 88
33ExprRangelambda_map: 37
start_index: 87
end_index: 88
34ExprTuple75
35Conditionalvalue: 38
condition: 39
36Lambdaparameter: 60
body: 40
37Lambdaparameter: 60
body: 41
38Operationoperator: 42
operands: 43
39Operationoperator: 73
operands: 44
40Operationoperator: 73
operands: 45
41Operationoperator: 89
operand: 51
42Literal
43ExprTuple47, 48
44ExprTuple75, 49
45ExprTuple50, 59
46ExprTuple51
47Operationoperator: 75
operand: 57
48Operationoperator: 61
operand: 58
49Operationoperator: 54
operands: 55
50IndexedVarvariable: 84
index: 60
51IndexedVarvariable: 93
index: 60
52ExprTuple57
53ExprTuple58
54Literal
55ExprTuple59, 59
56ExprTuple60
57Operationoperator: 61
operand: 64
58Lambdaparameter: 95
body: 63
59Literal
60Variable
61Literal
62ExprTuple64
63Conditionalvalue: 65
condition: 69
64Lambdaparameter: 95
body: 66
65Operationoperator: 71
operands: 67
66Conditionalvalue: 68
condition: 69
67ExprTuple70, 77
68Operationoperator: 71
operands: 72
69Operationoperator: 73
operands: 74
70Operationoperator: 75
operand: 79
71Literal
72ExprTuple79, 77
73Literal
74ExprTuple95, 78
75Variable
76ExprTuple79
77Operationoperator: 80
operands: 81
78Operationoperator: 82
operands: 83
79IndexedVarvariable: 84
index: 95
80Literal
81ExprTuple85, 86
82Literal
83ExprTuple87, 88
84Variable
85Operationoperator: 89
operand: 92
86Operationoperator: 90
operand: 92
87Literal
88Variable
89Literal
90Literal
91ExprTuple92
92IndexedVarvariable: 93
index: 95
93Variable
94ExprTuple95
95Variable