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, _pos_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 = _pos_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 \{e + 1~\ldotp \ldotp~2^{t - 1}\}}~\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: 106
body: 5
4ExprTuple106
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13, 14, 15
10Literal
11ExprTuple106, 16
12ExprTuple17, 18
13ExprTuple19, 20
14ExprTuple21, 22
15ExprTuple23, 24
16Operationoperator: 79
operands: 25
17ExprRangelambda_map: 26
start_index: 100
end_index: 101
18ExprRangelambda_map: 27
start_index: 100
end_index: 102
19ExprRangelambda_map: 28
start_index: 100
end_index: 101
20ExprRangelambda_map: 28
start_index: 87
end_index: 88
21ExprRangelambda_map: 29
start_index: 100
end_index: 101
22ExprRangelambda_map: 30
start_index: 100
end_index: 102
23ExprRangelambda_map: 31
start_index: 100
end_index: 101
24ExprRangelambda_map: 32
start_index: 100
end_index: 102
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: 96
operands: 43
34Operationoperator: 44
operands: 45
35Operationoperator: 71
operands: 46
36Operationoperator: 53
operands: 47
37Operationoperator: 53
operands: 48
38Operationoperator: 49
operands: 50
39Operationoperator: 72
operands: 51
40Operationoperator: 53
operands: 52
41ExprTuple86
42Operationoperator: 53
operands: 54
43ExprTuple55, 100
44Literal
45ExprTuple56, 57
46NamedExprsstate: 58
47NamedExprselement: 59
targets: 67
48NamedExprselement: 60
targets: 61
49Literal
50NamedExprsbasis: 62
51NamedExprsoperation: 63
52NamedExprselement: 64
targets: 65
53Literal
54NamedExprselement: 66
targets: 67
55Variable
56Literal
57Operationoperator: 96
operands: 68
58Operationoperator: 69
operand: 82
59Operationoperator: 71
operands: 78
60Operationoperator: 72
operands: 73
61Operationoperator: 79
operands: 74
62Literal
63Literal
64Operationoperator: 77
operands: 75
65Operationoperator: 79
operands: 76
66Operationoperator: 77
operands: 78
67Operationoperator: 79
operands: 80
68ExprTuple101, 81
69Literal
70ExprTuple82
71Literal
72Literal
73NamedExprsoperation: 83
part: 86
74ExprTuple100, 88
75NamedExprsstate: 84
part: 86
76ExprTuple100, 101
77Literal
78NamedExprsstate: 85
part: 86
79Literal
80ExprTuple87, 88
81Operationoperator: 89
operand: 100
82Literal
83Operationoperator: 91
operands: 92
84Operationoperator: 93
operands: 94
85Literal
86Variable
87Operationoperator: 96
operands: 95
88Operationoperator: 96
operands: 97
89Literal
90ExprTuple100
91Literal
92ExprTuple98, 101
93Literal
94ExprTuple99, 101
95ExprTuple101, 100
96Literal
97ExprTuple101, 102
98Literal
99Operationoperator: 103
operands: 104
100Literal
101Literal
102Literal
103Literal
104ExprTuple105, 106
105Literal
106Variable