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 M, 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 Adj, MatrixSpace, OrthoNormBases, ScalarMult, VecSum
from proveit.logic import CartExp, Equals, Exists, Forall, Iff, 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 = Adj(M)
expr = Forall(instance_param_or_params = [n], instance_expr = Forall(instance_param_or_params = [M], instance_expr = Iff(Equals(Qmult(sub_expr1, M), Qmult(M, sub_expr1)), Exists(instance_param_or_params = [v_1_to_n], instance_expr = Exists(instance_param_or_params = [a_1_to_n], instance_expr = Equals(M, VecSum(index_or_indices = [i], summand = ScalarMult(a_i, Qmult(Ket(v_i), Bra(v_i))), domain = Interval(one, n))), domain = Complex).with_wrapping(), condition = InSet(Set(v_1_to_n_kets), OrthoNormBases(CartExp(Complex, n)))).with_wrapping()).with_wrapping_at(2), domain = MatrixSpace(field = Complex, rows = n, columns = n)), domain = 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())
\forall_{n \in \mathbb{N}^+}~\left[\forall_{M \in \mathbb{C}^{n \times n}}~\left(\begin{array}{c} \begin{array}{l} \left(\left(M^{\dagger} \thinspace M\right) = \left(M \thinspace M^{\dagger}\right)\right) \Leftrightarrow  \\ \left[\begin{array}{l}\exists_{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(\mathbb{C}^{n}\right)}~\\
\left[\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{n} \in \mathbb{C}}~\\
\left(M = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right)\end{array}\right]\end{array}\right] \end{array} \end{array}\right)\right]
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('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: 7
operand: 2
1ExprTuple2
2Lambdaparameter: 100
body: 4
3ExprTuple100
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 85
operands: 9
7Literal
8ExprTuple10
9ExprTuple100, 11
10Lambdaparameter: 64
body: 12
11Literal
12Conditionalvalue: 13
condition: 14
13Operationoperator: 15
operands: 16
14Operationoperator: 85
operands: 17
15Literal
16ExprTuple18, 19
17ExprTuple64, 20
18Operationoperator: 56
operands: 21
19Operationoperator: 39
operand: 27
20Operationoperator: 23
operands: 24
21ExprTuple25, 26
22ExprTuple27
23Literal
24NamedExprsfield: 81
rows: 100
columns: 100
25Operationoperator: 93
operands: 28
26Operationoperator: 93
operands: 29
27Lambdaparameters: 30
body: 31
28ExprTuple32, 64
29ExprTuple64, 32
30ExprTuple33
31Conditionalvalue: 34
condition: 35
32Operationoperator: 36
operand: 64
33ExprRangelambda_map: 38
start_index: 99
end_index: 100
34Operationoperator: 39
operand: 42
35Operationoperator: 85
operands: 41
36Literal
37ExprTuple64
38Lambdaparameter: 91
body: 82
39Literal
40ExprTuple42
41ExprTuple43, 44
42Lambdaparameters: 45
body: 46
43Operationoperator: 60
operand: 53
44Operationoperator: 48
operand: 54
45ExprTuple50
46Conditionalvalue: 51
condition: 52
47ExprTuple53
48Literal
49ExprTuple54
50ExprRangelambda_map: 55
start_index: 99
end_index: 100
51Operationoperator: 56
operands: 57
52Operationoperator: 58
operands: 59
53Operationoperator: 60
operands: 61
54Operationoperator: 62
operands: 63
55Lambdaparameter: 91
body: 80
56Literal
57ExprTuple64, 65
58Literal
59ExprTuple66
60Literal
61ExprTuple67
62Literal
63ExprTuple81, 100
64Variable
65Operationoperator: 68
operand: 72
66ExprRangelambda_map: 70
start_index: 99
end_index: 100
67ExprRangelambda_map: 71
start_index: 99
end_index: 100
68Literal
69ExprTuple72
70Lambdaparameter: 91
body: 73
71Lambdaparameter: 91
body: 74
72Lambdaparameter: 107
body: 75
73Operationoperator: 85
operands: 76
74Operationoperator: 101
operand: 82
75Conditionalvalue: 78
condition: 79
76ExprTuple80, 81
77ExprTuple82
78Operationoperator: 83
operands: 84
79Operationoperator: 85
operands: 86
80IndexedVarvariable: 92
index: 91
81Literal
82IndexedVarvariable: 105
index: 91
83Literal
84ExprTuple88, 89
85Literal
86ExprTuple107, 90
87ExprTuple91
88IndexedVarvariable: 92
index: 107
89Operationoperator: 93
operands: 94
90Operationoperator: 95
operands: 96
91Variable
92Variable
93Literal
94ExprTuple97, 98
95Literal
96ExprTuple99, 100
97Operationoperator: 101
operand: 104
98Operationoperator: 102
operand: 104
99Literal
100Variable
101Literal
102Literal
103ExprTuple104
104IndexedVarvariable: 105
index: 107
105Variable
106ExprTuple107
107Variable