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 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 = Conditional(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(), InSet(n, 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())
\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} \textrm{ if } n \in \mathbb{N}^+\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: 3
operand: 6
2Operationoperator: 38
operands: 5
3Literal
4ExprTuple6
5ExprTuple53, 7
6Lambdaparameters: 8
body: 9
7Literal
8ExprTuple10
9Conditionalvalue: 11
condition: 12
10ExprRangelambda_map: 13
start_index: 52
end_index: 53
11Operationoperator: 14
operands: 15
12Operationoperator: 38
operands: 16
13Lambdaparameter: 54
body: 44
14Literal
15ExprTuple17, 18
16ExprTuple19, 20
17Operationoperator: 21
operand: 28
18Operationoperator: 23
operand: 30
19Operationoperator: 24
operands: 25
20Operationoperator: 26
operand: 30
21Literal
22ExprTuple28
23Literal
24Literal
25ExprTuple29
26Literal
27ExprTuple30
28Lambdaparameter: 57
body: 31
29ExprRangelambda_map: 32
start_index: 52
end_index: 53
30Variable
31Conditionalvalue: 33
condition: 34
32Lambdaparameter: 54
body: 35
33Operationoperator: 36
operands: 37
34Operationoperator: 38
operands: 39
35Operationoperator: 45
operand: 44
36Literal
37ExprTuple41, 42
38Literal
39ExprTuple57, 43
40ExprTuple44
41Operationoperator: 45
operand: 51
42Operationoperator: 46
operand: 51
43Operationoperator: 48
operands: 49
44IndexedVarvariable: 55
index: 54
45Literal
46Literal
47ExprTuple51
48Literal
49ExprTuple52, 53
50ExprTuple54
51IndexedVarvariable: 55
index: 57
52Literal
53Variable
54Variable
55Variable
56ExprTuple57
57Variable