logo

Expression of type MultiQubitElem

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, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase
from proveit.physics.quantum.circuits import MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
expr = MultiQubitElem(element = 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))), part = one), targets = Interval(Add(zero, one), one))
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)~\mbox{part}~1~\mbox{on}~\{0 + 1~\ldotp \ldotp~1\}} 
} \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
2NamedExprselement: 3
targets: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6NamedExprsstate: 9
part: 51
7Literal
8ExprTuple10, 51
9Operationoperator: 23
operands: 11
10Operationoperator: 48
operands: 12
11ExprTuple13, 14
12ExprTuple26, 51
13Operationoperator: 29
operands: 15
14Operationoperator: 16
operands: 17
15ExprTuple51, 18
16Literal
17ExprTuple19, 20
18Operationoperator: 42
operands: 21
19Operationoperator: 32
operand: 26
20Operationoperator: 23
operands: 24
21ExprTuple44, 25
22ExprTuple26
23Literal
24ExprTuple27, 28
25Operationoperator: 29
operands: 30
26Literal
27Operationoperator: 42
operands: 31
28Operationoperator: 32
operand: 51
29Literal
30ExprTuple51, 44
31ExprTuple34, 35
32Literal
33ExprTuple51
34Literal
35Operationoperator: 36
operands: 37
36Literal
37ExprTuple44, 38, 39, 40, 41
38Literal
39Literal
40Operationoperator: 42
operands: 43
41Literal
42Literal
43ExprTuple44, 45
44Literal
45Operationoperator: 52
operand: 47
46ExprTuple47
47Operationoperator: 48
operands: 49
48Literal
49ExprTuple50, 51
50Operationoperator: 52
operand: 54
51Literal
52Literal
53ExprTuple54
54Variable