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 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, 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)]))), 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}\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: 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: 75
operands: 17
12Literal
13ExprTuple18, 19
14ExprTuple20, 21
15ExprTuple22, 23
16ExprTuple24, 25
17ExprTuple26, 64
18ExprRangelambda_map: 27
start_index: 107
end_index: 99
19ExprRangelambda_map: 28
start_index: 107
end_index: 98
20ExprRangelambda_map: 29
start_index: 107
end_index: 99
21ExprRangelambda_map: 29
start_index: 84
end_index: 85
22ExprRangelambda_map: 30
start_index: 107
end_index: 99
23ExprRangelambda_map: 31
start_index: 107
end_index: 98
24ExprRangelambda_map: 32
start_index: 107
end_index: 99
25ExprRangelambda_map: 33
start_index: 107
end_index: 98
26Operationoperator: 94
operands: 34
27Lambdaparameter: 83
body: 35
28Lambdaparameter: 83
body: 36
29Lambdaparameter: 83
body: 37
30Lambdaparameter: 83
body: 38
31Lambdaparameter: 83
body: 39
32Lambdaparameter: 83
body: 40
33Lambdaparameter: 83
body: 42
34ExprTuple43, 107
35Operationoperator: 67
operands: 44
36Operationoperator: 51
operands: 45
37Operationoperator: 51
operands: 46
38Operationoperator: 47
operands: 48
39Operationoperator: 68
operands: 49
40Operationoperator: 51
operands: 50
41ExprTuple83
42Operationoperator: 51
operands: 52
43Operationoperator: 103
operand: 64
44NamedExprsstate: 54
45NamedExprselement: 55
targets: 63
46NamedExprselement: 56
targets: 57
47Literal
48NamedExprsbasis: 58
49NamedExprsoperation: 59
50NamedExprselement: 60
targets: 61
51Literal
52NamedExprselement: 62
targets: 63
53ExprTuple64
54Operationoperator: 65
operand: 79
55Operationoperator: 67
operands: 74
56Operationoperator: 68
operands: 69
57Operationoperator: 75
operands: 70
58Literal
59Literal
60Operationoperator: 73
operands: 71
61Operationoperator: 75
operands: 72
62Operationoperator: 73
operands: 74
63Operationoperator: 75
operands: 76
64Operationoperator: 77
operands: 78
65Literal
66ExprTuple79
67Literal
68Literal
69NamedExprsoperation: 80
part: 83
70ExprTuple107, 85
71NamedExprsstate: 81
part: 83
72ExprTuple107, 99
73Literal
74NamedExprsstate: 82
part: 83
75Literal
76ExprTuple84, 85
77Literal
78ExprTuple86, 87
79Literal
80Operationoperator: 88
operands: 89
81Operationoperator: 90
operands: 91
82Literal
83Variable
84Operationoperator: 94
operands: 92
85Operationoperator: 94
operands: 93
86Literal
87Operationoperator: 94
operands: 95
88Literal
89ExprTuple96, 99
90Literal
91ExprTuple97, 99
92ExprTuple99, 107
93ExprTuple99, 98
94Literal
95ExprTuple99, 100
96Literal
97Operationoperator: 101
operands: 102
98Literal
99Literal
100Operationoperator: 103
operand: 107
101Literal
102ExprTuple105, 106
103Literal
104ExprTuple107
105Literal
106Variable
107Literal