logo

Expression of type Norm

from the theory of proveit.physics.quantum.QPE

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 Variable
from proveit.linear_algebra import Norm, ScalarMult, VecAdd
from proveit.numbers import Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
expr = Norm(ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(Variable("_a", latex_format = r"{_{-}a}"))), _phase)), ket1))))
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 \|\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-{_{-}a}} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right \|
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Operationoperator: 15
operands: 4
4ExprTuple5, 6
5Operationoperator: 21
operands: 7
6Operationoperator: 8
operands: 9
7ExprTuple28, 10
8Literal
9ExprTuple11, 12
10Operationoperator: 35
operands: 13
11Operationoperator: 24
operand: 18
12Operationoperator: 15
operands: 16
13ExprTuple37, 17
14ExprTuple18
15Literal
16ExprTuple19, 20
17Operationoperator: 21
operands: 22
18Literal
19Operationoperator: 35
operands: 23
20Operationoperator: 24
operand: 28
21Literal
22ExprTuple28, 37
23ExprTuple26, 27
24Literal
25ExprTuple28
26Literal
27Operationoperator: 29
operands: 30
28Literal
29Literal
30ExprTuple37, 31, 32, 33, 34
31Literal
32Literal
33Operationoperator: 35
operands: 36
34Literal
35Literal
36ExprTuple37, 38
37Literal
38Operationoperator: 39
operand: 41
39Literal
40ExprTuple41
41Variable