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 X, i, n
from proveit.core_expr_types import x_1_to_n, x_i
from proveit.linear_algebra import Hspace, OrthoNormBases, OrthoProj, VecSum
from proveit.logic import Equals, Forall, InSet, SubsetEq
from proveit.numbers import Interval, NaturalPos, one
from proveit.physics.quantum import Bra, Ket, Qmult
from proveit.physics.quantum.algebra import x_1_to_n_kets
In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [X], instance_expr = Forall(instance_param_or_params = [n], instance_expr = Forall(instance_param_or_params = [x_1_to_n], instance_expr = Equals(OrthoProj(Hspace, X), VecSum(index_or_indices = [i], summand = Qmult(Ket(x_i), Bra(x_i)), domain = Interval(one, n))), condition = InSet(x_1_to_n_kets, OrthoNormBases(Hspace))).with_wrapping(), domain = NaturalPos), condition = SubsetEq(X, Hspace))
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_{X~|~X \subseteq \mathcal{H}}~\left[\forall_{n \in \mathbb{N}^+}~\left[\begin{array}{l}\forall_{x_{1}, x_{2}, \ldots, x_{n}~|~\left\{\lvert x_{1} \rangle, \lvert x_{2} \rangle, \ldots, \lvert x_{n} \rangle\right\} \in \textrm{O.N.Bases}\left(\mathcal{H}\right)}~\\
\left(\textrm{OrthoProj}\left(\mathcal{H}, X\right) = \left(\sum_{i=1}^{n} \left(\lvert x_{i} \rangle \thinspace \langle x_{i} \rvert\right)\right)\right)\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: 15
operand: 2
1ExprTuple2
2Lambdaparameter: 41
body: 4
3ExprTuple41
4Conditionalvalue: 5
condition: 6
5Operationoperator: 15
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple41, 44
10Lambdaparameter: 67
body: 12
11ExprTuple67
12Conditionalvalue: 13
condition: 14
13Operationoperator: 15
operand: 18
14Operationoperator: 52
operands: 17
15Literal
16ExprTuple18
17ExprTuple67, 19
18Lambdaparameters: 20
body: 21
19Literal
20ExprTuple22
21Conditionalvalue: 23
condition: 24
22ExprRangelambda_map: 25
start_index: 66
end_index: 67
23Operationoperator: 26
operands: 27
24Operationoperator: 52
operands: 28
25Lambdaparameter: 68
body: 58
26Literal
27ExprTuple29, 30
28ExprTuple31, 32
29Operationoperator: 33
operands: 34
30Operationoperator: 35
operand: 42
31Operationoperator: 37
operands: 38
32Operationoperator: 39
operand: 44
33Literal
34ExprTuple44, 41
35Literal
36ExprTuple42
37Literal
38ExprTuple43
39Literal
40ExprTuple44
41Variable
42Lambdaparameter: 71
body: 45
43ExprRangelambda_map: 46
start_index: 66
end_index: 67
44Variable
45Conditionalvalue: 47
condition: 48
46Lambdaparameter: 68
body: 49
47Operationoperator: 50
operands: 51
48Operationoperator: 52
operands: 53
49Operationoperator: 59
operand: 58
50Literal
51ExprTuple55, 56
52Literal
53ExprTuple71, 57
54ExprTuple58
55Operationoperator: 59
operand: 65
56Operationoperator: 60
operand: 65
57Operationoperator: 62
operands: 63
58IndexedVarvariable: 69
index: 68
59Literal
60Literal
61ExprTuple65
62Literal
63ExprTuple66, 67
64ExprTuple68
65IndexedVarvariable: 69
index: 71
66Literal
67Variable
68Variable
69Variable
70ExprTuple71
71Variable