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, 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_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()
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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('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: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameters: 4
body: 5
4ExprTuple6
5Conditionalvalue: 7
condition: 8
6ExprRangelambda_map: 9
start_index: 48
end_index: 49
7Operationoperator: 10
operands: 11
8Operationoperator: 34
operands: 12
9Lambdaparameter: 50
body: 40
10Literal
11ExprTuple13, 14
12ExprTuple15, 16
13Operationoperator: 17
operand: 24
14Operationoperator: 19
operand: 26
15Operationoperator: 20
operands: 21
16Operationoperator: 22
operand: 26
17Literal
18ExprTuple24
19Literal
20Literal
21ExprTuple25
22Literal
23ExprTuple26
24Lambdaparameter: 53
body: 27
25ExprRangelambda_map: 28
start_index: 48
end_index: 49
26Variable
27Conditionalvalue: 29
condition: 30
28Lambdaparameter: 50
body: 31
29Operationoperator: 32
operands: 33
30Operationoperator: 34
operands: 35
31Operationoperator: 41
operand: 40
32Literal
33ExprTuple37, 38
34Literal
35ExprTuple53, 39
36ExprTuple40
37Operationoperator: 41
operand: 47
38Operationoperator: 42
operand: 47
39Operationoperator: 44
operands: 45
40IndexedVarvariable: 51
index: 50
41Literal
42Literal
43ExprTuple47
44Literal
45ExprTuple48, 49
46ExprTuple50
47IndexedVarvariable: 51
index: 53
48Literal
49Variable
50Variable
51Variable
52ExprTuple53
53Variable