logo

Expression of type InSet

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, Lambda, Variable, VertExprArray, l
from proveit.logic import Bijections, InSet
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import ModAdd, QPE, _Omega, _U, _b_floor, _full_domain, _ket_u, _s, _s_wire, _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 = InSet(Lambda(l, Conditional(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _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), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(ModAdd(_b_floor, l), _t), part = sub_expr1), targets = Interval(one, _t)), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)])), InSet(l, _full_domain))), Bijections(_full_domain, _Omega))
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[l \mapsto \left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \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 b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array} \textrm{ if } l \in \{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\}\right..\right] \in \left[\{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\} \xrightarrow[\text{onto}]{\text{1-to-1}} \Omega\right]
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 13
operands: 1
1ExprTuple2, 3
2Lambdaparameter: 107
body: 5
3Operationoperator: 6
operands: 7
4ExprTuple107
5Conditionalvalue: 8
condition: 9
6Literal
7ExprTuple19, 10
8Operationoperator: 11
operands: 12
9Operationoperator: 13
operands: 14
10Literal
11Literal
12ExprTuple15, 16, 17, 18
13Literal
14ExprTuple107, 19
15ExprTuple20, 21
16ExprTuple22, 23
17ExprTuple24, 25
18ExprTuple26, 27
19Operationoperator: 77
operands: 28
20ExprRangelambda_map: 29
start_index: 110
end_index: 104
21ExprRangelambda_map: 30
start_index: 110
end_index: 99
22ExprRangelambda_map: 31
start_index: 110
end_index: 104
23ExprRangelambda_map: 31
start_index: 85
end_index: 86
24ExprRangelambda_map: 32
start_index: 110
end_index: 104
25ExprRangelambda_map: 33
start_index: 110
end_index: 99
26ExprRangelambda_map: 34
start_index: 110
end_index: 104
27ExprRangelambda_map: 35
start_index: 110
end_index: 99
28ExprTuple36, 79
29Lambdaparameter: 84
body: 37
30Lambdaparameter: 84
body: 38
31Lambdaparameter: 84
body: 39
32Lambdaparameter: 84
body: 40
33Lambdaparameter: 84
body: 41
34Lambdaparameter: 84
body: 42
35Lambdaparameter: 84
body: 44
36Operationoperator: 100
operands: 45
37Operationoperator: 69
operands: 46
38Operationoperator: 53
operands: 47
39Operationoperator: 53
operands: 48
40Operationoperator: 49
operands: 50
41Operationoperator: 70
operands: 51
42Operationoperator: 53
operands: 52
43ExprTuple84
44Operationoperator: 53
operands: 54
45ExprTuple55, 110
46NamedExprsstate: 56
47NamedExprselement: 57
targets: 65
48NamedExprselement: 58
targets: 59
49Literal
50NamedExprsbasis: 60
51NamedExprsoperation: 61
52NamedExprselement: 62
targets: 63
53Literal
54NamedExprselement: 64
targets: 65
55Operationoperator: 108
operand: 79
56Operationoperator: 67
operand: 80
57Operationoperator: 69
operands: 76
58Operationoperator: 70
operands: 71
59Operationoperator: 77
operands: 72
60Literal
61Literal
62Operationoperator: 75
operands: 73
63Operationoperator: 77
operands: 74
64Operationoperator: 75
operands: 76
65Operationoperator: 77
operands: 78
66ExprTuple79
67Literal
68ExprTuple80
69Literal
70Literal
71NamedExprsoperation: 81
part: 84
72ExprTuple110, 86
73NamedExprsstate: 82
part: 84
74ExprTuple110, 104
75Literal
76NamedExprsstate: 83
part: 84
77Literal
78ExprTuple85, 86
79Operationoperator: 87
operands: 88
80Literal
81Operationoperator: 89
operands: 90
82Operationoperator: 91
operands: 92
83Literal
84Variable
85Operationoperator: 100
operands: 93
86Operationoperator: 100
operands: 94
87Literal
88ExprTuple95, 96
89Literal
90ExprTuple97, 104
91Literal
92ExprTuple98, 104
93ExprTuple104, 110
94ExprTuple104, 99
95Literal
96Operationoperator: 100
operands: 101
97Literal
98Operationoperator: 102
operands: 103
99Literal
100Literal
101ExprTuple104, 105
102Literal
103ExprTuple106, 107
104Literal
105Operationoperator: 108
operand: 110
106Literal
107Variable
108Literal
109ExprTuple110
110Literal