logo

Expression of type Conditional

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, 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 = 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\{\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..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8, 9, 10
5Literal
6ExprTuple92, 11
7ExprTuple12, 13
8ExprTuple14, 15
9ExprTuple16, 17
10ExprTuple18, 19
11Operationoperator: 74
operands: 20
12ExprRangelambda_map: 21
start_index: 93
end_index: 94
13ExprRangelambda_map: 22
start_index: 93
end_index: 95
14ExprRangelambda_map: 23
start_index: 93
end_index: 94
15ExprRangelambda_map: 23
start_index: 82
end_index: 83
16ExprRangelambda_map: 24
start_index: 93
end_index: 94
17ExprRangelambda_map: 25
start_index: 93
end_index: 95
18ExprRangelambda_map: 26
start_index: 93
end_index: 94
19ExprRangelambda_map: 27
start_index: 93
end_index: 95
20ExprTuple28, 29
21Lambdaparameter: 81
body: 30
22Lambdaparameter: 81
body: 31
23Lambdaparameter: 81
body: 32
24Lambdaparameter: 81
body: 33
25Lambdaparameter: 81
body: 34
26Lambdaparameter: 81
body: 35
27Lambdaparameter: 81
body: 37
28Literal
29Operationoperator: 89
operands: 38
30Operationoperator: 66
operands: 39
31Operationoperator: 46
operands: 40
32Operationoperator: 46
operands: 41
33Operationoperator: 42
operands: 43
34Operationoperator: 67
operands: 44
35Operationoperator: 46
operands: 45
36ExprTuple81
37Operationoperator: 46
operands: 47
38ExprTuple48, 49
39NamedExprsstate: 50
40NamedExprselement: 51
targets: 59
41NamedExprselement: 52
targets: 53
42Literal
43NamedExprsbasis: 54
44NamedExprsoperation: 55
45NamedExprselement: 56
targets: 57
46Literal
47NamedExprselement: 58
targets: 59
48Operationoperator: 60
operands: 61
49Operationoperator: 62
operand: 93
50Operationoperator: 64
operand: 77
51Operationoperator: 66
operands: 73
52Operationoperator: 67
operands: 68
53Operationoperator: 74
operands: 69
54Literal
55Literal
56Operationoperator: 72
operands: 70
57Operationoperator: 74
operands: 71
58Operationoperator: 72
operands: 73
59Operationoperator: 74
operands: 75
60Literal
61ExprTuple76, 94
62Literal
63ExprTuple93
64Literal
65ExprTuple77
66Literal
67Literal
68NamedExprsoperation: 78
part: 81
69ExprTuple93, 83
70NamedExprsstate: 79
part: 81
71ExprTuple93, 94
72Literal
73NamedExprsstate: 80
part: 81
74Literal
75ExprTuple82, 83
76Literal
77Literal
78Operationoperator: 84
operands: 85
79Operationoperator: 86
operands: 87
80Literal
81Variable
82Operationoperator: 89
operands: 88
83Operationoperator: 89
operands: 90
84Literal
85ExprTuple91, 94
86Literal
87ExprTuple92, 94
88ExprTuple94, 93
89Literal
90ExprTuple94, 95
91Literal
92Variable
93Literal
94Literal
95Literal