logo

Expression of type ExprTuple

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, ExprTuple, 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 = ExprTuple(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(\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)|\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 4
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple7
6ExprRangelambda_map: 8
start_index: 9
end_index: 10
7ExprRangelambda_map: 11
start_index: 68
end_index: 67
8Lambdaparameter: 71
body: 12
9Operationoperator: 63
operands: 13
10Literal
11Lambdaparameter: 50
body: 50
12ExprTuple14, 15
13ExprTuple16, 68
14ExprRangelambda_map: 17
start_index: 68
end_index: 67
15ExprRangelambda_map: 18
start_index: 68
end_index: 59
16Operationoperator: 69
operand: 67
17Lambdaparameter: 50
body: 20
18Lambdaparameter: 50
body: 22
19ExprTuple67
20Operationoperator: 23
operands: 24
21ExprTuple50
22Operationoperator: 37
operands: 25
23Literal
24ExprTuple26, 27
25NamedExprselement: 28
targets: 29
26Conditionalvalue: 30
condition: 31
27Conditionalvalue: 32
condition: 33
28Operationoperator: 40
operands: 34
29Operationoperator: 35
operands: 36
30Operationoperator: 37
operands: 38
31Operationoperator: 39
operands: 43
32Operationoperator: 40
operands: 41
33Operationoperator: 42
operands: 43
34NamedExprsoperation: 44
part: 50
35Literal
36ExprTuple60, 45
37Literal
38NamedExprselement: 46
targets: 47
39Literal
40Literal
41NamedExprsoperation: 48
42Literal
43ExprTuple49, 50
44Operationoperator: 51
operands: 52
45Operationoperator: 63
operands: 53
46Literal
47Operationoperator: 54
operand: 60
48Literal
49Operationoperator: 63
operands: 56
50Variable
51Literal
52ExprTuple57, 58
53ExprTuple67, 59
54Literal
55ExprTuple60
56ExprTuple71, 67
57Literal
58Operationoperator: 61
operands: 62
59Literal
60Operationoperator: 63
operands: 64
61Literal
62ExprTuple65, 66
63Literal
64ExprTuple67, 68
65Literal
66Operationoperator: 69
operand: 71
67Variable
68Literal
69Literal
70ExprTuple71
71Variable