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, Mult, Real, e, i, one, pi, subtract, 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 = Mult(two_pow_t, phase)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Forall(instance_param_or_params = [phase], instance_expr = Equals(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_expr6, one, t), ExprRange(sub_expr1, sub_expr6, 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(sub_expr5, 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)]))), one), domain = Real, conditions = [InSet(sub_expr5, Interval(zero, subtract(two_pow_t, 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}~|~\left(2^{t} \cdot \varphi\right) \in \{0~\ldotp \ldotp~2^{t} - 1\}, \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = 1\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: 126
body: 5
4ExprTuple126
5Conditionalvalue: 6
condition: 7
6Operationoperator: 20
operands: 8
7Operationoperator: 9
operands: 10
8ExprTuple11, 121
9Literal
10ExprTuple12, 13, 14
11Operationoperator: 15
operand: 22
12Operationoperator: 18
operands: 17
13Operationoperator: 18
operands: 19
14Operationoperator: 20
operands: 21
15Literal
16ExprTuple22
17ExprTuple126, 23
18Literal
19ExprTuple120, 24
20Literal
21ExprTuple25, 26
22Operationoperator: 27
operands: 28
23Literal
24Operationoperator: 103
operands: 29
25Operationoperator: 30
operands: 31
26Operationoperator: 32
operands: 33
27Literal
28ExprTuple34, 35, 36, 37
29ExprTuple38, 39
30Literal
31ExprTuple119, 108
32Literal
33ExprTuple40, 108
34ExprTuple41, 42
35ExprTuple43, 44
36ExprTuple45, 46
37ExprTuple47, 48
38Literal
39Operationoperator: 117
operands: 49
40Operationoperator: 127
operands: 50
41ExprRangelambda_map: 51
start_index: 121
end_index: 130
42ExprRangelambda_map: 52
start_index: 121
end_index: 122
43ExprRangelambda_map: 53
start_index: 121
end_index: 130
44ExprRangelambda_map: 53
start_index: 110
end_index: 111
45ExprRangelambda_map: 54
start_index: 121
end_index: 130
46ExprRangelambda_map: 55
start_index: 121
end_index: 122
47ExprRangelambda_map: 56
start_index: 121
end_index: 130
48ExprRangelambda_map: 57
start_index: 121
end_index: 122
49ExprTuple125, 58
50ExprTuple59, 60
51Lambdaparameter: 109
body: 61
52Lambdaparameter: 109
body: 62
53Lambdaparameter: 109
body: 63
54Lambdaparameter: 109
body: 64
55Lambdaparameter: 109
body: 65
56Lambdaparameter: 109
body: 66
57Lambdaparameter: 109
body: 68
58Operationoperator: 69
operand: 121
59Literal
60Operationoperator: 123
operands: 71
61Operationoperator: 95
operands: 72
62Operationoperator: 79
operands: 73
63Operationoperator: 79
operands: 74
64Operationoperator: 75
operands: 76
65Operationoperator: 96
operands: 77
66Operationoperator: 79
operands: 78
67ExprTuple109
68Operationoperator: 79
operands: 80
69Literal
70ExprTuple121
71ExprTuple129, 81, 82, 126
72NamedExprsstate: 83
73NamedExprselement: 84
targets: 92
74NamedExprselement: 85
targets: 86
75Literal
76NamedExprsbasis: 87
77NamedExprsoperation: 88
78NamedExprselement: 89
targets: 90
79Literal
80NamedExprselement: 91
targets: 92
81Literal
82Literal
83Operationoperator: 93
operand: 105
84Operationoperator: 95
operands: 102
85Operationoperator: 96
operands: 97
86Operationoperator: 103
operands: 98
87Literal
88Literal
89Operationoperator: 101
operands: 99
90Operationoperator: 103
operands: 100
91Operationoperator: 101
operands: 102
92Operationoperator: 103
operands: 104
93Literal
94ExprTuple105
95Literal
96Literal
97NamedExprsoperation: 106
part: 109
98ExprTuple121, 111
99NamedExprsstate: 107
part: 109
100ExprTuple121, 130
101Literal
102NamedExprsstate: 108
part: 109
103Literal
104ExprTuple110, 111
105Literal
106Operationoperator: 112
operands: 113
107Operationoperator: 114
operands: 115
108Variable
109Variable
110Operationoperator: 117
operands: 116
111Operationoperator: 117
operands: 118
112Literal
113ExprTuple119, 130
114Literal
115ExprTuple120, 130
116ExprTuple130, 121
117Literal
118ExprTuple130, 122
119Variable
120Operationoperator: 123
operands: 124
121Literal
122Variable
123Literal
124ExprTuple125, 126
125Operationoperator: 127
operands: 128
126Variable
127Literal
128ExprTuple129, 130
129Literal
130Variable