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, Variable, VertExprArray, l
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import ModAdd, QPE, _U, _b_floor, _ket_u, _neg_domain, _s, _s_wire, _t
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(_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 = ProbOfAll(instance_param_or_params = [l], instance_element = 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)])), domain = _neg_domain)
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())
\textrm{Prob}_{l \in \{-2^{t - 1} + 1~\ldotp \ldotp~-\left(e + 1\right)\}}~\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}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('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: 109
body: 5
4ExprTuple109
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13, 14, 15
10Literal
11ExprTuple109, 16
12ExprTuple17, 18
13ExprTuple19, 20
14ExprTuple21, 22
15ExprTuple23, 24
16Operationoperator: 78
operands: 25
17ExprRangelambda_map: 26
start_index: 112
end_index: 106
18ExprRangelambda_map: 27
start_index: 112
end_index: 101
19ExprRangelambda_map: 28
start_index: 112
end_index: 106
20ExprRangelambda_map: 28
start_index: 87
end_index: 88
21ExprRangelambda_map: 29
start_index: 112
end_index: 106
22ExprRangelambda_map: 30
start_index: 112
end_index: 101
23ExprRangelambda_map: 31
start_index: 112
end_index: 106
24ExprRangelambda_map: 32
start_index: 112
end_index: 101
25ExprTuple33, 34
26Lambdaparameter: 86
body: 35
27Lambdaparameter: 86
body: 36
28Lambdaparameter: 86
body: 37
29Lambdaparameter: 86
body: 38
30Lambdaparameter: 86
body: 39
31Lambdaparameter: 86
body: 40
32Lambdaparameter: 86
body: 42
33Operationoperator: 102
operands: 43
34Operationoperator: 110
operand: 55
35Operationoperator: 70
operands: 45
36Operationoperator: 52
operands: 46
37Operationoperator: 52
operands: 47
38Operationoperator: 48
operands: 49
39Operationoperator: 71
operands: 50
40Operationoperator: 52
operands: 51
41ExprTuple86
42Operationoperator: 52
operands: 53
43ExprTuple54, 112
44ExprTuple55
45NamedExprsstate: 56
46NamedExprselement: 57
targets: 65
47NamedExprselement: 58
targets: 59
48Literal
49NamedExprsbasis: 60
50NamedExprsoperation: 61
51NamedExprselement: 62
targets: 63
52Literal
53NamedExprselement: 64
targets: 65
54Operationoperator: 110
operand: 80
55Operationoperator: 102
operands: 67
56Operationoperator: 68
operand: 82
57Operationoperator: 70
operands: 77
58Operationoperator: 71
operands: 72
59Operationoperator: 78
operands: 73
60Literal
61Literal
62Operationoperator: 76
operands: 74
63Operationoperator: 78
operands: 75
64Operationoperator: 76
operands: 77
65Operationoperator: 78
operands: 79
66ExprTuple80
67ExprTuple81, 112
68Literal
69ExprTuple82
70Literal
71Literal
72NamedExprsoperation: 83
part: 86
73ExprTuple112, 88
74NamedExprsstate: 84
part: 86
75ExprTuple112, 106
76Literal
77NamedExprsstate: 85
part: 86
78Literal
79ExprTuple87, 88
80Operationoperator: 89
operands: 90
81Variable
82Literal
83Operationoperator: 91
operands: 92
84Operationoperator: 93
operands: 94
85Literal
86Variable
87Operationoperator: 102
operands: 95
88Operationoperator: 102
operands: 96
89Literal
90ExprTuple97, 98
91Literal
92ExprTuple99, 106
93Literal
94ExprTuple100, 106
95ExprTuple106, 112
96ExprTuple106, 101
97Literal
98Operationoperator: 102
operands: 103
99Literal
100Operationoperator: 104
operands: 105
101Literal
102Literal
103ExprTuple106, 107
104Literal
105ExprTuple108, 109
106Literal
107Operationoperator: 110
operand: 112
108Literal
109Variable
110Literal
111ExprTuple112
112Literal