logo

Expression of type Output

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 t
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase
from proveit.physics.quantum.circuits import Output
In [2]:
# build up the expression from sub-expressions
expr = Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(Add(Neg(t), one))), _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())
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-\left(-t + 1\right)} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} 
} \end{array}
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2NamedExprsstate: 3
3Operationoperator: 15
operands: 4
4ExprTuple5, 6
5Operationoperator: 21
operands: 7
6Operationoperator: 8
operands: 9
7ExprTuple43, 10
8Literal
9ExprTuple11, 12
10Operationoperator: 34
operands: 13
11Operationoperator: 24
operand: 18
12Operationoperator: 15
operands: 16
13ExprTuple36, 17
14ExprTuple18
15Literal
16ExprTuple19, 20
17Operationoperator: 21
operands: 22
18Literal
19Operationoperator: 34
operands: 23
20Operationoperator: 24
operand: 43
21Literal
22ExprTuple43, 36
23ExprTuple26, 27
24Literal
25ExprTuple43
26Literal
27Operationoperator: 28
operands: 29
28Literal
29ExprTuple36, 30, 31, 32, 33
30Literal
31Literal
32Operationoperator: 34
operands: 35
33Literal
34Literal
35ExprTuple36, 37
36Literal
37Operationoperator: 44
operand: 39
38ExprTuple39
39Operationoperator: 40
operands: 41
40Literal
41ExprTuple42, 43
42Operationoperator: 44
operand: 46
43Literal
44Literal
45ExprTuple46
46Variable