logo

Expression of type VertExprArray

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, U, Variable, VertExprArray, s, 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, I
from proveit.physics.quantum.circuits import Gate, 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 = VertExprArray(ExprRange(sub_expr1, [ExprRange(sub_expr2, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr4, sub_expr2)), Conditional(Gate(operation = I).with_implicit_representation(), 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().with_case_simplification())
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())
\begin{array}{cccc} 
 \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} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \\
\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} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \\
\vdots & \vdots & \ddots & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \cdots & \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^{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 - 2}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \cdots & \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^{t - 1}}~\mbox{part}~2~\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} & \cdots & \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} \\
\vdots & \vdots & \ddots & \vdots \\
\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} & \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} & \cdots & \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} \\
\end{array}

In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenterwith_justification
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1ExprRangelambda_map: 2
start_index: 3
end_index: 4
2Lambdaparameter: 64
body: 5
3Operationoperator: 56
operands: 6
4Literal
5ExprTuple7, 8
6ExprTuple9, 61
7ExprRangelambda_map: 10
start_index: 61
end_index: 60
8ExprRangelambda_map: 11
start_index: 61
end_index: 52
9Operationoperator: 62
operand: 60
10Lambdaparameter: 43
body: 13
11Lambdaparameter: 43
body: 15
12ExprTuple60
13Operationoperator: 16
operands: 17
14ExprTuple43
15Operationoperator: 30
operands: 18
16Literal
17ExprTuple19, 20
18NamedExprselement: 21
targets: 22
19Conditionalvalue: 23
condition: 24
20Conditionalvalue: 25
condition: 26
21Operationoperator: 33
operands: 27
22Operationoperator: 28
operands: 29
23Operationoperator: 30
operands: 31
24Operationoperator: 32
operands: 36
25Operationoperator: 33
operands: 34
26Operationoperator: 35
operands: 36
27NamedExprsoperation: 37
part: 43
28Literal
29ExprTuple53, 38
30Literal
31NamedExprselement: 39
targets: 40
32Literal
33Literal
34NamedExprsoperation: 41
35Literal
36ExprTuple42, 43
37Operationoperator: 44
operands: 45
38Operationoperator: 56
operands: 46
39Literal
40Operationoperator: 47
operand: 53
41Literal
42Operationoperator: 56
operands: 49
43Variable
44Literal
45ExprTuple50, 51
46ExprTuple60, 52
47Literal
48ExprTuple53
49ExprTuple64, 60
50Variable
51Operationoperator: 54
operands: 55
52Variable
53Operationoperator: 56
operands: 57
54Literal
55ExprTuple58, 59
56Literal
57ExprTuple60, 61
58Literal
59Operationoperator: 62
operand: 64
60Variable
61Literal
62Literal
63ExprTuple64
64Variable