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.numbers import Interval, one
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import _Psi_ket, _psi__t_ket, _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 = Interval(one, _t)
expr = Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _psi__t_ket, part = sub_expr1), targets = sub_expr2), one, _t)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr2), one, _t)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr2), one, _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())
\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert \psi_{t} \rangle} & \gate{{\mathrm {FT}}^{\dag}_{t}} & \qout{\lvert \Psi \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
7ExprTuple10
8ExprTuple11
9ExprRangelambda_map: 12
start_index: 39
end_index: 43
10ExprRangelambda_map: 13
start_index: 39
end_index: 43
11ExprRangelambda_map: 14
start_index: 39
end_index: 43
12Lambdaparameter: 38
body: 15
13Lambdaparameter: 38
body: 16
14Lambdaparameter: 38
body: 18
15Operationoperator: 21
operands: 19
16Operationoperator: 21
operands: 20
17ExprTuple38
18Operationoperator: 21
operands: 22
19NamedExprselement: 23
targets: 26
20NamedExprselement: 24
targets: 26
21Literal
22NamedExprselement: 25
targets: 26
23Operationoperator: 27
operands: 28
24Operationoperator: 29
operands: 30
25Operationoperator: 31
operands: 32
26Operationoperator: 33
operands: 34
27Literal
28NamedExprsstate: 35
part: 38
29Literal
30NamedExprsoperation: 36
part: 38
31Literal
32NamedExprsstate: 37
part: 38
33Literal
34ExprTuple39, 43
35Operationoperator: 40
operand: 43
36Operationoperator: 41
operand: 43
37Literal
38Variable
39Literal
40Literal
41Literal
42ExprTuple43
43Literal