logo

Expression of type Len

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 = 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()])
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)|
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',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3
3ExprRangelambda_map: 4
start_index: 5
end_index: 6
4Lambdaparameter: 66
body: 7
5Operationoperator: 58
operands: 8
6Literal
7ExprTuple9, 10
8ExprTuple11, 63
9ExprRangelambda_map: 12
start_index: 63
end_index: 62
10ExprRangelambda_map: 13
start_index: 63
end_index: 54
11Operationoperator: 64
operand: 62
12Lambdaparameter: 45
body: 15
13Lambdaparameter: 45
body: 17
14ExprTuple62
15Operationoperator: 18
operands: 19
16ExprTuple45
17Operationoperator: 32
operands: 20
18Literal
19ExprTuple21, 22
20NamedExprselement: 23
targets: 24
21Conditionalvalue: 25
condition: 26
22Conditionalvalue: 27
condition: 28
23Operationoperator: 35
operands: 29
24Operationoperator: 30
operands: 31
25Operationoperator: 32
operands: 33
26Operationoperator: 34
operands: 38
27Operationoperator: 35
operands: 36
28Operationoperator: 37
operands: 38
29NamedExprsoperation: 39
part: 45
30Literal
31ExprTuple55, 40
32Literal
33NamedExprselement: 41
targets: 42
34Literal
35Literal
36NamedExprsoperation: 43
37Literal
38ExprTuple44, 45
39Operationoperator: 46
operands: 47
40Operationoperator: 58
operands: 48
41Literal
42Operationoperator: 49
operand: 55
43Literal
44Operationoperator: 58
operands: 51
45Variable
46Literal
47ExprTuple52, 53
48ExprTuple62, 54
49Literal
50ExprTuple55
51ExprTuple66, 62
52Literal
53Operationoperator: 56
operands: 57
54Literal
55Operationoperator: 58
operands: 59
56Literal
57ExprTuple60, 61
58Literal
59ExprTuple62, 63
60Literal
61Operationoperator: 64
operand: 66
62Variable
63Literal
64Literal
65ExprTuple66
66Variable