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, Unitary
from proveit.logic import 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_s, 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 = [var_ket_u], instance_expr = 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(), domain = s_ket_domain, condition = normalized_var_ket_u).with_wrapping(), InSet(U, Unitary(two_pow_s)))
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_{\lvert u \rangle \in \mathbb{C}^{2^{s}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\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}\right]\end{array} \textrm{ if } U \in \textrm{U}\left(2^{s}\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: 12
operand: 5
2Operationoperator: 42
operands: 4
3ExprTuple5
4ExprTuple144, 6
5Lambdaparameter: 133
body: 7
6Operationoperator: 8
operand: 38
7Conditionalvalue: 10
condition: 11
8Literal
9ExprTuple38
10Operationoperator: 12
operand: 15
11Operationoperator: 27
operands: 14
12Literal
13ExprTuple15
14ExprTuple16, 17
15Lambdaparameter: 151
body: 19
16Operationoperator: 42
operands: 20
17Operationoperator: 44
operands: 21
18ExprTuple151
19Conditionalvalue: 22
condition: 23
20ExprTuple133, 24
21ExprTuple25, 146
22Operationoperator: 44
operands: 26
23Operationoperator: 27
operands: 28
24Operationoperator: 29
operands: 30
25Operationoperator: 31
operand: 133
26ExprTuple33, 146
27Literal
28ExprTuple34, 35, 36
29Literal
30ExprTuple37, 38
31Literal
32ExprTuple133
33Operationoperator: 39
operand: 47
34Operationoperator: 42
operands: 41
35Operationoperator: 42
operands: 43
36Operationoperator: 44
operands: 45
37Literal
38Operationoperator: 152
operands: 46
39Literal
40ExprTuple47
41ExprTuple151, 48
42Literal
43ExprTuple145, 49
44Literal
45ExprTuple50, 51
46ExprTuple154, 147
47Operationoperator: 52
operands: 53
48Literal
49Operationoperator: 128
operands: 54
50Operationoperator: 55
operands: 56
51Operationoperator: 57
operands: 58
52Literal
53ExprTuple59, 60, 61, 62
54ExprTuple63, 64
55Literal
56ExprTuple144, 133
57Literal
58ExprTuple65, 133
59ExprTuple66, 67
60ExprTuple68, 69
61ExprTuple70, 71
62ExprTuple72, 73
63Literal
64Operationoperator: 142
operands: 74
65Operationoperator: 152
operands: 75
66ExprRangelambda_map: 76
start_index: 146
end_index: 155
67ExprRangelambda_map: 77
start_index: 146
end_index: 147
68ExprRangelambda_map: 78
start_index: 146
end_index: 155
69ExprRangelambda_map: 78
start_index: 135
end_index: 136
70ExprRangelambda_map: 79
start_index: 146
end_index: 155
71ExprRangelambda_map: 80
start_index: 146
end_index: 147
72ExprRangelambda_map: 81
start_index: 146
end_index: 155
73ExprRangelambda_map: 82
start_index: 146
end_index: 147
74ExprTuple150, 83
75ExprTuple84, 85
76Lambdaparameter: 134
body: 86
77Lambdaparameter: 134
body: 87
78Lambdaparameter: 134
body: 88
79Lambdaparameter: 134
body: 89
80Lambdaparameter: 134
body: 90
81Lambdaparameter: 134
body: 91
82Lambdaparameter: 134
body: 93
83Operationoperator: 94
operand: 146
84Literal
85Operationoperator: 148
operands: 96
86Operationoperator: 120
operands: 97
87Operationoperator: 104
operands: 98
88Operationoperator: 104
operands: 99
89Operationoperator: 100
operands: 101
90Operationoperator: 121
operands: 102
91Operationoperator: 104
operands: 103
92ExprTuple134
93Operationoperator: 104
operands: 105
94Literal
95ExprTuple146
96ExprTuple154, 106, 107, 151
97NamedExprsstate: 108
98NamedExprselement: 109
targets: 117
99NamedExprselement: 110
targets: 111
100Literal
101NamedExprsbasis: 112
102NamedExprsoperation: 113
103NamedExprselement: 114
targets: 115
104Literal
105NamedExprselement: 116
targets: 117
106Literal
107Literal
108Operationoperator: 118
operand: 130
109Operationoperator: 120
operands: 127
110Operationoperator: 121
operands: 122
111Operationoperator: 128
operands: 123
112Literal
113Literal
114Operationoperator: 126
operands: 124
115Operationoperator: 128
operands: 125
116Operationoperator: 126
operands: 127
117Operationoperator: 128
operands: 129
118Literal
119ExprTuple130
120Literal
121Literal
122NamedExprsoperation: 131
part: 134
123ExprTuple146, 136
124NamedExprsstate: 132
part: 134
125ExprTuple146, 155
126Literal
127NamedExprsstate: 133
part: 134
128Literal
129ExprTuple135, 136
130Literal
131Operationoperator: 137
operands: 138
132Operationoperator: 139
operands: 140
133Variable
134Variable
135Operationoperator: 142
operands: 141
136Operationoperator: 142
operands: 143
137Literal
138ExprTuple144, 155
139Literal
140ExprTuple145, 155
141ExprTuple155, 146
142Literal
143ExprTuple155, 147
144Variable
145Operationoperator: 148
operands: 149
146Literal
147Variable
148Literal
149ExprTuple150, 151
150Operationoperator: 152
operands: 153
151Variable
152Literal
153ExprTuple154, 155
154Literal
155Variable