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, 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(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()
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(\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}
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: 50
end_index: 51
7Operationoperator: 10
operands: 11
8Operationoperator: 36
operands: 12
9Lambdaparameter: 52
body: 42
10Literal
11ExprTuple13, 14
12ExprTuple15, 16
13Operationoperator: 17
operands: 18
14Operationoperator: 19
operand: 26
15Operationoperator: 21
operands: 22
16Operationoperator: 23
operand: 28
17Literal
18ExprTuple28, 25
19Literal
20ExprTuple26
21Literal
22ExprTuple27
23Literal
24ExprTuple28
25Variable
26Lambdaparameter: 55
body: 29
27ExprRangelambda_map: 30
start_index: 50
end_index: 51
28Variable
29Conditionalvalue: 31
condition: 32
30Lambdaparameter: 52
body: 33
31Operationoperator: 34
operands: 35
32Operationoperator: 36
operands: 37
33Operationoperator: 43
operand: 42
34Literal
35ExprTuple39, 40
36Literal
37ExprTuple55, 41
38ExprTuple42
39Operationoperator: 43
operand: 49
40Operationoperator: 44
operand: 49
41Operationoperator: 46
operands: 47
42IndexedVarvariable: 53
index: 52
43Literal
44Literal
45ExprTuple49
46Literal
47ExprTuple50, 51
48ExprTuple52
49IndexedVarvariable: 53
index: 55
50Literal
51Variable
52Variable
53Variable
54ExprTuple55
55Variable