logo

Expression of type Prob

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 ExprRange, Variable, VertExprArray
from proveit.linear_algebra import TensorProd
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import I
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import _Psi_ket, _ket_u, _psi__t_ket, _s, _t
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(_t, _s)
sub_expr3 = Add(_t, one)
sub_expr4 = Interval(one, _t)
sub_expr5 = MultiQubitElem(element = Input(state = TensorProd(_psi__t_ket, _ket_u), part = sub_expr1), targets = Interval(one, sub_expr2))
expr = Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr5, one, _t).with_wrapping_at(2,6), ExprRange(sub_expr1, sub_expr5, sub_expr3, sub_expr2).with_wrapping_at(2,6)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr4), one, _t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, _s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr4), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr3, sub_expr2)), one, _s)])))
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())
\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\multiqin{1}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} & \gate{{\mathrm {FT}}^{\dag}_{t}} & \qout{\lvert \Psi \rangle} \\
\ghostqin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Operationoperator: 4
operands: 5
4Literal
5ExprTuple6, 7, 8
6ExprTuple9, 10
7ExprTuple11, 12
8ExprTuple13, 14
9ExprRangelambda_map: 15
start_index: 65
end_index: 69
10ExprRangelambda_map: 15
start_index: 55
end_index: 56
11ExprRangelambda_map: 16
start_index: 65
end_index: 69
12ExprRangelambda_map: 17
start_index: 65
end_index: 66
13ExprRangelambda_map: 18
start_index: 65
end_index: 69
14ExprRangelambda_map: 19
start_index: 65
end_index: 66
15Lambdaparameter: 54
body: 20
16Lambdaparameter: 54
body: 21
17Lambdaparameter: 54
body: 22
18Lambdaparameter: 54
body: 23
19Lambdaparameter: 54
body: 25
20Operationoperator: 30
operands: 26
21Operationoperator: 30
operands: 27
22Operationoperator: 43
operands: 28
23Operationoperator: 30
operands: 29
24ExprTuple54
25Operationoperator: 30
operands: 31
26NamedExprselement: 32
targets: 33
27NamedExprselement: 34
targets: 37
28NamedExprsoperation: 35
29NamedExprselement: 36
targets: 37
30Literal
31NamedExprselement: 38
targets: 39
32Operationoperator: 40
operands: 41
33Operationoperator: 49
operands: 42
34Operationoperator: 43
operands: 44
35Literal
36Operationoperator: 47
operands: 45
37Operationoperator: 49
operands: 46
38Operationoperator: 47
operands: 48
39Operationoperator: 49
operands: 50
40Literal
41NamedExprsstate: 51
part: 54
42ExprTuple65, 56
43Literal
44NamedExprsoperation: 52
part: 54
45NamedExprsstate: 53
part: 54
46ExprTuple65, 69
47Literal
48NamedExprsstate: 64
part: 54
49Literal
50ExprTuple55, 56
51Operationoperator: 57
operands: 58
52Operationoperator: 59
operand: 69
53Literal
54Variable
55Operationoperator: 61
operands: 60
56Operationoperator: 61
operands: 62
57Literal
58ExprTuple63, 64
59Literal
60ExprTuple69, 65
61Literal
62ExprTuple69, 66
63Operationoperator: 67
operand: 69
64Literal
65Literal
66Literal
67Literal
68ExprTuple69
69Literal