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 import Qmult
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import _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)
sub_expr3 = InverseFourierTransform(_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 = sub_expr3, part = sub_expr1), targets = sub_expr2), one, _t)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = Qmult(sub_expr3, _psi__t_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{{\mathrm {FT}}^{\dag}_{t} \thinspace \lvert \psi_{t} \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, 40
3Operationoperator: 4
operand: 6
4Literal
5ExprTuple6
6Operationoperator: 7
operands: 8
7Literal
8ExprTuple9, 10, 11
9ExprTuple12
10ExprTuple13
11ExprTuple14
12ExprRangelambda_map: 15
start_index: 40
end_index: 48
13ExprRangelambda_map: 16
start_index: 40
end_index: 48
14ExprRangelambda_map: 17
start_index: 40
end_index: 48
15Lambdaparameter: 39
body: 18
16Lambdaparameter: 39
body: 19
17Lambdaparameter: 39
body: 21
18Operationoperator: 24
operands: 22
19Operationoperator: 24
operands: 23
20ExprTuple39
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: 44
part: 39
32Literal
33NamedExprsoperation: 43
part: 39
34Literal
35NamedExprsstate: 38
part: 39
36Literal
37ExprTuple40, 48
38Operationoperator: 41
operands: 42
39Variable
40Literal
41Literal
42ExprTuple43, 44
43Operationoperator: 45
operand: 48
44Operationoperator: 46
operand: 48
45Literal
46Literal
47ExprTuple48
48Literal