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, i, n
from proveit.core_expr_types import x_1_to_n, x_i
from proveit.linear_algebra import HilbertSpaces, Hspace, Identity, OrthoNormBases, VecSum
from proveit.logic import Equals, Forall, InClass, 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 = Conditional(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), 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_{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] \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: 12
operand: 6
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple39, 7
6Lambdaparameter: 62
body: 9
7Literal
8ExprTuple62
9Conditionalvalue: 10
condition: 11
10Operationoperator: 12
operand: 15
11Operationoperator: 47
operands: 14
12Literal
13ExprTuple15
14ExprTuple62, 16
15Lambdaparameters: 17
body: 18
16Literal
17ExprTuple19
18Conditionalvalue: 20
condition: 21
19ExprRangelambda_map: 22
start_index: 61
end_index: 62
20Operationoperator: 23
operands: 24
21Operationoperator: 47
operands: 25
22Lambdaparameter: 63
body: 53
23Literal
24ExprTuple26, 27
25ExprTuple28, 29
26Operationoperator: 30
operand: 37
27Operationoperator: 32
operand: 39
28Operationoperator: 33
operands: 34
29Operationoperator: 35
operand: 39
30Literal
31ExprTuple37
32Literal
33Literal
34ExprTuple38
35Literal
36ExprTuple39
37Lambdaparameter: 66
body: 40
38ExprRangelambda_map: 41
start_index: 61
end_index: 62
39Variable
40Conditionalvalue: 42
condition: 43
41Lambdaparameter: 63
body: 44
42Operationoperator: 45
operands: 46
43Operationoperator: 47
operands: 48
44Operationoperator: 54
operand: 53
45Literal
46ExprTuple50, 51
47Literal
48ExprTuple66, 52
49ExprTuple53
50Operationoperator: 54
operand: 60
51Operationoperator: 55
operand: 60
52Operationoperator: 57
operands: 58
53IndexedVarvariable: 64
index: 63
54Literal
55Literal
56ExprTuple60
57Literal
58ExprTuple61, 62
59ExprTuple63
60IndexedVarvariable: 64
index: 66
61Literal
62Variable
63Variable
64Variable
65ExprTuple66
66Variable