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 i, n
from proveit.core_expr_types import x_1_to_n, x_i
from proveit.linear_algebra import Hspace, Identity, OrthoNormBases, 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(VecSum(index_or_indices = [i], summand = Qmult(Ket(x_i), Bra(x_i)), domain = Interval(one, n)), Identity(Hspace)), 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(\left(\sum_{i=1}^{n} \left(\lvert x_{i} \rangle \thinspace \langle x_{i} \rvert\right)\right) = I_{\mathcal{H}}\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: 57
body: 4
3ExprTuple57
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 42
operands: 9
7Literal
8ExprTuple10
9ExprTuple57, 11
10Lambdaparameters: 12
body: 13
11Literal
12ExprTuple14
13Conditionalvalue: 15
condition: 16
14ExprRangelambda_map: 17
start_index: 56
end_index: 57
15Operationoperator: 18
operands: 19
16Operationoperator: 42
operands: 20
17Lambdaparameter: 58
body: 48
18Literal
19ExprTuple21, 22
20ExprTuple23, 24
21Operationoperator: 25
operand: 32
22Operationoperator: 27
operand: 34
23Operationoperator: 28
operands: 29
24Operationoperator: 30
operand: 34
25Literal
26ExprTuple32
27Literal
28Literal
29ExprTuple33
30Literal
31ExprTuple34
32Lambdaparameter: 61
body: 35
33ExprRangelambda_map: 36
start_index: 56
end_index: 57
34Variable
35Conditionalvalue: 37
condition: 38
36Lambdaparameter: 58
body: 39
37Operationoperator: 40
operands: 41
38Operationoperator: 42
operands: 43
39Operationoperator: 49
operand: 48
40Literal
41ExprTuple45, 46
42Literal
43ExprTuple61, 47
44ExprTuple48
45Operationoperator: 49
operand: 55
46Operationoperator: 50
operand: 55
47Operationoperator: 52
operands: 53
48IndexedVarvariable: 59
index: 58
49Literal
50Literal
51ExprTuple55
52Literal
53ExprTuple56, 57
54ExprTuple58
55IndexedVarvariable: 59
index: 61
56Literal
57Variable
58Variable
59Variable
60ExprTuple61
61Variable