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 ExprRange, Variable, VertExprArray
from proveit.logic import Equals
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 = Equals(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)]))), one)
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) = 1
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, 42
3Operationoperator: 4
operand: 6
4Literal
5ExprTuple6
6Operationoperator: 7
operands: 8
7Literal
8ExprTuple9, 10, 11
9ExprTuple12
10ExprTuple13
11ExprTuple14
12ExprRangelambda_map: 15
start_index: 42
end_index: 46
13ExprRangelambda_map: 16
start_index: 42
end_index: 46
14ExprRangelambda_map: 17
start_index: 42
end_index: 46
15Lambdaparameter: 41
body: 18
16Lambdaparameter: 41
body: 19
17Lambdaparameter: 41
body: 21
18Operationoperator: 24
operands: 22
19Operationoperator: 24
operands: 23
20ExprTuple41
21Operationoperator: 24
operands: 25
22NamedExprselement: 26
targets: 29
23NamedExprselement: 27
targets: 29
24Literal
25NamedExprselement: 28
targets: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operands: 33
28Operationoperator: 34
operands: 35
29Operationoperator: 36
operands: 37
30Literal
31NamedExprsstate: 38
part: 41
32Literal
33NamedExprsoperation: 39
part: 41
34Literal
35NamedExprsstate: 40
part: 41
36Literal
37ExprTuple42, 46
38Operationoperator: 43
operand: 46
39Operationoperator: 44
operand: 46
40Literal
41Variable
42Literal
43Literal
44Literal
45ExprTuple46
46Literal