logo

Expression of type Equals

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.logic import Equals
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}")
sub_expr2 = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))
expr = Equals(MultiQubitElem(element = Output(state = sub_expr2, part = one), targets = Interval(Add(Add(sub_expr1, Neg(one), t), one), Add(sub_expr1, t))), Output(state = sub_expr2))
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} = \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)} 
} \end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 5
operands: 6
4Operationoperator: 10
operands: 7
5Literal
6NamedExprselement: 8
targets: 9
7NamedExprsstate: 14
8Operationoperator: 10
operands: 11
9Operationoperator: 12
operands: 13
10Literal
11NamedExprsstate: 14
part: 48
12Literal
13ExprTuple15, 16
14Operationoperator: 35
operands: 17
15Operationoperator: 26
operands: 18
16Operationoperator: 26
operands: 19
17ExprTuple20, 21
18ExprTuple22, 48
19ExprTuple61, 32
20Operationoperator: 41
operands: 23
21Operationoperator: 24
operands: 25
22Operationoperator: 26
operands: 27
23ExprTuple48, 28
24Literal
25ExprTuple29, 30
26Literal
27ExprTuple61, 31, 32
28Operationoperator: 55
operands: 33
29Operationoperator: 44
operand: 38
30Operationoperator: 35
operands: 36
31Operationoperator: 59
operand: 48
32Variable
33ExprTuple57, 37
34ExprTuple38
35Literal
36ExprTuple39, 40
37Operationoperator: 41
operands: 42
38Literal
39Operationoperator: 55
operands: 43
40Operationoperator: 44
operand: 48
41Literal
42ExprTuple48, 57
43ExprTuple46, 47
44Literal
45ExprTuple48
46Literal
47Operationoperator: 49
operands: 50
48Literal
49Literal
50ExprTuple57, 51, 52, 53, 54
51Literal
52Literal
53Operationoperator: 55
operands: 56
54Literal
55Literal
56ExprTuple57, 58
57Literal
58Operationoperator: 59
operand: 61
59Literal
60ExprTuple61
61Variable