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, Literal, Variable, VertExprArray, e, m
from proveit.logic import And, InSet
from proveit.numbers import Add, Exp, Interval, LessEq, ModAbs, one, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import QPE
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(Literal("t", theory = "proveit.physics.quantum.QPE"), one)
sub_expr3 = Add(Literal("t", theory = "proveit.physics.quantum.QPE"), Literal("s", theory = "proveit.physics.quantum.QPE"))
sub_expr4 = Exp(two, Literal("t", theory = "proveit.physics.quantum.QPE"))
sub_expr5 = Interval(sub_expr2, sub_expr3)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(Literal("U", theory = "proveit.physics.quantum.QPE"), Literal("t", theory = "proveit.physics.quantum.QPE")), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = ExprTuple(Lambda(m, Conditional(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr5), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, sub_expr6, one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, sub_expr6, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, Literal("t", theory = "proveit.physics.quantum.QPE")), part = sub_expr1), targets = Interval(one, Literal("t", theory = "proveit.physics.quantum.QPE"))), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr5), one, Literal("s", theory = "proveit.physics.quantum.QPE"))])), And(InSet(m, Interval(zero, subtract(sub_expr4, one))), LessEq(ModAbs(subtract(m, Literal("b_{f}", latex_format = r"b_{\textit{f}}", theory = "proveit.physics.quantum.QPE")), sub_expr4), e)))))
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(m \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 m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \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 m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array} \textrm{ if } m \in \{0~\ldotp \ldotp~2^{t} - 1\} ,  \left|m - b_{\textit{f}}\right|_{\textup{mod}\thinspace 2^{t}} \leq e\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 110
body: 3
2ExprTuple110
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operands: 7
5Operationoperator: 8
operands: 9
6Literal
7ExprTuple10, 11, 12, 13
8Literal
9ExprTuple14, 15
10ExprTuple16, 17
11ExprTuple18, 19
12ExprTuple20, 21
13ExprTuple22, 23
14Operationoperator: 24
operands: 25
15Operationoperator: 26
operands: 27
16ExprRangelambda_map: 28
start_index: 111
end_index: 112
17ExprRangelambda_map: 29
start_index: 111
end_index: 113
18ExprRangelambda_map: 30
start_index: 111
end_index: 112
19ExprRangelambda_map: 30
start_index: 93
end_index: 94
20ExprRangelambda_map: 31
start_index: 111
end_index: 112
21ExprRangelambda_map: 32
start_index: 111
end_index: 113
22ExprRangelambda_map: 33
start_index: 111
end_index: 112
23ExprRangelambda_map: 34
start_index: 111
end_index: 113
24Literal
25ExprTuple110, 35
26Literal
27ExprTuple36, 37
28Lambdaparameter: 92
body: 38
29Lambdaparameter: 92
body: 39
30Lambdaparameter: 92
body: 40
31Lambdaparameter: 92
body: 41
32Lambdaparameter: 92
body: 42
33Lambdaparameter: 92
body: 43
34Lambdaparameter: 92
body: 45
35Operationoperator: 83
operands: 46
36Operationoperator: 47
operands: 48
37Variable
38Operationoperator: 75
operands: 49
39Operationoperator: 56
operands: 50
40Operationoperator: 56
operands: 51
41Operationoperator: 52
operands: 53
42Operationoperator: 76
operands: 54
43Operationoperator: 56
operands: 55
44ExprTuple92
45Operationoperator: 56
operands: 57
46ExprTuple58, 59
47Literal
48ExprTuple60, 85
49NamedExprsstate: 61
50NamedExprselement: 62
targets: 70
51NamedExprselement: 63
targets: 64
52Literal
53NamedExprsbasis: 65
54NamedExprsoperation: 66
55NamedExprselement: 67
targets: 68
56Literal
57NamedExprselement: 69
targets: 70
58Literal
59Operationoperator: 105
operands: 71
60Operationoperator: 105
operands: 72
61Operationoperator: 73
operand: 88
62Operationoperator: 75
operands: 82
63Operationoperator: 76
operands: 77
64Operationoperator: 83
operands: 78
65Literal
66Literal
67Operationoperator: 81
operands: 79
68Operationoperator: 83
operands: 80
69Operationoperator: 81
operands: 82
70Operationoperator: 83
operands: 84
71ExprTuple85, 86
72ExprTuple110, 87
73Literal
74ExprTuple88
75Literal
76Literal
77NamedExprsoperation: 89
part: 92
78ExprTuple111, 94
79NamedExprsstate: 90
part: 92
80ExprTuple111, 112
81Literal
82NamedExprsstate: 91
part: 92
83Literal
84ExprTuple93, 94
85Operationoperator: 95
operands: 96
86Operationoperator: 98
operand: 111
87Operationoperator: 98
operand: 108
88Literal
89Operationoperator: 100
operands: 101
90Operationoperator: 102
operands: 103
91Literal
92Variable
93Operationoperator: 105
operands: 104
94Operationoperator: 105
operands: 106
95Literal
96ExprTuple107, 112
97ExprTuple111
98Literal
99ExprTuple108
100Literal
101ExprTuple109, 112
102Literal
103ExprTuple110, 112
104ExprTuple112, 111
105Literal
106ExprTuple112, 113
107Literal
108Literal
109Literal
110Variable
111Literal
112Literal
113Literal