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 HilbertSpaces, 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 = [Hspace], instance_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)), domain = HilbertSpaces)
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_{\mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces}}~\left[\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]\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: 23
operand: 2
1ExprTuple2
2Lambdaparameter: 52
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 23
operand: 9
5Operationoperator: 7
operands: 8
6ExprTuple9
7Literal
8ExprTuple52, 10
9Lambdaparameter: 49
body: 12
10Literal
11ExprTuple49
12Conditionalvalue: 13
condition: 14
13Operationoperator: 23
operand: 18
14Operationoperator: 16
operands: 17
15ExprTuple18
16Literal
17ExprTuple49, 52
18Lambdaparameter: 75
body: 20
19ExprTuple75
20Conditionalvalue: 21
condition: 22
21Operationoperator: 23
operand: 26
22Operationoperator: 60
operands: 25
23Literal
24ExprTuple26
25ExprTuple75, 27
26Lambdaparameters: 28
body: 29
27Literal
28ExprTuple30
29Conditionalvalue: 31
condition: 32
30ExprRangelambda_map: 33
start_index: 74
end_index: 75
31Operationoperator: 34
operands: 35
32Operationoperator: 60
operands: 36
33Lambdaparameter: 76
body: 66
34Literal
35ExprTuple37, 38
36ExprTuple39, 40
37Operationoperator: 41
operands: 42
38Operationoperator: 43
operand: 50
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operand: 52
41Literal
42ExprTuple52, 49
43Literal
44ExprTuple50
45Literal
46ExprTuple51
47Literal
48ExprTuple52
49Variable
50Lambdaparameter: 79
body: 53
51ExprRangelambda_map: 54
start_index: 74
end_index: 75
52Variable
53Conditionalvalue: 55
condition: 56
54Lambdaparameter: 76
body: 57
55Operationoperator: 58
operands: 59
56Operationoperator: 60
operands: 61
57Operationoperator: 67
operand: 66
58Literal
59ExprTuple63, 64
60Literal
61ExprTuple79, 65
62ExprTuple66
63Operationoperator: 67
operand: 73
64Operationoperator: 68
operand: 73
65Operationoperator: 70
operands: 71
66IndexedVarvariable: 77
index: 76
67Literal
68Literal
69ExprTuple73
70Literal
71ExprTuple74, 75
72ExprTuple76
73IndexedVarvariable: 77
index: 79
74Literal
75Variable
76Variable
77Variable
78ExprTuple79
79Variable