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 Variable, t
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Interval, 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 MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = MultiQubitElem(element = Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1))), part = one), targets = Interval(Add(Add(sub_expr1, Neg(one), t), one), Add(sub_expr1, t)))
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^{-{_{-}a}} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)~\mbox{part}~1~\mbox{on}~\{\left({_{-}a} - 1 + t\right) + 1~\ldotp \ldotp~{_{-}a} + t\}} 
} \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: 43
7Literal
8ExprTuple10, 11
9Operationoperator: 30
operands: 12
10Operationoperator: 21
operands: 13
11Operationoperator: 21
operands: 14
12ExprTuple15, 16
13ExprTuple17, 43
14ExprTuple56, 27
15Operationoperator: 36
operands: 18
16Operationoperator: 19
operands: 20
17Operationoperator: 21
operands: 22
18ExprTuple43, 23
19Literal
20ExprTuple24, 25
21Literal
22ExprTuple56, 26, 27
23Operationoperator: 50
operands: 28
24Operationoperator: 39
operand: 33
25Operationoperator: 30
operands: 31
26Operationoperator: 54
operand: 43
27Variable
28ExprTuple52, 32
29ExprTuple33
30Literal
31ExprTuple34, 35
32Operationoperator: 36
operands: 37
33Literal
34Operationoperator: 50
operands: 38
35Operationoperator: 39
operand: 43
36Literal
37ExprTuple43, 52
38ExprTuple41, 42
39Literal
40ExprTuple43
41Literal
42Operationoperator: 44
operands: 45
43Literal
44Literal
45ExprTuple52, 46, 47, 48, 49
46Literal
47Literal
48Operationoperator: 50
operands: 51
49Literal
50Literal
51ExprTuple52, 53
52Literal
53Operationoperator: 54
operand: 56
54Literal
55ExprTuple56
56Variable