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, t
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _psi_t_ket, _s
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, one)
sub_expr3 = Add(t, _s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE1(_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 = _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, MultiQubitElem(element = Output(state = _psi_t_ket, part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _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}_1\left(U, t\right)} & \multiqout{3}{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \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: 67
end_index: 68
10ExprRangelambda_map: 16
start_index: 67
end_index: 69
11ExprRangelambda_map: 17
start_index: 67
end_index: 68
12ExprRangelambda_map: 17
start_index: 57
end_index: 58
13ExprRangelambda_map: 18
start_index: 67
end_index: 68
14ExprRangelambda_map: 19
start_index: 67
end_index: 69
15Lambdaparameter: 56
body: 20
16Lambdaparameter: 56
body: 21
17Lambdaparameter: 56
body: 22
18Lambdaparameter: 56
body: 23
19Lambdaparameter: 56
body: 25
20Operationoperator: 42
operands: 26
21Operationoperator: 30
operands: 27
22Operationoperator: 30
operands: 28
23Operationoperator: 30
operands: 29
24ExprTuple56
25Operationoperator: 30
operands: 31
26NamedExprsstate: 32
27NamedExprselement: 33
targets: 39
28NamedExprselement: 34
targets: 35
29NamedExprselement: 36
targets: 37
30Literal
31NamedExprselement: 38
targets: 39
32Operationoperator: 40
operand: 52
33Operationoperator: 42
operands: 49
34Operationoperator: 43
operands: 44
35Operationoperator: 50
operands: 45
36Operationoperator: 48
operands: 46
37Operationoperator: 50
operands: 47
38Operationoperator: 48
operands: 49
39Operationoperator: 50
operands: 51
40Literal
41ExprTuple52
42Literal
43Literal
44NamedExprsoperation: 53
part: 56
45ExprTuple67, 58
46NamedExprsstate: 54
part: 56
47ExprTuple67, 68
48Literal
49NamedExprsstate: 55
part: 56
50Literal
51ExprTuple57, 58
52Literal
53Operationoperator: 59
operands: 60
54Operationoperator: 61
operand: 68
55Literal
56Variable
57Operationoperator: 64
operands: 63
58Operationoperator: 64
operands: 65
59Literal
60ExprTuple66, 68
61Literal
62ExprTuple68
63ExprTuple68, 67
64Literal
65ExprTuple68, 69
66Literal
67Literal
68Variable
69Literal