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, t
from proveit.core_expr_types import Len
from proveit.linear_algebra import MatrixExp
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Exp, Interval, Neg, one, two, zero
from proveit.physics.quantum import CONTROL
from proveit.physics.quantum.QPE import _U, _s
from proveit.physics.quantum.circuits import Gate, Igate, MultiQubitElem
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr2 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr3 = Add(t, one)
sub_expr4 = Add(sub_expr1, t)
expr = Equals(Len(operands = [ExprRange(sub_expr1, [ExprRange(sub_expr2, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr4, sub_expr2)), Conditional(Igate, NotEquals(sub_expr4, sub_expr2))), one, t).with_case_simplification(), ExprRange(sub_expr2, MultiQubitElem(element = Gate(operation = MatrixExp(_U, Exp(two, Neg(sub_expr1))), part = sub_expr2), targets = Interval(sub_expr3, Add(t, _s))), one, _s)], Add(Neg(t), one), zero).with_decreasing_order()]), Len(operands = [ExprRange(sub_expr2, sub_expr2, one, t)]))
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())
|\left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{t - 1}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{t - 1}}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{t - 1}}~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}\right), \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{t - 2}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{t - 2}}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{t - 2}}~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}\right), \ldots, \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{0}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{0}}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{0}}~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}\right)\right)| = |\left(1, 2, \ldots, t\right)|
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: 40
operands: 1
1ExprTuple2, 3
2Operationoperator: 5
operands: 4
3Operationoperator: 5
operands: 6
4ExprTuple7
5Literal
6ExprTuple8
7ExprRangelambda_map: 9
start_index: 10
end_index: 11
8ExprRangelambda_map: 12
start_index: 69
end_index: 68
9Lambdaparameter: 72
body: 13
10Operationoperator: 64
operands: 14
11Literal
12Lambdaparameter: 51
body: 51
13ExprTuple15, 16
14ExprTuple17, 69
15ExprRangelambda_map: 18
start_index: 69
end_index: 68
16ExprRangelambda_map: 19
start_index: 69
end_index: 60
17Operationoperator: 70
operand: 68
18Lambdaparameter: 51
body: 21
19Lambdaparameter: 51
body: 23
20ExprTuple68
21Operationoperator: 24
operands: 25
22ExprTuple51
23Operationoperator: 38
operands: 26
24Literal
25ExprTuple27, 28
26NamedExprselement: 29
targets: 30
27Conditionalvalue: 31
condition: 32
28Conditionalvalue: 33
condition: 34
29Operationoperator: 41
operands: 35
30Operationoperator: 36
operands: 37
31Operationoperator: 38
operands: 39
32Operationoperator: 40
operands: 44
33Operationoperator: 41
operands: 42
34Operationoperator: 43
operands: 44
35NamedExprsoperation: 45
part: 51
36Literal
37ExprTuple61, 46
38Literal
39NamedExprselement: 47
targets: 48
40Literal
41Literal
42NamedExprsoperation: 49
43Literal
44ExprTuple50, 51
45Operationoperator: 52
operands: 53
46Operationoperator: 64
operands: 54
47Literal
48Operationoperator: 55
operand: 61
49Literal
50Operationoperator: 64
operands: 57
51Variable
52Literal
53ExprTuple58, 59
54ExprTuple68, 60
55Literal
56ExprTuple61
57ExprTuple72, 68
58Literal
59Operationoperator: 62
operands: 63
60Literal
61Operationoperator: 64
operands: 65
62Literal
63ExprTuple66, 67
64Literal
65ExprTuple68, 69
66Literal
67Operationoperator: 70
operand: 72
68Variable
69Literal
70Literal
71ExprTuple72
72Variable