logo

Expression of type ExprTuple

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, ExprTuple, 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 = ExprTuple(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.., \left[\{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\} \xrightarrow[\text{onto}]{\text{1-to-1}} \Omega\right]\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Lambdaparameter: 106
body: 4
2Operationoperator: 5
operands: 6
3ExprTuple106
4Conditionalvalue: 7
condition: 8
5Literal
6ExprTuple18, 9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operands: 13
9Literal
10Literal
11ExprTuple14, 15, 16, 17
12Literal
13ExprTuple106, 18
14ExprTuple19, 20
15ExprTuple21, 22
16ExprTuple23, 24
17ExprTuple25, 26
18Operationoperator: 76
operands: 27
19ExprRangelambda_map: 28
start_index: 109
end_index: 103
20ExprRangelambda_map: 29
start_index: 109
end_index: 98
21ExprRangelambda_map: 30
start_index: 109
end_index: 103
22ExprRangelambda_map: 30
start_index: 84
end_index: 85
23ExprRangelambda_map: 31
start_index: 109
end_index: 103
24ExprRangelambda_map: 32
start_index: 109
end_index: 98
25ExprRangelambda_map: 33
start_index: 109
end_index: 103
26ExprRangelambda_map: 34
start_index: 109
end_index: 98
27ExprTuple35, 78
28Lambdaparameter: 83
body: 36
29Lambdaparameter: 83
body: 37
30Lambdaparameter: 83
body: 38
31Lambdaparameter: 83
body: 39
32Lambdaparameter: 83
body: 40
33Lambdaparameter: 83
body: 41
34Lambdaparameter: 83
body: 43
35Operationoperator: 99
operands: 44
36Operationoperator: 68
operands: 45
37Operationoperator: 52
operands: 46
38Operationoperator: 52
operands: 47
39Operationoperator: 48
operands: 49
40Operationoperator: 69
operands: 50
41Operationoperator: 52
operands: 51
42ExprTuple83
43Operationoperator: 52
operands: 53
44ExprTuple54, 109
45NamedExprsstate: 55
46NamedExprselement: 56
targets: 64
47NamedExprselement: 57
targets: 58
48Literal
49NamedExprsbasis: 59
50NamedExprsoperation: 60
51NamedExprselement: 61
targets: 62
52Literal
53NamedExprselement: 63
targets: 64
54Operationoperator: 107
operand: 78
55Operationoperator: 66
operand: 79
56Operationoperator: 68
operands: 75
57Operationoperator: 69
operands: 70
58Operationoperator: 76
operands: 71
59Literal
60Literal
61Operationoperator: 74
operands: 72
62Operationoperator: 76
operands: 73
63Operationoperator: 74
operands: 75
64Operationoperator: 76
operands: 77
65ExprTuple78
66Literal
67ExprTuple79
68Literal
69Literal
70NamedExprsoperation: 80
part: 83
71ExprTuple109, 85
72NamedExprsstate: 81
part: 83
73ExprTuple109, 103
74Literal
75NamedExprsstate: 82
part: 83
76Literal
77ExprTuple84, 85
78Operationoperator: 86
operands: 87
79Literal
80Operationoperator: 88
operands: 89
81Operationoperator: 90
operands: 91
82Literal
83Variable
84Operationoperator: 99
operands: 92
85Operationoperator: 99
operands: 93
86Literal
87ExprTuple94, 95
88Literal
89ExprTuple96, 103
90Literal
91ExprTuple97, 103
92ExprTuple103, 109
93ExprTuple103, 98
94Literal
95Operationoperator: 99
operands: 100
96Literal
97Operationoperator: 101
operands: 102
98Literal
99Literal
100ExprTuple103, 104
101Literal
102ExprTuple105, 106
103Literal
104Operationoperator: 107
operand: 109
105Literal
106Variable
107Literal
108ExprTuple109
109Literal