logo

Expression of type ProbOfAll

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, U, Variable, VertExprArray, m, n, s, t
from proveit.numbers import Add, Exp, Interval, LessEq, ModAbs, Neg, frac, one, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import ProbOfAll
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 = ProbOfAll(instance_param_or_params = [m], instance_element = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_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), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)])), domain = Interval(zero, subtract(two_pow_t, one)), condition = LessEq(ModAbs(subtract(frac(m, two_pow_t), phase), one), Exp(two, Neg(n)))).with_wrapping()
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())
\begin{array}{l}\textrm{Prob}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}~|~\left|\frac{m}{2^{t}} - \varphi\right|_{\textup{mod}\thinspace 1} \leq 2^{-n}}~\\
\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \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 m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)\end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 116
body: 5
4ExprTuple116
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13, 14, 15
10Literal
11ExprTuple16, 17
12ExprTuple18, 19
13ExprTuple20, 21
14ExprTuple22, 23
15ExprTuple24, 25
16Operationoperator: 26
operands: 27
17Operationoperator: 28
operands: 29
18ExprRangelambda_map: 30
start_index: 117
end_index: 122
19ExprRangelambda_map: 31
start_index: 117
end_index: 118
20ExprRangelambda_map: 32
start_index: 117
end_index: 122
21ExprRangelambda_map: 32
start_index: 99
end_index: 100
22ExprRangelambda_map: 33
start_index: 117
end_index: 122
23ExprRangelambda_map: 34
start_index: 117
end_index: 118
24ExprRangelambda_map: 35
start_index: 117
end_index: 122
25ExprRangelambda_map: 36
start_index: 117
end_index: 118
26Literal
27ExprTuple116, 37
28Literal
29ExprTuple38, 39
30Lambdaparameter: 98
body: 40
31Lambdaparameter: 98
body: 41
32Lambdaparameter: 98
body: 42
33Lambdaparameter: 98
body: 43
34Lambdaparameter: 98
body: 44
35Lambdaparameter: 98
body: 45
36Lambdaparameter: 98
body: 47
37Operationoperator: 88
operands: 48
38Operationoperator: 49
operands: 50
39Operationoperator: 119
operands: 51
40Operationoperator: 80
operands: 52
41Operationoperator: 59
operands: 53
42Operationoperator: 59
operands: 54
43Operationoperator: 55
operands: 56
44Operationoperator: 81
operands: 57
45Operationoperator: 59
operands: 58
46ExprTuple98
47Operationoperator: 59
operands: 60
48ExprTuple61, 62
49Literal
50ExprTuple63, 117
51ExprTuple121, 64
52NamedExprsstate: 65
53NamedExprselement: 66
targets: 74
54NamedExprselement: 67
targets: 68
55Literal
56NamedExprsbasis: 69
57NamedExprsoperation: 70
58NamedExprselement: 71
targets: 72
59Literal
60NamedExprselement: 73
targets: 74
61Literal
62Operationoperator: 111
operands: 75
63Operationoperator: 111
operands: 76
64Operationoperator: 104
operand: 93
65Operationoperator: 78
operand: 94
66Operationoperator: 80
operands: 87
67Operationoperator: 81
operands: 82
68Operationoperator: 88
operands: 83
69Literal
70Literal
71Operationoperator: 86
operands: 84
72Operationoperator: 88
operands: 85
73Operationoperator: 86
operands: 87
74Operationoperator: 88
operands: 89
75ExprTuple113, 90
76ExprTuple91, 92
77ExprTuple93
78Literal
79ExprTuple94
80Literal
81Literal
82NamedExprsoperation: 95
part: 98
83ExprTuple117, 100
84NamedExprsstate: 96
part: 98
85ExprTuple117, 122
86Literal
87NamedExprsstate: 97
part: 98
88Literal
89ExprTuple99, 100
90Operationoperator: 104
operand: 117
91Operationoperator: 102
operands: 103
92Operationoperator: 104
operand: 114
93Variable
94Literal
95Operationoperator: 106
operands: 107
96Operationoperator: 108
operands: 109
97Variable
98Variable
99Operationoperator: 111
operands: 110
100Operationoperator: 111
operands: 112
101ExprTuple117
102Literal
103ExprTuple116, 113
104Literal
105ExprTuple114
106Literal
107ExprTuple115, 122
108Literal
109ExprTuple116, 122
110ExprTuple122, 117
111Literal
112ExprTuple122, 118
113Operationoperator: 119
operands: 120
114Variable
115Variable
116Variable
117Literal
118Variable
119Literal
120ExprTuple121, 122
121Literal
122Variable