logo

Expression of type Less

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 Add, Exp, Interval, Mod, Mult, Round, four, frac, greater, one, pi, two
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import QPE, _U, _ket_u, _phase, _s, _s_wire, _t, _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 = greater(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, Measure(basis = Z), one, _t), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(Mod(Round(Mult(_two_pow_t, _phase)), _two_pow_t), _t), 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)]))), frac(four, Exp(pi, two)))
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 round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \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 round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) > \frac{4}{\pi^{2}}
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)normalreversed('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operand: 11
5Literal
6ExprTuple9, 10
7Literal
8ExprTuple11
9Literal
10Operationoperator: 102
operands: 12
11Operationoperator: 13
operands: 14
12ExprTuple15, 104
13Literal
14ExprTuple16, 17, 18, 19
15Literal
16ExprTuple20, 21
17ExprTuple22, 23
18ExprTuple24, 25
19ExprTuple26, 27
20ExprRangelambda_map: 28
start_index: 90
end_index: 105
21ExprRangelambda_map: 29
start_index: 90
end_index: 91
22ExprRangelambda_map: 30
start_index: 90
end_index: 105
23ExprRangelambda_map: 30
start_index: 79
end_index: 80
24ExprRangelambda_map: 31
start_index: 90
end_index: 105
25ExprRangelambda_map: 32
start_index: 90
end_index: 91
26ExprRangelambda_map: 33
start_index: 90
end_index: 105
27ExprRangelambda_map: 34
start_index: 90
end_index: 91
28Lambdaparameter: 78
body: 35
29Lambdaparameter: 78
body: 36
30Lambdaparameter: 78
body: 37
31Lambdaparameter: 78
body: 38
32Lambdaparameter: 78
body: 39
33Lambdaparameter: 78
body: 40
34Lambdaparameter: 78
body: 42
35Operationoperator: 64
operands: 43
36Operationoperator: 50
operands: 44
37Operationoperator: 50
operands: 45
38Operationoperator: 46
operands: 47
39Operationoperator: 65
operands: 48
40Operationoperator: 50
operands: 49
41ExprTuple78
42Operationoperator: 50
operands: 51
43NamedExprsstate: 52
44NamedExprselement: 53
targets: 61
45NamedExprselement: 54
targets: 55
46Literal
47NamedExprsbasis: 56
48NamedExprsoperation: 57
49NamedExprselement: 58
targets: 59
50Literal
51NamedExprselement: 60
targets: 61
52Operationoperator: 62
operand: 74
53Operationoperator: 64
operands: 71
54Operationoperator: 65
operands: 66
55Operationoperator: 72
operands: 67
56Literal
57Literal
58Operationoperator: 70
operands: 68
59Operationoperator: 72
operands: 69
60Operationoperator: 70
operands: 71
61Operationoperator: 72
operands: 73
62Literal
63ExprTuple74
64Literal
65Literal
66NamedExprsoperation: 75
part: 78
67ExprTuple90, 80
68NamedExprsstate: 76
part: 78
69ExprTuple90, 105
70Literal
71NamedExprsstate: 77
part: 78
72Literal
73ExprTuple79, 80
74Literal
75Operationoperator: 81
operands: 82
76Operationoperator: 83
operands: 84
77Literal
78Variable
79Operationoperator: 86
operands: 85
80Operationoperator: 86
operands: 87
81Literal
82ExprTuple88, 105
83Literal
84ExprTuple89, 105
85ExprTuple105, 90
86Literal
87ExprTuple105, 91
88Literal
89Operationoperator: 92
operands: 93
90Literal
91Literal
92Literal
93ExprTuple94, 100
94Operationoperator: 95
operand: 97
95Literal
96ExprTuple97
97Operationoperator: 98
operands: 99
98Literal
99ExprTuple100, 101
100Operationoperator: 102
operands: 103
101Literal
102Literal
103ExprTuple104, 105
104Literal
105Literal