logo

Expression of type Equals

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 Conditional, ConditionalSet, ExprRange, Variable, VertExprArray, t
from proveit.linear_algebra import MatrixExp, ScalarMult, VecAdd
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import CONTROL, ket0, ket1, ket_plus
from proveit.physics.quantum.QPE import _U, _ket_u, _phase, _s
from proveit.physics.quantum.circuits import Gate, Igate, Input, 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 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr3 = Add(t, one)
sub_expr4 = Add(sub_expr2, t)
sub_expr5 = Interval(sub_expr3, Add(t, _s))
sub_expr6 = Add(Neg(t), one)
expr = Equals(Prob(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_expr5), one, _s)], ExprRange(sub_expr2, [ExprRange(sub_expr1, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr4, sub_expr1)), Conditional(Igate, NotEquals(sub_expr4, sub_expr1))), one, t).with_case_simplification(), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = MatrixExp(_U, Exp(two, Neg(sub_expr2))), part = sub_expr1), targets = sub_expr5), one, _s)], sub_expr6, zero).with_decreasing_order(), [ExprRange(sub_expr1, Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))), sub_expr6, zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr5), one, _s)]))), one)
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{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 1} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 2} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{0} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & \qout{\lvert u \rangle}
} \end{array}\right) = 1
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 71
operands: 1
1ExprTuple2, 115
2Operationoperator: 3
operand: 5
3Literal
4ExprTuple5
5Operationoperator: 6
operands: 7
6Literal
7ExprTuple8, 9, 10
8ExprTuple11, 12
9ExprRangelambda_map: 13
start_index: 20
end_index: 99
10ExprTuple14, 15
11ExprRangelambda_map: 16
start_index: 115
end_index: 114
12ExprRangelambda_map: 17
start_index: 115
end_index: 97
13Lambdaparameter: 119
body: 18
14ExprRangelambda_map: 19
start_index: 20
end_index: 99
15ExprRangelambda_map: 21
start_index: 115
end_index: 97
16Lambdaparameter: 130
body: 22
17Lambdaparameter: 130
body: 23
18ExprTuple24, 25
19Lambdaparameter: 130
body: 26
20Operationoperator: 109
operands: 27
21Lambdaparameter: 130
body: 28
22Operationoperator: 44
operands: 29
23Operationoperator: 69
operands: 30
24ExprRangelambda_map: 31
start_index: 115
end_index: 114
25ExprRangelambda_map: 32
start_index: 115
end_index: 97
26Operationoperator: 49
operands: 33
27ExprTuple34, 115
28Operationoperator: 69
operands: 35
29NamedExprsstate: 36
30NamedExprselement: 37
targets: 55
31Lambdaparameter: 130
body: 38
32Lambdaparameter: 130
body: 39
33NamedExprsstate: 40
34Operationoperator: 128
operand: 114
35NamedExprselement: 42
targets: 55
36Operationoperator: 107
operand: 51
37Operationoperator: 44
operands: 50
38Operationoperator: 45
operands: 46
39Operationoperator: 69
operands: 47
40Operationoperator: 90
operands: 48
41ExprTuple114
42Operationoperator: 49
operands: 50
43ExprTuple51
44Literal
45Literal
46ExprTuple52, 53
47NamedExprselement: 54
targets: 55
48ExprTuple56, 57
49Literal
50NamedExprsstate: 58
part: 130
51Literal
52Conditionalvalue: 59
condition: 60
53Conditionalvalue: 61
condition: 62
54Operationoperator: 72
operands: 63
55Operationoperator: 64
operands: 65
56Operationoperator: 104
operands: 66
57Operationoperator: 67
operands: 68
58Literal
59Operationoperator: 69
operands: 70
60Operationoperator: 71
operands: 75
61Operationoperator: 72
operands: 73
62Operationoperator: 74
operands: 75
63NamedExprsoperation: 76
part: 130
64Literal
65ExprTuple102, 77
66ExprTuple115, 78
67Literal
68ExprTuple79, 80
69Literal
70NamedExprselement: 81
targets: 82
71Literal
72Literal
73NamedExprsoperation: 83
74Literal
75ExprTuple84, 130
76Operationoperator: 85
operands: 86
77Operationoperator: 109
operands: 87
78Operationoperator: 124
operands: 88
79Operationoperator: 107
operand: 99
80Operationoperator: 90
operands: 91
81Literal
82Operationoperator: 92
operand: 102
83Literal
84Operationoperator: 109
operands: 94
85Literal
86ExprTuple95, 96
87ExprTuple114, 97
88ExprTuple126, 98
89ExprTuple99
90Literal
91ExprTuple100, 101
92Literal
93ExprTuple102
94ExprTuple119, 114
95Literal
96Operationoperator: 124
operands: 103
97Literal
98Operationoperator: 104
operands: 105
99Literal
100Operationoperator: 124
operands: 106
101Operationoperator: 107
operand: 115
102Operationoperator: 109
operands: 110
103ExprTuple126, 111
104Literal
105ExprTuple115, 126
106ExprTuple112, 113
107Literal
108ExprTuple115
109Literal
110ExprTuple114, 115
111Operationoperator: 128
operand: 119
112Literal
113Operationoperator: 117
operands: 118
114Variable
115Literal
116ExprTuple119
117Literal
118ExprTuple126, 120, 121, 122, 123
119Variable
120Literal
121Literal
122Operationoperator: 124
operands: 125
123Literal
124Literal
125ExprTuple126, 127
126Literal
127Operationoperator: 128
operand: 130
128Literal
129ExprTuple130
130Variable