# 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.
# import Expression classes needed to build the expression
from proveit import Conditional, Lambda
from proveit.linear_algebra import InnerProd
from proveit.logic import Equals, Forall, InSet
from proveit.physics.quantum import HilbertSpaces, bra_varphi, ket_varphi, var_ket_psi, varphi
from proveit.physics.quantum.algebra import Hspace

In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [Hspace], instance_expr = Forall(instance_param_or_params = [varphi], instance_expr = Equals(bra_varphi, Lambda(var_ket_psi, Conditional(InnerProd(ket_varphi, var_ket_psi), InSet(var_ket_psi, Hspace)))), condition = InSet(ket_varphi, Hspace)), domain = HilbertSpaces)

Out[2]:
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())

\forall_{\mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces}}~\left[\forall_{\varphi~|~\lvert \varphi \rangle \in \mathcal{H}}~\left(\langle \varphi \rvert = \left[\lvert \psi \rangle \mapsto \left\{\left \langle \lvert \varphi \rangle, \lvert \psi \rangle\right \rangle \textrm{ if } \lvert \psi \rangle \in \mathcal{H}\right..\right]\right)\right]

In [5]:
stored_expr.style_options()

Out[5]:
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('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()

Out[6]:
core typesub-expressionsexpression
0Operationoperator: 7
operand: 2
1ExprTuple2
2Lambdaparameter: 32
body: 4
3ExprTuple32
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 11
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11
9Literal
10ExprTuple32, 12
11Lambdaparameter: 35
body: 13
12Literal
13Conditionalvalue: 14
condition: 15
14Operationoperator: 16
operands: 17
15Operationoperator: 28
operands: 18
16Literal
17ExprTuple19, 20
18ExprTuple30, 32
19Operationoperator: 21
operand: 35
20Lambdaparameter: 31
body: 23
21Literal
22ExprTuple31
23Conditionalvalue: 24
condition: 25
24Operationoperator: 26
operands: 27
25Operationoperator: 28
operands: 29
26Literal
27ExprTuple30, 31
28Literal
29ExprTuple31, 32
30Operationoperator: 33
operand: 35
31Variable
32Variable
33Literal
34ExprTuple35
35Variable