logo

Expression of type Forall

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, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, IntervalCO, Mod, Mult, Real, Round, e, four, frac, greater, i, one, pi, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
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 = Forall(instance_param_or_params = [phase], instance_expr = greater(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_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), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(Mod(Round(Mult(two_pow_t, phase)), two_pow_t), t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)]))), frac(four, Exp(pi, two))), domain = Real, conditions = [InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), var_ket_u))]).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}\forall_{\varphi \in \mathbb{R}~|~\varphi \in \left[0,1\right), \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \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 round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) > \frac{4}{\pi^{2}}\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: 135
body: 5
4ExprTuple135
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple12, 13
10Literal
11ExprTuple14, 15, 16
12Operationoperator: 17
operands: 18
13Operationoperator: 19
operand: 28
14Operationoperator: 22
operands: 21
15Operationoperator: 22
operands: 23
16Operationoperator: 24
operands: 25
17Literal
18ExprTuple26, 27
19Literal
20ExprTuple28
21ExprTuple135, 29
22Literal
23ExprTuple135, 30
24Literal
25ExprTuple31, 32
26Literal
27Operationoperator: 136
operands: 33
28Operationoperator: 34
operands: 35
29Literal
30Operationoperator: 36
operands: 37
31Operationoperator: 38
operands: 39
32Operationoperator: 40
operands: 41
33ExprTuple84, 138
34Literal
35ExprTuple42, 43, 44, 45
36Literal
37ExprTuple46, 124
38Literal
39ExprTuple122, 111
40Literal
41ExprTuple47, 111
42ExprTuple48, 49
43ExprTuple50, 51
44ExprTuple52, 53
45ExprTuple54, 55
46Literal
47Operationoperator: 136
operands: 56
48ExprRangelambda_map: 57
start_index: 124
end_index: 139
49ExprRangelambda_map: 58
start_index: 124
end_index: 125
50ExprRangelambda_map: 59
start_index: 124
end_index: 139
51ExprRangelambda_map: 59
start_index: 113
end_index: 114
52ExprRangelambda_map: 60
start_index: 124
end_index: 139
53ExprRangelambda_map: 61
start_index: 124
end_index: 125
54ExprRangelambda_map: 62
start_index: 124
end_index: 139
55ExprRangelambda_map: 63
start_index: 124
end_index: 125
56ExprTuple64, 65
57Lambdaparameter: 112
body: 66
58Lambdaparameter: 112
body: 67
59Lambdaparameter: 112
body: 68
60Lambdaparameter: 112
body: 69
61Lambdaparameter: 112
body: 70
62Lambdaparameter: 112
body: 71
63Lambdaparameter: 112
body: 73
64Literal
65Operationoperator: 132
operands: 74
66Operationoperator: 98
operands: 75
67Operationoperator: 82
operands: 76
68Operationoperator: 82
operands: 77
69Operationoperator: 78
operands: 79
70Operationoperator: 99
operands: 80
71Operationoperator: 82
operands: 81
72ExprTuple112
73Operationoperator: 82
operands: 83
74ExprTuple138, 84, 85, 135
75NamedExprsstate: 86
76NamedExprselement: 87
targets: 95
77NamedExprselement: 88
targets: 89
78Literal
79NamedExprsbasis: 90
80NamedExprsoperation: 91
81NamedExprselement: 92
targets: 93
82Literal
83NamedExprselement: 94
targets: 95
84Literal
85Literal
86Operationoperator: 96
operand: 108
87Operationoperator: 98
operands: 105
88Operationoperator: 99
operands: 100
89Operationoperator: 106
operands: 101
90Literal
91Literal
92Operationoperator: 104
operands: 102
93Operationoperator: 106
operands: 103
94Operationoperator: 104
operands: 105
95Operationoperator: 106
operands: 107
96Literal
97ExprTuple108
98Literal
99Literal
100NamedExprsoperation: 109
part: 112
101ExprTuple124, 114
102NamedExprsstate: 110
part: 112
103ExprTuple124, 139
104Literal
105NamedExprsstate: 111
part: 112
106Literal
107ExprTuple113, 114
108Literal
109Operationoperator: 115
operands: 116
110Operationoperator: 117
operands: 118
111Variable
112Variable
113Operationoperator: 120
operands: 119
114Operationoperator: 120
operands: 121
115Literal
116ExprTuple122, 139
117Literal
118ExprTuple123, 139
119ExprTuple139, 124
120Literal
121ExprTuple139, 125
122Variable
123Operationoperator: 126
operands: 127
124Literal
125Variable
126Literal
127ExprTuple128, 134
128Operationoperator: 129
operand: 131
129Literal
130ExprTuple131
131Operationoperator: 132
operands: 133
132Literal
133ExprTuple134, 135
134Operationoperator: 136
operands: 137
135Variable
136Literal
137ExprTuple138, 139
138Literal
139Variable