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, m
from proveit.logic import InSet
from proveit.numbers import Add, Exp, Interval, 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 = Interval(sub_expr2, sub_expr3)
sub_expr5 = 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_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, sub_expr5, one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, sub_expr5, 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_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))])), InSet(m, Interval(zero, subtract(Exp(two, Literal("t", theory = "proveit.physics.quantum.QPE")), one))))))
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\}\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: 95
body: 3
2ExprTuple95
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operands: 7
5Operationoperator: 8
operands: 9
6Literal
7ExprTuple10, 11, 12, 13
8Literal
9ExprTuple95, 14
10ExprTuple15, 16
11ExprTuple17, 18
12ExprTuple19, 20
13ExprTuple21, 22
14Operationoperator: 77
operands: 23
15ExprRangelambda_map: 24
start_index: 96
end_index: 97
16ExprRangelambda_map: 25
start_index: 96
end_index: 98
17ExprRangelambda_map: 26
start_index: 96
end_index: 97
18ExprRangelambda_map: 26
start_index: 85
end_index: 86
19ExprRangelambda_map: 27
start_index: 96
end_index: 97
20ExprRangelambda_map: 28
start_index: 96
end_index: 98
21ExprRangelambda_map: 29
start_index: 96
end_index: 97
22ExprRangelambda_map: 30
start_index: 96
end_index: 98
23ExprTuple31, 32
24Lambdaparameter: 84
body: 33
25Lambdaparameter: 84
body: 34
26Lambdaparameter: 84
body: 35
27Lambdaparameter: 84
body: 36
28Lambdaparameter: 84
body: 37
29Lambdaparameter: 84
body: 38
30Lambdaparameter: 84
body: 40
31Literal
32Operationoperator: 92
operands: 41
33Operationoperator: 69
operands: 42
34Operationoperator: 49
operands: 43
35Operationoperator: 49
operands: 44
36Operationoperator: 45
operands: 46
37Operationoperator: 70
operands: 47
38Operationoperator: 49
operands: 48
39ExprTuple84
40Operationoperator: 49
operands: 50
41ExprTuple51, 52
42NamedExprsstate: 53
43NamedExprselement: 54
targets: 62
44NamedExprselement: 55
targets: 56
45Literal
46NamedExprsbasis: 57
47NamedExprsoperation: 58
48NamedExprselement: 59
targets: 60
49Literal
50NamedExprselement: 61
targets: 62
51Operationoperator: 63
operands: 64
52Operationoperator: 65
operand: 96
53Operationoperator: 67
operand: 80
54Operationoperator: 69
operands: 76
55Operationoperator: 70
operands: 71
56Operationoperator: 77
operands: 72
57Literal
58Literal
59Operationoperator: 75
operands: 73
60Operationoperator: 77
operands: 74
61Operationoperator: 75
operands: 76
62Operationoperator: 77
operands: 78
63Literal
64ExprTuple79, 97
65Literal
66ExprTuple96
67Literal
68ExprTuple80
69Literal
70Literal
71NamedExprsoperation: 81
part: 84
72ExprTuple96, 86
73NamedExprsstate: 82
part: 84
74ExprTuple96, 97
75Literal
76NamedExprsstate: 83
part: 84
77Literal
78ExprTuple85, 86
79Literal
80Literal
81Operationoperator: 87
operands: 88
82Operationoperator: 89
operands: 90
83Literal
84Variable
85Operationoperator: 92
operands: 91
86Operationoperator: 92
operands: 93
87Literal
88ExprTuple94, 97
89Literal
90ExprTuple95, 97
91ExprTuple97, 96
92Literal
93ExprTuple97, 98
94Literal
95Variable
96Literal
97Literal
98Literal