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, _neg_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(_neg_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[\{-2^{t - 1} + 1~\ldotp \ldotp~-\left(e + 1\right)\} \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: 111
body: 6
4Operationoperator: 7
operands: 8
5ExprTuple111
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: 112
end_index: 104
19ExprRangelambda_map: 29
start_index: 112
end_index: 103
20ExprRangelambda_map: 30
start_index: 112
end_index: 104
21ExprRangelambda_map: 30
start_index: 89
end_index: 90
22ExprRangelambda_map: 31
start_index: 112
end_index: 104
23ExprRangelambda_map: 32
start_index: 112
end_index: 103
24ExprRangelambda_map: 33
start_index: 112
end_index: 104
25ExprRangelambda_map: 34
start_index: 112
end_index: 103
26Operationoperator: 99
operands: 35
27Operationoperator: 108
operand: 46
28Lambdaparameter: 88
body: 37
29Lambdaparameter: 88
body: 38
30Lambdaparameter: 88
body: 39
31Lambdaparameter: 88
body: 40
32Lambdaparameter: 88
body: 41
33Lambdaparameter: 88
body: 42
34Lambdaparameter: 88
body: 44
35ExprTuple45, 112
36ExprTuple46
37Operationoperator: 72
operands: 47
38Operationoperator: 54
operands: 48
39Operationoperator: 54
operands: 49
40Operationoperator: 50
operands: 51
41Operationoperator: 73
operands: 52
42Operationoperator: 54
operands: 53
43ExprTuple88
44Operationoperator: 54
operands: 55
45Operationoperator: 108
operand: 68
46Operationoperator: 99
operands: 57
47NamedExprsstate: 58
48NamedExprselement: 59
targets: 67
49NamedExprselement: 60
targets: 61
50Literal
51NamedExprsbasis: 62
52NamedExprsoperation: 63
53NamedExprselement: 64
targets: 65
54Literal
55NamedExprselement: 66
targets: 67
56ExprTuple68
57ExprTuple69, 112
58Operationoperator: 70
operand: 84
59Operationoperator: 72
operands: 79
60Operationoperator: 73
operands: 74
61Operationoperator: 80
operands: 75
62Literal
63Literal
64Operationoperator: 78
operands: 76
65Operationoperator: 80
operands: 77
66Operationoperator: 78
operands: 79
67Operationoperator: 80
operands: 81
68Operationoperator: 82
operands: 83
69Variable
70Literal
71ExprTuple84
72Literal
73Literal
74NamedExprsoperation: 85
part: 88
75ExprTuple112, 90
76NamedExprsstate: 86
part: 88
77ExprTuple112, 104
78Literal
79NamedExprsstate: 87
part: 88
80Literal
81ExprTuple89, 90
82Literal
83ExprTuple91, 92
84Literal
85Operationoperator: 93
operands: 94
86Operationoperator: 95
operands: 96
87Literal
88Variable
89Operationoperator: 99
operands: 97
90Operationoperator: 99
operands: 98
91Literal
92Operationoperator: 99
operands: 100
93Literal
94ExprTuple101, 104
95Literal
96ExprTuple102, 104
97ExprTuple104, 112
98ExprTuple104, 103
99Literal
100ExprTuple104, 105
101Literal
102Operationoperator: 106
operands: 107
103Literal
104Literal
105Operationoperator: 108
operand: 112
106Literal
107ExprTuple110, 111
108Literal
109ExprTuple112
110Literal
111Variable
112Literal