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 A, W, i, j, m, n
from proveit.core_expr_types import v_i, w_1_to_n, w_j
from proveit.linear_algebra import OrthoNormBases, VecSum
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
from proveit.physics.quantum.algebra import w_1_to_n_kets
In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [w_1_to_n], instance_expr = Equals(A, VecSum(index_or_indices = [i], summand = VecSum(index_or_indices = [j], summand = Qmult(Bra(w_j), A, Ket(v_i), Ket(w_j), Bra(v_i)), domain = Interval(one, n)), domain = Interval(one, m))), condition = InSet(w_1_to_n_kets, OrthoNormBases(W))).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_{w_{1}, w_{2}, \ldots, w_{n}~|~\left\{\lvert w_{1} \rangle, \lvert w_{2} \rangle, \ldots, \lvert w_{n} \rangle\right\} \in \textrm{O.N.Bases}\left(W\right)}~\\
\left(A = \left(\sum_{i=1}^{m} \left(\sum_{j=1}^{n} \left(\langle w_{j} \rvert \thinspace A \thinspace \lvert v_{i} \rangle \thinspace \lvert w_{j} \rangle \thinspace \langle v_{i} \rvert\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: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameters: 4
body: 5
4ExprTuple6
5Conditionalvalue: 7
condition: 8
6ExprRangelambda_map: 9
start_index: 61
end_index: 62
7Operationoperator: 10
operands: 11
8Operationoperator: 45
operands: 12
9Lambdaparameter: 42
body: 35
10Literal
11ExprTuple48, 13
12ExprTuple14, 15
13Operationoperator: 29
operand: 21
14Operationoperator: 17
operands: 18
15Operationoperator: 19
operand: 23
16ExprTuple21
17Literal
18ExprTuple22
19Literal
20ExprTuple23
21Lambdaparameter: 68
body: 24
22ExprRangelambda_map: 25
start_index: 61
end_index: 62
23Variable
24Conditionalvalue: 26
condition: 27
25Lambdaparameter: 42
body: 28
26Operationoperator: 29
operand: 33
27Operationoperator: 45
operands: 31
28Operationoperator: 53
operand: 35
29Literal
30ExprTuple33
31ExprTuple68, 34
32ExprTuple35
33Lambdaparameter: 67
body: 36
34Operationoperator: 57
operands: 37
35IndexedVarvariable: 63
index: 42
36Conditionalvalue: 39
condition: 40
37ExprTuple61, 41
38ExprTuple42
39Operationoperator: 43
operands: 44
40Operationoperator: 45
operands: 46
41Variable
42Variable
43Literal
44ExprTuple47, 48, 49, 50, 51
45Literal
46ExprTuple67, 52
47Operationoperator: 55
operand: 59
48Variable
49Operationoperator: 53
operand: 60
50Operationoperator: 53
operand: 59
51Operationoperator: 55
operand: 60
52Operationoperator: 57
operands: 58
53Literal
54ExprTuple59
55Literal
56ExprTuple60
57Literal
58ExprTuple61, 62
59IndexedVarvariable: 63
index: 67
60IndexedVarvariable: 65
index: 68
61Literal
62Variable
63Variable
64ExprTuple67
65Variable
66ExprTuple68
67Variable
68Variable