logo

Expression of type ProbOfAll

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, Literal, Variable, VertExprArray, e, m
from proveit.numbers import Add, Exp, Interval, ModAbs, greater, 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
from proveit.statistics import ProbOfAll
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 = ProbOfAll(instance_param_or_params = [m], instance_element = 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"))])), domain = Interval(zero, subtract(sub_expr4, one)), condition = greater(ModAbs(subtract(m, Literal("b_{f}", latex_format = r"b_{\textit{f}}", theory = "proveit.physics.quantum.QPE")), sub_expr4), e)).with_wrapping()
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())
\begin{array}{l}\textrm{Prob}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}~|~\left|m - b_{\textit{f}}\right|_{\textup{mod}\thinspace 2^{t}} > e}~\\
\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}\right)\end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 112
body: 5
4ExprTuple112
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13, 14, 15
10Literal
11ExprTuple16, 17
12ExprTuple18, 19
13ExprTuple20, 21
14ExprTuple22, 23
15ExprTuple24, 25
16Operationoperator: 26
operands: 27
17Operationoperator: 28
operands: 29
18ExprRangelambda_map: 30
start_index: 113
end_index: 114
19ExprRangelambda_map: 31
start_index: 113
end_index: 115
20ExprRangelambda_map: 32
start_index: 113
end_index: 114
21ExprRangelambda_map: 32
start_index: 95
end_index: 96
22ExprRangelambda_map: 33
start_index: 113
end_index: 114
23ExprRangelambda_map: 34
start_index: 113
end_index: 115
24ExprRangelambda_map: 35
start_index: 113
end_index: 114
25ExprRangelambda_map: 36
start_index: 113
end_index: 115
26Literal
27ExprTuple112, 37
28Literal
29ExprTuple38, 39
30Lambdaparameter: 94
body: 40
31Lambdaparameter: 94
body: 41
32Lambdaparameter: 94
body: 42
33Lambdaparameter: 94
body: 43
34Lambdaparameter: 94
body: 44
35Lambdaparameter: 94
body: 45
36Lambdaparameter: 94
body: 47
37Operationoperator: 85
operands: 48
38Variable
39Operationoperator: 49
operands: 50
40Operationoperator: 77
operands: 51
41Operationoperator: 58
operands: 52
42Operationoperator: 58
operands: 53
43Operationoperator: 54
operands: 55
44Operationoperator: 78
operands: 56
45Operationoperator: 58
operands: 57
46ExprTuple94
47Operationoperator: 58
operands: 59
48ExprTuple60, 61
49Literal
50ExprTuple62, 87
51NamedExprsstate: 63
52NamedExprselement: 64
targets: 72
53NamedExprselement: 65
targets: 66
54Literal
55NamedExprsbasis: 67
56NamedExprsoperation: 68
57NamedExprselement: 69
targets: 70
58Literal
59NamedExprselement: 71
targets: 72
60Literal
61Operationoperator: 107
operands: 73
62Operationoperator: 107
operands: 74
63Operationoperator: 75
operand: 90
64Operationoperator: 77
operands: 84
65Operationoperator: 78
operands: 79
66Operationoperator: 85
operands: 80
67Literal
68Literal
69Operationoperator: 83
operands: 81
70Operationoperator: 85
operands: 82
71Operationoperator: 83
operands: 84
72Operationoperator: 85
operands: 86
73ExprTuple87, 88
74ExprTuple112, 89
75Literal
76ExprTuple90
77Literal
78Literal
79NamedExprsoperation: 91
part: 94
80ExprTuple113, 96
81NamedExprsstate: 92
part: 94
82ExprTuple113, 114
83Literal
84NamedExprsstate: 93
part: 94
85Literal
86ExprTuple95, 96
87Operationoperator: 97
operands: 98
88Operationoperator: 100
operand: 113
89Operationoperator: 100
operand: 110
90Literal
91Operationoperator: 102
operands: 103
92Operationoperator: 104
operands: 105
93Literal
94Variable
95Operationoperator: 107
operands: 106
96Operationoperator: 107
operands: 108
97Literal
98ExprTuple109, 114
99ExprTuple113
100Literal
101ExprTuple110
102Literal
103ExprTuple111, 114
104Literal
105ExprTuple112, 114
106ExprTuple114, 113
107Literal
108ExprTuple114, 115
109Literal
110Literal
111Literal
112Variable
113Literal
114Literal
115Literal