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
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 = [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)
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[\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]
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: 59
body: 4
3ExprTuple59
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 44
operands: 9
7Literal
8ExprTuple10
9ExprTuple59, 11
10Lambdaparameters: 12
body: 13
11Literal
12ExprTuple14
13Conditionalvalue: 15
condition: 16
14ExprRangelambda_map: 17
start_index: 58
end_index: 59
15Operationoperator: 18
operands: 19
16Operationoperator: 44
operands: 20
17Lambdaparameter: 60
body: 50
18Literal
19ExprTuple21, 22
20ExprTuple23, 24
21Operationoperator: 25
operands: 26
22Operationoperator: 27
operand: 34
23Operationoperator: 29
operands: 30
24Operationoperator: 31
operand: 36
25Literal
26ExprTuple36, 33
27Literal
28ExprTuple34
29Literal
30ExprTuple35
31Literal
32ExprTuple36
33Variable
34Lambdaparameter: 63
body: 37
35ExprRangelambda_map: 38
start_index: 58
end_index: 59
36Variable
37Conditionalvalue: 39
condition: 40
38Lambdaparameter: 60
body: 41
39Operationoperator: 42
operands: 43
40Operationoperator: 44
operands: 45
41Operationoperator: 51
operand: 50
42Literal
43ExprTuple47, 48
44Literal
45ExprTuple63, 49
46ExprTuple50
47Operationoperator: 51
operand: 57
48Operationoperator: 52
operand: 57
49Operationoperator: 54
operands: 55
50IndexedVarvariable: 61
index: 60
51Literal
52Literal
53ExprTuple57
54Literal
55ExprTuple58, 59
56ExprTuple60
57IndexedVarvariable: 61
index: 63
58Literal
59Variable
60Variable
61Variable
62ExprTuple63
63Variable