logo

Expression of type Conditional

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 Conditional, ExprRange, U, Variable, VertExprArray, eps, m, n, s, t
from proveit.logic import And, InSet
from proveit.numbers import Add, Ceil, Exp, Interval, LessEq, Log, ModAbs, Mult, NaturalPos, Neg, frac, greater_eq, 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 = Conditional(greater_eq(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(), subtract(one, eps)), And(InSet(t, NaturalPos), greater_eq(t, Add(n, Ceil(Log(two, Add(two, frac(one, Mult(two, eps)))))))))
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())
\left\{\left[\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}\right] \geq \left(1 - \epsilon\right) \textrm{ if } t \in \mathbb{N}^+ ,  t \geq \left(n + \left\lceil \textrm{log}_2\left(2 + \frac{1}{2 \cdot \epsilon}\right)\right\rceil\right)\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 48
operands: 3
2Operationoperator: 27
operands: 4
3ExprTuple5, 6
4ExprTuple7, 8
5Operationoperator: 140
operands: 9
6Operationoperator: 10
operand: 15
7Operationoperator: 46
operands: 12
8Operationoperator: 48
operands: 13
9ExprTuple147, 14
10Literal
11ExprTuple15
12ExprTuple152, 16
13ExprTuple17, 152
14Operationoperator: 131
operand: 144
15Lambdaparameter: 146
body: 20
16Literal
17Operationoperator: 140
operands: 21
18ExprTuple144
19ExprTuple146
20Conditionalvalue: 22
condition: 23
21ExprTuple119, 24
22Operationoperator: 25
operands: 26
23Operationoperator: 27
operands: 28
24Operationoperator: 29
operand: 37
25Literal
26ExprTuple31, 32, 33, 34
27Literal
28ExprTuple35, 36
29Literal
30ExprTuple37
31ExprTuple38, 39
32ExprTuple40, 41
33ExprTuple42, 43
34ExprTuple44, 45
35Operationoperator: 46
operands: 47
36Operationoperator: 48
operands: 49
37Operationoperator: 50
operands: 51
38ExprRangelambda_map: 52
start_index: 147
end_index: 152
39ExprRangelambda_map: 53
start_index: 147
end_index: 148
40ExprRangelambda_map: 54
start_index: 147
end_index: 152
41ExprRangelambda_map: 54
start_index: 126
end_index: 127
42ExprRangelambda_map: 55
start_index: 147
end_index: 152
43ExprRangelambda_map: 56
start_index: 147
end_index: 148
44ExprRangelambda_map: 57
start_index: 147
end_index: 152
45ExprRangelambda_map: 58
start_index: 147
end_index: 148
46Literal
47ExprTuple146, 59
48Literal
49ExprTuple60, 61
50Literal
51ExprTuple151, 62
52Lambdaparameter: 125
body: 63
53Lambdaparameter: 125
body: 64
54Lambdaparameter: 125
body: 65
55Lambdaparameter: 125
body: 66
56Lambdaparameter: 125
body: 67
57Lambdaparameter: 125
body: 68
58Lambdaparameter: 125
body: 70
59Operationoperator: 114
operands: 71
60Operationoperator: 72
operands: 73
61Operationoperator: 149
operands: 74
62Operationoperator: 140
operands: 75
63Operationoperator: 106
operands: 76
64Operationoperator: 83
operands: 77
65Operationoperator: 83
operands: 78
66Operationoperator: 79
operands: 80
67Operationoperator: 107
operands: 81
68Operationoperator: 83
operands: 82
69ExprTuple125
70Operationoperator: 83
operands: 84
71ExprTuple85, 86
72Literal
73ExprTuple87, 147
74ExprTuple151, 88
75ExprTuple151, 89
76NamedExprsstate: 90
77NamedExprselement: 91
targets: 99
78NamedExprselement: 92
targets: 93
79Literal
80NamedExprsbasis: 94
81NamedExprsoperation: 95
82NamedExprselement: 96
targets: 97
83Literal
84NamedExprselement: 98
targets: 99
85Literal
86Operationoperator: 140
operands: 100
87Operationoperator: 140
operands: 101
88Operationoperator: 131
operand: 119
89Operationoperator: 129
operands: 103
90Operationoperator: 104
operand: 121
91Operationoperator: 106
operands: 113
92Operationoperator: 107
operands: 108
93Operationoperator: 114
operands: 109
94Literal
95Literal
96Operationoperator: 112
operands: 110
97Operationoperator: 114
operands: 111
98Operationoperator: 112
operands: 113
99Operationoperator: 114
operands: 115
100ExprTuple142, 116
101ExprTuple117, 118
102ExprTuple119
103ExprTuple147, 120
104Literal
105ExprTuple121
106Literal
107Literal
108NamedExprsoperation: 122
part: 125
109ExprTuple147, 127
110NamedExprsstate: 123
part: 125
111ExprTuple147, 152
112Literal
113NamedExprsstate: 124
part: 125
114Literal
115ExprTuple126, 127
116Operationoperator: 131
operand: 147
117Operationoperator: 129
operands: 130
118Operationoperator: 131
operand: 143
119Variable
120Operationoperator: 133
operands: 134
121Literal
122Operationoperator: 135
operands: 136
123Operationoperator: 137
operands: 138
124Variable
125Variable
126Operationoperator: 140
operands: 139
127Operationoperator: 140
operands: 141
128ExprTuple147
129Literal
130ExprTuple146, 142
131Literal
132ExprTuple143
133Literal
134ExprTuple151, 144
135Literal
136ExprTuple145, 152
137Literal
138ExprTuple146, 152
139ExprTuple152, 147
140Literal
141ExprTuple152, 148
142Operationoperator: 149
operands: 150
143Variable
144Variable
145Variable
146Variable
147Literal
148Variable
149Literal
150ExprTuple151, 152
151Literal
152Variable