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, Mult, Real, e, i, one, pi, subtract, 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 = Mult(two_pow_t, phase)
sub_expr6 = 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 = Equals(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_expr6, one, t), ExprRange(sub_expr1, sub_expr6, 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(sub_expr5, 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)]))), one), domain = Real, conditions = [InSet(sub_expr5, Interval(zero, subtract(two_pow_t, 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}~|~\left(2^{t} \cdot \varphi\right) \in \{0~\ldotp \ldotp~2^{t} - 1\}, \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = 1\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: 18
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameter: 142
body: 10
7Operationoperator: 33
operands: 11
8Operationoperator: 35
operands: 12
9ExprTuple142
10Conditionalvalue: 13
condition: 14
11ExprTuple124, 15
12ExprTuple16, 137
13Operationoperator: 35
operands: 17
14Operationoperator: 18
operands: 19
15Operationoperator: 20
operands: 21
16Operationoperator: 22
operand: 124
17ExprTuple24, 137
18Literal
19ExprTuple25, 26, 27
20Literal
21ExprTuple28, 29
22Literal
23ExprTuple124
24Operationoperator: 30
operand: 38
25Operationoperator: 33
operands: 32
26Operationoperator: 33
operands: 34
27Operationoperator: 35
operands: 36
28Literal
29Operationoperator: 143
operands: 37
30Literal
31ExprTuple38
32ExprTuple142, 39
33Literal
34ExprTuple136, 40
35Literal
36ExprTuple41, 42
37ExprTuple145, 138
38Operationoperator: 43
operands: 44
39Literal
40Operationoperator: 119
operands: 45
41Operationoperator: 46
operands: 47
42Operationoperator: 48
operands: 49
43Literal
44ExprTuple50, 51, 52, 53
45ExprTuple54, 55
46Literal
47ExprTuple135, 124
48Literal
49ExprTuple56, 124
50ExprTuple57, 58
51ExprTuple59, 60
52ExprTuple61, 62
53ExprTuple63, 64
54Literal
55Operationoperator: 133
operands: 65
56Operationoperator: 143
operands: 66
57ExprRangelambda_map: 67
start_index: 137
end_index: 146
58ExprRangelambda_map: 68
start_index: 137
end_index: 138
59ExprRangelambda_map: 69
start_index: 137
end_index: 146
60ExprRangelambda_map: 69
start_index: 126
end_index: 127
61ExprRangelambda_map: 70
start_index: 137
end_index: 146
62ExprRangelambda_map: 71
start_index: 137
end_index: 138
63ExprRangelambda_map: 72
start_index: 137
end_index: 146
64ExprRangelambda_map: 73
start_index: 137
end_index: 138
65ExprTuple141, 74
66ExprTuple75, 76
67Lambdaparameter: 125
body: 77
68Lambdaparameter: 125
body: 78
69Lambdaparameter: 125
body: 79
70Lambdaparameter: 125
body: 80
71Lambdaparameter: 125
body: 81
72Lambdaparameter: 125
body: 82
73Lambdaparameter: 125
body: 84
74Operationoperator: 85
operand: 137
75Literal
76Operationoperator: 139
operands: 87
77Operationoperator: 111
operands: 88
78Operationoperator: 95
operands: 89
79Operationoperator: 95
operands: 90
80Operationoperator: 91
operands: 92
81Operationoperator: 112
operands: 93
82Operationoperator: 95
operands: 94
83ExprTuple125
84Operationoperator: 95
operands: 96
85Literal
86ExprTuple137
87ExprTuple145, 97, 98, 142
88NamedExprsstate: 99
89NamedExprselement: 100
targets: 108
90NamedExprselement: 101
targets: 102
91Literal
92NamedExprsbasis: 103
93NamedExprsoperation: 104
94NamedExprselement: 105
targets: 106
95Literal
96NamedExprselement: 107
targets: 108
97Literal
98Literal
99Operationoperator: 109
operand: 121
100Operationoperator: 111
operands: 118
101Operationoperator: 112
operands: 113
102Operationoperator: 119
operands: 114
103Literal
104Literal
105Operationoperator: 117
operands: 115
106Operationoperator: 119
operands: 116
107Operationoperator: 117
operands: 118
108Operationoperator: 119
operands: 120
109Literal
110ExprTuple121
111Literal
112Literal
113NamedExprsoperation: 122
part: 125
114ExprTuple137, 127
115NamedExprsstate: 123
part: 125
116ExprTuple137, 146
117Literal
118NamedExprsstate: 124
part: 125
119Literal
120ExprTuple126, 127
121Literal
122Operationoperator: 128
operands: 129
123Operationoperator: 130
operands: 131
124Variable
125Variable
126Operationoperator: 133
operands: 132
127Operationoperator: 133
operands: 134
128Literal
129ExprTuple135, 146
130Literal
131ExprTuple136, 146
132ExprTuple146, 137
133Literal
134ExprTuple146, 138
135Variable
136Operationoperator: 139
operands: 140
137Literal
138Variable
139Literal
140ExprTuple141, 142
141Operationoperator: 143
operands: 144
142Variable
143Literal
144ExprTuple145, 146
145Literal
146Variable