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)]), Variable("_c", latex_format = r"{_{-}c}"))
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^{-\left(-t + 1\right)}}~\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^{-\left(-t + 1\right)}}~\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^{-\left(-t + 1\right)}}~\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^{-\left(-t + 2\right)}}~\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^{-\left(-t + 2\right)}}~\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^{-\left(-t + 2\right)}}~\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)| = {_{-}c}
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: 37
operands: 1
1ExprTuple2, 3
2Operationoperator: 4
operands: 5
3Variable
4Literal
5ExprTuple6
6ExprRangelambda_map: 7
start_index: 8
end_index: 9
7Lambdaparameter: 69
body: 10
8Operationoperator: 61
operands: 11
9Literal
10ExprTuple12, 13
11ExprTuple14, 66
12ExprRangelambda_map: 15
start_index: 66
end_index: 65
13ExprRangelambda_map: 16
start_index: 66
end_index: 57
14Operationoperator: 67
operand: 65
15Lambdaparameter: 48
body: 18
16Lambdaparameter: 48
body: 20
17ExprTuple65
18Operationoperator: 21
operands: 22
19ExprTuple48
20Operationoperator: 35
operands: 23
21Literal
22ExprTuple24, 25
23NamedExprselement: 26
targets: 27
24Conditionalvalue: 28
condition: 29
25Conditionalvalue: 30
condition: 31
26Operationoperator: 38
operands: 32
27Operationoperator: 33
operands: 34
28Operationoperator: 35
operands: 36
29Operationoperator: 37
operands: 41
30Operationoperator: 38
operands: 39
31Operationoperator: 40
operands: 41
32NamedExprsoperation: 42
part: 48
33Literal
34ExprTuple58, 43
35Literal
36NamedExprselement: 44
targets: 45
37Literal
38Literal
39NamedExprsoperation: 46
40Literal
41ExprTuple47, 48
42Operationoperator: 49
operands: 50
43Operationoperator: 61
operands: 51
44Literal
45Operationoperator: 52
operand: 58
46Literal
47Operationoperator: 61
operands: 54
48Variable
49Literal
50ExprTuple55, 56
51ExprTuple65, 57
52Literal
53ExprTuple58
54ExprTuple69, 65
55Literal
56Operationoperator: 59
operands: 60
57Literal
58Operationoperator: 61
operands: 62
59Literal
60ExprTuple63, 64
61Literal
62ExprTuple65, 66
63Literal
64Operationoperator: 67
operand: 69
65Variable
66Literal
67Literal
68ExprTuple69
69Variable