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 ExprRange, Lambda, Variable, VertExprArray, l
from proveit.logic import InSet, Injections
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, _ket_u, _pos_domain, _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, 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)]))), Injections(_pos_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}\right)\right] \in \left[\{e + 1~\ldotp \ldotp~2^{t - 1}\} \xrightarrow[]{\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: 1
operands: 2
1Literal
2ExprTuple3, 4
3Lambdaparameter: 106
body: 6
4Operationoperator: 7
operands: 8
5ExprTuple106
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11, 12
9Literal
10ExprTuple13, 14, 15, 16
11Operationoperator: 80
operands: 17
12Literal
13ExprTuple18, 19
14ExprTuple20, 21
15ExprTuple22, 23
16ExprTuple24, 25
17ExprTuple26, 27
18ExprRangelambda_map: 28
start_index: 100
end_index: 101
19ExprRangelambda_map: 29
start_index: 100
end_index: 102
20ExprRangelambda_map: 30
start_index: 100
end_index: 101
21ExprRangelambda_map: 30
start_index: 89
end_index: 90
22ExprRangelambda_map: 31
start_index: 100
end_index: 101
23ExprRangelambda_map: 32
start_index: 100
end_index: 102
24ExprRangelambda_map: 33
start_index: 100
end_index: 101
25ExprRangelambda_map: 34
start_index: 100
end_index: 102
26Operationoperator: 96
operands: 35
27Operationoperator: 36
operands: 37
28Lambdaparameter: 88
body: 38
29Lambdaparameter: 88
body: 39
30Lambdaparameter: 88
body: 40
31Lambdaparameter: 88
body: 41
32Lambdaparameter: 88
body: 42
33Lambdaparameter: 88
body: 43
34Lambdaparameter: 88
body: 45
35ExprTuple46, 100
36Literal
37ExprTuple47, 48
38Operationoperator: 72
operands: 49
39Operationoperator: 56
operands: 50
40Operationoperator: 56
operands: 51
41Operationoperator: 52
operands: 53
42Operationoperator: 73
operands: 54
43Operationoperator: 56
operands: 55
44ExprTuple88
45Operationoperator: 56
operands: 57
46Variable
47Literal
48Operationoperator: 96
operands: 58
49NamedExprsstate: 59
50NamedExprselement: 60
targets: 68
51NamedExprselement: 61
targets: 62
52Literal
53NamedExprsbasis: 63
54NamedExprsoperation: 64
55NamedExprselement: 65
targets: 66
56Literal
57NamedExprselement: 67
targets: 68
58ExprTuple101, 69
59Operationoperator: 70
operand: 84
60Operationoperator: 72
operands: 79
61Operationoperator: 73
operands: 74
62Operationoperator: 80
operands: 75
63Literal
64Literal
65Operationoperator: 78
operands: 76
66Operationoperator: 80
operands: 77
67Operationoperator: 78
operands: 79
68Operationoperator: 80
operands: 81
69Operationoperator: 82
operand: 100
70Literal
71ExprTuple84
72Literal
73Literal
74NamedExprsoperation: 85
part: 88
75ExprTuple100, 90
76NamedExprsstate: 86
part: 88
77ExprTuple100, 101
78Literal
79NamedExprsstate: 87
part: 88
80Literal
81ExprTuple89, 90
82Literal
83ExprTuple100
84Literal
85Operationoperator: 91
operands: 92
86Operationoperator: 93
operands: 94
87Literal
88Variable
89Operationoperator: 96
operands: 95
90Operationoperator: 96
operands: 97
91Literal
92ExprTuple98, 101
93Literal
94ExprTuple99, 101
95ExprTuple101, 100
96Literal
97ExprTuple101, 102
98Literal
99Operationoperator: 103
operands: 104
100Literal
101Literal
102Literal
103Literal
104ExprTuple105, 106
105Literal
106Variable