logo

Expression of type QcircuitEquiv

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 QPE1, _U, _ket_u, _phase, _s
from proveit.physics.quantum.circuits import Gate, Igate, Input, MultiQubitElem, Output, Qcircuit, QcircuitEquiv
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(t, _s)
sub_expr5 = Add(sub_expr2, t)
sub_expr6 = Interval(sub_expr3, sub_expr4)
sub_expr7 = Add(Neg(t), one)
sub_expr8 = MultiQubitElem(element = Gate(operation = QPE1(_U, t), part = sub_expr1), targets = Interval(one, sub_expr4))
sub_expr9 = [ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr6), one, _s)]
sub_expr10 = [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_expr7, zero).with_decreasing_order(), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr6), one, _s)]
expr = QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray(sub_expr9, ExprRange(sub_expr2, [ExprRange(sub_expr1, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr5, sub_expr1)), Conditional(Igate, NotEquals(sub_expr5, 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_expr6), one, _s)], sub_expr7, zero).with_decreasing_order(), sub_expr10)), Qcircuit(vert_expr_array = VertExprArray(sub_expr9, [ExprRange(sub_expr1, sub_expr8, one, t), ExprRange(sub_expr1, sub_expr8, sub_expr3, sub_expr4)], sub_expr10))).with_wrapping_at(1)
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}{c} \begin{array}{l} \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) \\  \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \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} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \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}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \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} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\lvert u \rangle}
} \end{array}\right) \end{array} \end{array}
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.()(1)('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: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 6
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple9, 8, 11
6Literal
7ExprTuple9, 10, 11
8ExprRangelambda_map: 12
start_index: 24
end_index: 112
9ExprTuple13, 14
10ExprTuple15, 16
11ExprTuple17, 18
12Lambdaparameter: 132
body: 19
13ExprRangelambda_map: 20
start_index: 128
end_index: 127
14ExprRangelambda_map: 21
start_index: 128
end_index: 110
15ExprRangelambda_map: 22
start_index: 128
end_index: 127
16ExprRangelambda_map: 22
start_index: 115
end_index: 90
17ExprRangelambda_map: 23
start_index: 24
end_index: 112
18ExprRangelambda_map: 25
start_index: 128
end_index: 110
19ExprTuple26, 27
20Lambdaparameter: 143
body: 28
21Lambdaparameter: 143
body: 29
22Lambdaparameter: 143
body: 30
23Lambdaparameter: 143
body: 31
24Operationoperator: 122
operands: 32
25Lambdaparameter: 143
body: 33
26ExprRangelambda_map: 34
start_index: 128
end_index: 127
27ExprRangelambda_map: 35
start_index: 128
end_index: 110
28Operationoperator: 55
operands: 36
29Operationoperator: 82
operands: 37
30Operationoperator: 82
operands: 38
31Operationoperator: 59
operands: 39
32ExprTuple40, 128
33Operationoperator: 82
operands: 41
34Lambdaparameter: 143
body: 42
35Lambdaparameter: 143
body: 43
36NamedExprsstate: 44
37NamedExprselement: 45
targets: 64
38NamedExprselement: 46
targets: 47
39NamedExprsstate: 48
40Operationoperator: 141
operand: 127
41NamedExprselement: 50
targets: 64
42Operationoperator: 51
operands: 52
43Operationoperator: 82
operands: 53
44Operationoperator: 120
operand: 65
45Operationoperator: 55
operands: 60
46Operationoperator: 85
operands: 56
47Operationoperator: 75
operands: 57
48Operationoperator: 103
operands: 58
49ExprTuple127
50Operationoperator: 59
operands: 60
51Literal
52ExprTuple61, 62
53NamedExprselement: 63
targets: 64
54ExprTuple65
55Literal
56NamedExprsoperation: 66
part: 143
57ExprTuple128, 90
58ExprTuple67, 68
59Literal
60NamedExprsstate: 69
part: 143
61Conditionalvalue: 70
condition: 71
62Conditionalvalue: 72
condition: 73
63Operationoperator: 85
operands: 74
64Operationoperator: 75
operands: 76
65Literal
66Operationoperator: 77
operands: 78
67Operationoperator: 117
operands: 79
68Operationoperator: 80
operands: 81
69Literal
70Operationoperator: 82
operands: 83
71Operationoperator: 84
operands: 88
72Operationoperator: 85
operands: 86
73Operationoperator: 87
operands: 88
74NamedExprsoperation: 89
part: 143
75Literal
76ExprTuple115, 90
77Literal
78ExprTuple108, 127
79ExprTuple128, 91
80Literal
81ExprTuple92, 93
82Literal
83NamedExprselement: 94
targets: 95
84Literal
85Literal
86NamedExprsoperation: 96
87Literal
88ExprTuple97, 143
89Operationoperator: 98
operands: 99
90Operationoperator: 122
operands: 100
91Operationoperator: 137
operands: 101
92Operationoperator: 120
operand: 112
93Operationoperator: 103
operands: 104
94Literal
95Operationoperator: 105
operand: 115
96Literal
97Operationoperator: 122
operands: 107
98Literal
99ExprTuple108, 109
100ExprTuple127, 110
101ExprTuple139, 111
102ExprTuple112
103Literal
104ExprTuple113, 114
105Literal
106ExprTuple115
107ExprTuple132, 127
108Literal
109Operationoperator: 137
operands: 116
110Literal
111Operationoperator: 117
operands: 118
112Literal
113Operationoperator: 137
operands: 119
114Operationoperator: 120
operand: 128
115Operationoperator: 122
operands: 123
116ExprTuple139, 124
117Literal
118ExprTuple128, 139
119ExprTuple125, 126
120Literal
121ExprTuple128
122Literal
123ExprTuple127, 128
124Operationoperator: 141
operand: 132
125Literal
126Operationoperator: 130
operands: 131
127Variable
128Literal
129ExprTuple132
130Literal
131ExprTuple139, 133, 134, 135, 136
132Variable
133Literal
134Literal
135Operationoperator: 137
operands: 138
136Literal
137Literal
138ExprTuple139, 140
139Literal
140Operationoperator: 141
operand: 143
141Literal
142ExprTuple143
143Variable