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, m, n, s, t
from proveit.logic import And, InSet
from proveit.numbers import Add, Exp, Interval, LessEq, ModAbs, Neg, frac, one, 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
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(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(m, 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)])), And(InSet(m, Interval(zero, subtract(two_pow_t, one))), LessEq(ModAbs(subtract(frac(m, two_pow_t), phase), one), Exp(two, Neg(n)))))
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}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \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 m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array} \textrm{ if } m \in \{0~\ldotp \ldotp~2^{t} - 1\} ,  \left|\frac{m}{2^{t}} - \varphi\right|_{\textup{mod}\thinspace 1} \leq 2^{-n}\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, 9, 10
5Literal
6ExprTuple11, 12
7ExprTuple13, 14
8ExprTuple15, 16
9ExprTuple17, 18
10ExprTuple19, 20
11Operationoperator: 21
operands: 22
12Operationoperator: 23
operands: 24
13ExprRangelambda_map: 25
start_index: 112
end_index: 117
14ExprRangelambda_map: 26
start_index: 112
end_index: 113
15ExprRangelambda_map: 27
start_index: 112
end_index: 117
16ExprRangelambda_map: 27
start_index: 94
end_index: 95
17ExprRangelambda_map: 28
start_index: 112
end_index: 117
18ExprRangelambda_map: 29
start_index: 112
end_index: 113
19ExprRangelambda_map: 30
start_index: 112
end_index: 117
20ExprRangelambda_map: 31
start_index: 112
end_index: 113
21Literal
22ExprTuple111, 32
23Literal
24ExprTuple33, 34
25Lambdaparameter: 93
body: 35
26Lambdaparameter: 93
body: 36
27Lambdaparameter: 93
body: 37
28Lambdaparameter: 93
body: 38
29Lambdaparameter: 93
body: 39
30Lambdaparameter: 93
body: 40
31Lambdaparameter: 93
body: 42
32Operationoperator: 83
operands: 43
33Operationoperator: 44
operands: 45
34Operationoperator: 114
operands: 46
35Operationoperator: 75
operands: 47
36Operationoperator: 54
operands: 48
37Operationoperator: 54
operands: 49
38Operationoperator: 50
operands: 51
39Operationoperator: 76
operands: 52
40Operationoperator: 54
operands: 53
41ExprTuple93
42Operationoperator: 54
operands: 55
43ExprTuple56, 57
44Literal
45ExprTuple58, 112
46ExprTuple116, 59
47NamedExprsstate: 60
48NamedExprselement: 61
targets: 69
49NamedExprselement: 62
targets: 63
50Literal
51NamedExprsbasis: 64
52NamedExprsoperation: 65
53NamedExprselement: 66
targets: 67
54Literal
55NamedExprselement: 68
targets: 69
56Literal
57Operationoperator: 106
operands: 70
58Operationoperator: 106
operands: 71
59Operationoperator: 99
operand: 88
60Operationoperator: 73
operand: 89
61Operationoperator: 75
operands: 82
62Operationoperator: 76
operands: 77
63Operationoperator: 83
operands: 78
64Literal
65Literal
66Operationoperator: 81
operands: 79
67Operationoperator: 83
operands: 80
68Operationoperator: 81
operands: 82
69Operationoperator: 83
operands: 84
70ExprTuple108, 85
71ExprTuple86, 87
72ExprTuple88
73Literal
74ExprTuple89
75Literal
76Literal
77NamedExprsoperation: 90
part: 93
78ExprTuple112, 95
79NamedExprsstate: 91
part: 93
80ExprTuple112, 117
81Literal
82NamedExprsstate: 92
part: 93
83Literal
84ExprTuple94, 95
85Operationoperator: 99
operand: 112
86Operationoperator: 97
operands: 98
87Operationoperator: 99
operand: 109
88Variable
89Literal
90Operationoperator: 101
operands: 102
91Operationoperator: 103
operands: 104
92Variable
93Variable
94Operationoperator: 106
operands: 105
95Operationoperator: 106
operands: 107
96ExprTuple112
97Literal
98ExprTuple111, 108
99Literal
100ExprTuple109
101Literal
102ExprTuple110, 117
103Literal
104ExprTuple111, 117
105ExprTuple117, 112
106Literal
107ExprTuple117, 113
108Operationoperator: 114
operands: 115
109Variable
110Variable
111Variable
112Literal
113Variable
114Literal
115ExprTuple116, 117
116Literal
117Variable