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, U, Variable, VertExprArray, s, t
from proveit.numbers import Add, Interval, Mult, one
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, 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, one)
sub_expr3 = Add(t, s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(Mult(two_pow_t, phase), t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), 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{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{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, 9
6ExprTuple10, 11
7ExprTuple12, 13
8ExprTuple14, 15
9ExprTuple16, 17
10ExprRangelambda_map: 18
start_index: 80
end_index: 89
11ExprRangelambda_map: 19
start_index: 80
end_index: 81
12ExprRangelambda_map: 20
start_index: 80
end_index: 89
13ExprRangelambda_map: 20
start_index: 69
end_index: 70
14ExprRangelambda_map: 21
start_index: 80
end_index: 89
15ExprRangelambda_map: 22
start_index: 80
end_index: 81
16ExprRangelambda_map: 23
start_index: 80
end_index: 89
17ExprRangelambda_map: 24
start_index: 80
end_index: 81
18Lambdaparameter: 68
body: 25
19Lambdaparameter: 68
body: 26
20Lambdaparameter: 68
body: 27
21Lambdaparameter: 68
body: 28
22Lambdaparameter: 68
body: 29
23Lambdaparameter: 68
body: 30
24Lambdaparameter: 68
body: 32
25Operationoperator: 54
operands: 33
26Operationoperator: 40
operands: 34
27Operationoperator: 40
operands: 35
28Operationoperator: 36
operands: 37
29Operationoperator: 55
operands: 38
30Operationoperator: 40
operands: 39
31ExprTuple68
32Operationoperator: 40
operands: 41
33NamedExprsstate: 42
34NamedExprselement: 43
targets: 51
35NamedExprselement: 44
targets: 45
36Literal
37NamedExprsbasis: 46
38NamedExprsoperation: 47
39NamedExprselement: 48
targets: 49
40Literal
41NamedExprselement: 50
targets: 51
42Operationoperator: 52
operand: 64
43Operationoperator: 54
operands: 61
44Operationoperator: 55
operands: 56
45Operationoperator: 62
operands: 57
46Literal
47Literal
48Operationoperator: 60
operands: 58
49Operationoperator: 62
operands: 59
50Operationoperator: 60
operands: 61
51Operationoperator: 62
operands: 63
52Literal
53ExprTuple64
54Literal
55Literal
56NamedExprsoperation: 65
part: 68
57ExprTuple80, 70
58NamedExprsstate: 66
part: 68
59ExprTuple80, 89
60Literal
61NamedExprsstate: 67
part: 68
62Literal
63ExprTuple69, 70
64Literal
65Operationoperator: 71
operands: 72
66Operationoperator: 73
operands: 74
67Variable
68Variable
69Operationoperator: 76
operands: 75
70Operationoperator: 76
operands: 77
71Literal
72ExprTuple78, 89
73Literal
74ExprTuple79, 89
75ExprTuple89, 80
76Literal
77ExprTuple89, 81
78Variable
79Operationoperator: 82
operands: 83
80Literal
81Variable
82Literal
83ExprTuple84, 85
84Operationoperator: 86
operands: 87
85Variable
86Literal
87ExprTuple88, 89
88Literal
89Variable