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, VertExprArray, t
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 QPE1, _U, _s
from proveit.physics.quantum.circuits import Gate, Igate, MultiQubitElem, Qcircuit
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)
sub_expr5 = Add(t, _s)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE1(_U, t), part = sub_expr2), targets = Interval(one, sub_expr5))
expr = ExprTuple(Qcircuit(vert_expr_array = VertExprArray(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, sub_expr5)), one, _s)], Add(Neg(t), one), zero).with_decreasing_order())), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr2, sub_expr6, one, t), ExprRange(sub_expr2, sub_expr6, sub_expr3, sub_expr5)])))
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(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qw \\
& \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qw \\
& \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & { /^{s} } \qw
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}_1\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw
} \end{array}\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
operand: 7
3ExprTuple6
4Literal
5ExprTuple7
6ExprRangelambda_map: 8
start_index: 9
end_index: 10
7ExprTuple11, 12
8Lambdaparameter: 82
body: 13
9Operationoperator: 74
operands: 14
10Literal
11ExprRangelambda_map: 15
start_index: 79
end_index: 78
12ExprRangelambda_map: 15
start_index: 71
end_index: 56
13ExprTuple16, 17
14ExprTuple18, 79
15Lambdaparameter: 61
body: 19
16ExprRangelambda_map: 20
start_index: 79
end_index: 78
17ExprRangelambda_map: 21
start_index: 79
end_index: 70
18Operationoperator: 80
operand: 78
19Operationoperator: 48
operands: 23
20Lambdaparameter: 61
body: 24
21Lambdaparameter: 61
body: 26
22ExprTuple78
23NamedExprselement: 27
targets: 28
24Operationoperator: 29
operands: 30
25ExprTuple61
26Operationoperator: 48
operands: 31
27Operationoperator: 51
operands: 32
28Operationoperator: 44
operands: 33
29Literal
30ExprTuple34, 35
31NamedExprselement: 36
targets: 37
32NamedExprsoperation: 38
part: 61
33ExprTuple79, 56
34Conditionalvalue: 39
condition: 40
35Conditionalvalue: 41
condition: 42
36Operationoperator: 51
operands: 43
37Operationoperator: 44
operands: 45
38Operationoperator: 46
operands: 47
39Operationoperator: 48
operands: 49
40Operationoperator: 50
operands: 54
41Operationoperator: 51
operands: 52
42Operationoperator: 53
operands: 54
43NamedExprsoperation: 55
part: 61
44Literal
45ExprTuple71, 56
46Literal
47ExprTuple68, 78
48Literal
49NamedExprselement: 57
targets: 58
50Literal
51Literal
52NamedExprsoperation: 59
53Literal
54ExprTuple60, 61
55Operationoperator: 62
operands: 63
56Operationoperator: 74
operands: 64
57Literal
58Operationoperator: 65
operand: 71
59Literal
60Operationoperator: 74
operands: 67
61Variable
62Literal
63ExprTuple68, 69
64ExprTuple78, 70
65Literal
66ExprTuple71
67ExprTuple82, 78
68Literal
69Operationoperator: 72
operands: 73
70Literal
71Operationoperator: 74
operands: 75
72Literal
73ExprTuple76, 77
74Literal
75ExprTuple78, 79
76Literal
77Operationoperator: 80
operand: 82
78Variable
79Literal
80Literal
81ExprTuple82
82Variable