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_i
from proveit.linear_algebra import Hspace, Identity, OrthoNormBases, VecSum
from proveit.logic import Equals, 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 = Conditional(Equals(VecSum(index_or_indices = [i], summand = Qmult(Ket(x_i), Bra(x_i)), domain = Interval(one, n)), Identity(Hspace)), InSet(x_1_to_n_kets, OrthoNormBases(Hspace)))
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\{\left(\sum_{i=1}^{n} \left(\lvert x_{i} \rangle \thinspace \langle x_{i} \rvert\right)\right) = I_{\mathcal{H}} \textrm{ if } \left\{\lvert x_{1} \rangle, \lvert x_{2} \rangle, \ldots, \lvert x_{n} \rangle\right\} \in \textrm{O.N.Bases}\left(\mathcal{H}\right)\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
operands: 4
2Operationoperator: 27
operands: 5
3Literal
4ExprTuple6, 7
5ExprTuple8, 9
6Operationoperator: 10
operand: 17
7Operationoperator: 12
operand: 19
8Operationoperator: 13
operands: 14
9Operationoperator: 15
operand: 19
10Literal
11ExprTuple17
12Literal
13Literal
14ExprTuple18
15Literal
16ExprTuple19
17Lambdaparameter: 46
body: 20
18ExprRangelambda_map: 21
start_index: 41
end_index: 42
19Variable
20Conditionalvalue: 22
condition: 23
21Lambdaparameter: 43
body: 24
22Operationoperator: 25
operands: 26
23Operationoperator: 27
operands: 28
24Operationoperator: 34
operand: 33
25Literal
26ExprTuple30, 31
27Literal
28ExprTuple46, 32
29ExprTuple33
30Operationoperator: 34
operand: 40
31Operationoperator: 35
operand: 40
32Operationoperator: 37
operands: 38
33IndexedVarvariable: 44
index: 43
34Literal
35Literal
36ExprTuple40
37Literal
38ExprTuple41, 42
39ExprTuple43
40IndexedVarvariable: 44
index: 46
41Literal
42Variable
43Variable
44Variable
45ExprTuple46
46Variable