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, 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, 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 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(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))), And(InSet(phase, Real), InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), 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\{\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}} \textrm{ if } \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)\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
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple9, 10, 11
7Operationoperator: 12
operands: 13
8Operationoperator: 14
operand: 23
9Operationoperator: 17
operands: 16
10Operationoperator: 17
operands: 18
11Operationoperator: 19
operands: 20
12Literal
13ExprTuple21, 22
14Literal
15ExprTuple23
16ExprTuple130, 24
17Literal
18ExprTuple130, 25
19Literal
20ExprTuple26, 27
21Literal
22Operationoperator: 131
operands: 28
23Operationoperator: 29
operands: 30
24Literal
25Operationoperator: 31
operands: 32
26Operationoperator: 33
operands: 34
27Operationoperator: 35
operands: 36
28ExprTuple79, 133
29Literal
30ExprTuple37, 38, 39, 40
31Literal
32ExprTuple41, 119
33Literal
34ExprTuple117, 106
35Literal
36ExprTuple42, 106
37ExprTuple43, 44
38ExprTuple45, 46
39ExprTuple47, 48
40ExprTuple49, 50
41Literal
42Operationoperator: 131
operands: 51
43ExprRangelambda_map: 52
start_index: 119
end_index: 134
44ExprRangelambda_map: 53
start_index: 119
end_index: 120
45ExprRangelambda_map: 54
start_index: 119
end_index: 134
46ExprRangelambda_map: 54
start_index: 108
end_index: 109
47ExprRangelambda_map: 55
start_index: 119
end_index: 134
48ExprRangelambda_map: 56
start_index: 119
end_index: 120
49ExprRangelambda_map: 57
start_index: 119
end_index: 134
50ExprRangelambda_map: 58
start_index: 119
end_index: 120
51ExprTuple59, 60
52Lambdaparameter: 107
body: 61
53Lambdaparameter: 107
body: 62
54Lambdaparameter: 107
body: 63
55Lambdaparameter: 107
body: 64
56Lambdaparameter: 107
body: 65
57Lambdaparameter: 107
body: 66
58Lambdaparameter: 107
body: 68
59Literal
60Operationoperator: 127
operands: 69
61Operationoperator: 93
operands: 70
62Operationoperator: 77
operands: 71
63Operationoperator: 77
operands: 72
64Operationoperator: 73
operands: 74
65Operationoperator: 94
operands: 75
66Operationoperator: 77
operands: 76
67ExprTuple107
68Operationoperator: 77
operands: 78
69ExprTuple133, 79, 80, 130
70NamedExprsstate: 81
71NamedExprselement: 82
targets: 90
72NamedExprselement: 83
targets: 84
73Literal
74NamedExprsbasis: 85
75NamedExprsoperation: 86
76NamedExprselement: 87
targets: 88
77Literal
78NamedExprselement: 89
targets: 90
79Literal
80Literal
81Operationoperator: 91
operand: 103
82Operationoperator: 93
operands: 100
83Operationoperator: 94
operands: 95
84Operationoperator: 101
operands: 96
85Literal
86Literal
87Operationoperator: 99
operands: 97
88Operationoperator: 101
operands: 98
89Operationoperator: 99
operands: 100
90Operationoperator: 101
operands: 102
91Literal
92ExprTuple103
93Literal
94Literal
95NamedExprsoperation: 104
part: 107
96ExprTuple119, 109
97NamedExprsstate: 105
part: 107
98ExprTuple119, 134
99Literal
100NamedExprsstate: 106
part: 107
101Literal
102ExprTuple108, 109
103Literal
104Operationoperator: 110
operands: 111
105Operationoperator: 112
operands: 113
106Variable
107Variable
108Operationoperator: 115
operands: 114
109Operationoperator: 115
operands: 116
110Literal
111ExprTuple117, 134
112Literal
113ExprTuple118, 134
114ExprTuple134, 119
115Literal
116ExprTuple134, 120
117Variable
118Operationoperator: 121
operands: 122
119Literal
120Variable
121Literal
122ExprTuple123, 129
123Operationoperator: 124
operand: 126
124Literal
125ExprTuple126
126Operationoperator: 127
operands: 128
127Literal
128ExprTuple129, 130
129Operationoperator: 131
operands: 132
130Variable
131Literal
132ExprTuple133, 134
133Literal
134Variable