logo

Expression of type Conditional

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 Conditional, 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, InClass, 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 = Conditional(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(X))).with_wrapping(), domain = NaturalPos), condition = SubsetEq(X, Hspace)), InClass(Hspace, 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())
\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(X\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] \textrm{ if } \mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces}\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 19
operand: 6
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple45, 7
6Lambdaparameter: 48
body: 8
7Literal
8Conditionalvalue: 9
condition: 10
9Operationoperator: 19
operand: 14
10Operationoperator: 12
operands: 13
11ExprTuple14
12Literal
13ExprTuple48, 45
14Lambdaparameter: 71
body: 16
15ExprTuple71
16Conditionalvalue: 17
condition: 18
17Operationoperator: 19
operand: 22
18Operationoperator: 56
operands: 21
19Literal
20ExprTuple22
21ExprTuple71, 23
22Lambdaparameters: 24
body: 25
23Literal
24ExprTuple26
25Conditionalvalue: 27
condition: 28
26ExprRangelambda_map: 29
start_index: 70
end_index: 71
27Operationoperator: 30
operands: 31
28Operationoperator: 56
operands: 32
29Lambdaparameter: 72
body: 62
30Literal
31ExprTuple33, 34
32ExprTuple35, 36
33Operationoperator: 37
operands: 38
34Operationoperator: 39
operand: 46
35Operationoperator: 41
operands: 42
36Operationoperator: 43
operand: 48
37Literal
38ExprTuple45, 48
39Literal
40ExprTuple46
41Literal
42ExprTuple47
43Literal
44ExprTuple48
45Variable
46Lambdaparameter: 75
body: 49
47ExprRangelambda_map: 50
start_index: 70
end_index: 71
48Variable
49Conditionalvalue: 51
condition: 52
50Lambdaparameter: 72
body: 53
51Operationoperator: 54
operands: 55
52Operationoperator: 56
operands: 57
53Operationoperator: 63
operand: 62
54Literal
55ExprTuple59, 60
56Literal
57ExprTuple75, 61
58ExprTuple62
59Operationoperator: 63
operand: 69
60Operationoperator: 64
operand: 69
61Operationoperator: 66
operands: 67
62IndexedVarvariable: 73
index: 72
63Literal
64Literal
65ExprTuple69
66Literal
67ExprTuple70, 71
68ExprTuple72
69IndexedVarvariable: 73
index: 75
70Literal
71Variable
72Variable
73Variable
74ExprTuple75
75Variable