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, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, IntervalCO, Mod, Mult, Real, Round, e, four, frac, greater, i, one, pi, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, normalized_var_ket_u, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, s_ket_domain, 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 = Conditional(Forall(instance_param_or_params = [phase], instance_expr = greater(Prob(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(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 = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)]))), frac(four, Exp(pi, two))), domain = Real, conditions = [InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), var_ket_u))]).with_wrapping(), And(InSet(var_ket_u, s_ket_domain), normalized_var_ket_u))
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\{\begin{array}{l}\forall_{\varphi \in \mathbb{R}~|~\varphi \in \left[0,1\right), \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\\
\left(\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}}\right)\end{array} \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{s}} ,  \left \|\lvert u \rangle\right \| = 1\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: 3
operand: 6
2Operationoperator: 19
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameter: 151
body: 10
7Operationoperator: 37
operands: 11
8Operationoperator: 39
operands: 12
9ExprTuple151
10Conditionalvalue: 13
condition: 14
11ExprTuple127, 15
12ExprTuple16, 140
13Operationoperator: 17
operands: 18
14Operationoperator: 19
operands: 20
15Operationoperator: 21
operands: 22
16Operationoperator: 23
operand: 127
17Literal
18ExprTuple25, 26
19Literal
20ExprTuple27, 28, 29
21Literal
22ExprTuple30, 31
23Literal
24ExprTuple127
25Operationoperator: 32
operands: 33
26Operationoperator: 34
operand: 44
27Operationoperator: 37
operands: 36
28Operationoperator: 37
operands: 38
29Operationoperator: 39
operands: 40
30Literal
31Operationoperator: 152
operands: 41
32Literal
33ExprTuple42, 43
34Literal
35ExprTuple44
36ExprTuple151, 45
37Literal
38ExprTuple151, 46
39Literal
40ExprTuple47, 48
41ExprTuple154, 141
42Literal
43Operationoperator: 152
operands: 49
44Operationoperator: 50
operands: 51
45Literal
46Operationoperator: 52
operands: 53
47Operationoperator: 54
operands: 55
48Operationoperator: 56
operands: 57
49ExprTuple100, 154
50Literal
51ExprTuple58, 59, 60, 61
52Literal
53ExprTuple62, 140
54Literal
55ExprTuple138, 127
56Literal
57ExprTuple63, 127
58ExprTuple64, 65
59ExprTuple66, 67
60ExprTuple68, 69
61ExprTuple70, 71
62Literal
63Operationoperator: 152
operands: 72
64ExprRangelambda_map: 73
start_index: 140
end_index: 155
65ExprRangelambda_map: 74
start_index: 140
end_index: 141
66ExprRangelambda_map: 75
start_index: 140
end_index: 155
67ExprRangelambda_map: 75
start_index: 129
end_index: 130
68ExprRangelambda_map: 76
start_index: 140
end_index: 155
69ExprRangelambda_map: 77
start_index: 140
end_index: 141
70ExprRangelambda_map: 78
start_index: 140
end_index: 155
71ExprRangelambda_map: 79
start_index: 140
end_index: 141
72ExprTuple80, 81
73Lambdaparameter: 128
body: 82
74Lambdaparameter: 128
body: 83
75Lambdaparameter: 128
body: 84
76Lambdaparameter: 128
body: 85
77Lambdaparameter: 128
body: 86
78Lambdaparameter: 128
body: 87
79Lambdaparameter: 128
body: 89
80Literal
81Operationoperator: 148
operands: 90
82Operationoperator: 114
operands: 91
83Operationoperator: 98
operands: 92
84Operationoperator: 98
operands: 93
85Operationoperator: 94
operands: 95
86Operationoperator: 115
operands: 96
87Operationoperator: 98
operands: 97
88ExprTuple128
89Operationoperator: 98
operands: 99
90ExprTuple154, 100, 101, 151
91NamedExprsstate: 102
92NamedExprselement: 103
targets: 111
93NamedExprselement: 104
targets: 105
94Literal
95NamedExprsbasis: 106
96NamedExprsoperation: 107
97NamedExprselement: 108
targets: 109
98Literal
99NamedExprselement: 110
targets: 111
100Literal
101Literal
102Operationoperator: 112
operand: 124
103Operationoperator: 114
operands: 121
104Operationoperator: 115
operands: 116
105Operationoperator: 122
operands: 117
106Literal
107Literal
108Operationoperator: 120
operands: 118
109Operationoperator: 122
operands: 119
110Operationoperator: 120
operands: 121
111Operationoperator: 122
operands: 123
112Literal
113ExprTuple124
114Literal
115Literal
116NamedExprsoperation: 125
part: 128
117ExprTuple140, 130
118NamedExprsstate: 126
part: 128
119ExprTuple140, 155
120Literal
121NamedExprsstate: 127
part: 128
122Literal
123ExprTuple129, 130
124Literal
125Operationoperator: 131
operands: 132
126Operationoperator: 133
operands: 134
127Variable
128Variable
129Operationoperator: 136
operands: 135
130Operationoperator: 136
operands: 137
131Literal
132ExprTuple138, 155
133Literal
134ExprTuple139, 155
135ExprTuple155, 140
136Literal
137ExprTuple155, 141
138Variable
139Operationoperator: 142
operands: 143
140Literal
141Variable
142Literal
143ExprTuple144, 150
144Operationoperator: 145
operand: 147
145Literal
146ExprTuple147
147Operationoperator: 148
operands: 149
148Literal
149ExprTuple150, 151
150Operationoperator: 152
operands: 153
151Variable
152Literal
153ExprTuple154, 155
154Literal
155Variable