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, Mult, Real, e, i, one, pi, 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 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(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), And(InSet(phase, Real), 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))))
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 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 \textrm{ if } \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)\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: 15
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 116
4Literal
5ExprTuple7, 8, 9
6Operationoperator: 10
operand: 17
7Operationoperator: 13
operands: 12
8Operationoperator: 13
operands: 14
9Operationoperator: 15
operands: 16
10Literal
11ExprTuple17
12ExprTuple121, 18
13Literal
14ExprTuple115, 19
15Literal
16ExprTuple20, 21
17Operationoperator: 22
operands: 23
18Literal
19Operationoperator: 98
operands: 24
20Operationoperator: 25
operands: 26
21Operationoperator: 27
operands: 28
22Literal
23ExprTuple29, 30, 31, 32
24ExprTuple33, 34
25Literal
26ExprTuple114, 103
27Literal
28ExprTuple35, 103
29ExprTuple36, 37
30ExprTuple38, 39
31ExprTuple40, 41
32ExprTuple42, 43
33Literal
34Operationoperator: 112
operands: 44
35Operationoperator: 122
operands: 45
36ExprRangelambda_map: 46
start_index: 116
end_index: 125
37ExprRangelambda_map: 47
start_index: 116
end_index: 117
38ExprRangelambda_map: 48
start_index: 116
end_index: 125
39ExprRangelambda_map: 48
start_index: 105
end_index: 106
40ExprRangelambda_map: 49
start_index: 116
end_index: 125
41ExprRangelambda_map: 50
start_index: 116
end_index: 117
42ExprRangelambda_map: 51
start_index: 116
end_index: 125
43ExprRangelambda_map: 52
start_index: 116
end_index: 117
44ExprTuple120, 53
45ExprTuple54, 55
46Lambdaparameter: 104
body: 56
47Lambdaparameter: 104
body: 57
48Lambdaparameter: 104
body: 58
49Lambdaparameter: 104
body: 59
50Lambdaparameter: 104
body: 60
51Lambdaparameter: 104
body: 61
52Lambdaparameter: 104
body: 63
53Operationoperator: 64
operand: 116
54Literal
55Operationoperator: 118
operands: 66
56Operationoperator: 90
operands: 67
57Operationoperator: 74
operands: 68
58Operationoperator: 74
operands: 69
59Operationoperator: 70
operands: 71
60Operationoperator: 91
operands: 72
61Operationoperator: 74
operands: 73
62ExprTuple104
63Operationoperator: 74
operands: 75
64Literal
65ExprTuple116
66ExprTuple124, 76, 77, 121
67NamedExprsstate: 78
68NamedExprselement: 79
targets: 87
69NamedExprselement: 80
targets: 81
70Literal
71NamedExprsbasis: 82
72NamedExprsoperation: 83
73NamedExprselement: 84
targets: 85
74Literal
75NamedExprselement: 86
targets: 87
76Literal
77Literal
78Operationoperator: 88
operand: 100
79Operationoperator: 90
operands: 97
80Operationoperator: 91
operands: 92
81Operationoperator: 98
operands: 93
82Literal
83Literal
84Operationoperator: 96
operands: 94
85Operationoperator: 98
operands: 95
86Operationoperator: 96
operands: 97
87Operationoperator: 98
operands: 99
88Literal
89ExprTuple100
90Literal
91Literal
92NamedExprsoperation: 101
part: 104
93ExprTuple116, 106
94NamedExprsstate: 102
part: 104
95ExprTuple116, 125
96Literal
97NamedExprsstate: 103
part: 104
98Literal
99ExprTuple105, 106
100Literal
101Operationoperator: 107
operands: 108
102Operationoperator: 109
operands: 110
103Variable
104Variable
105Operationoperator: 112
operands: 111
106Operationoperator: 112
operands: 113
107Literal
108ExprTuple114, 125
109Literal
110ExprTuple115, 125
111ExprTuple125, 116
112Literal
113ExprTuple125, 117
114Variable
115Operationoperator: 118
operands: 119
116Literal
117Variable
118Literal
119ExprTuple120, 121
120Operationoperator: 122
operands: 123
121Variable
122Literal
123ExprTuple124, 125
124Literal
125Variable