@Deprecated public class NormalExpression extends java.lang.Object implements java.lang.Comparable, java.util.Comparator<NormalExpression>
Like its predecessor Polaris, a key feature of Cetus is the ability to reason about the represented program in symbolic terms. For example, compiler analyses and optimizations at the source level often require the expressions in the program to be in a simplified form. A specific example is data dependence analysis that collects the coefficients of affine subscript expressions, which are passed to the underlying data dependence test package. Cetus has functionalities that ease the manipulation of expressions for pass writers. The following example shows how to invoke the simplifier. The simplifier returns a new copy of the original expression that was converted to a normalized form.
Expression e = ... e = NormalExpression.simplify(e);It is also possible for users to invoke individual simplification technique for their own purposes. The following examples show the functionality of the individual simplification technique. See the javadoc page or the source code to learn how to invoke each technique individually.
1+2*a+4-a --> 5+a (folding) a*(b+c) --> a*b+a*c (distribution) (a*2)/(8*c) --> a/(4*c) (division)
Modifier and Type | Method and Description |
---|---|
static Expression |
add(Expression e1,
Expression e2)
Deprecated.
Returns addition of the two expressions with simplification.
|
static Expression |
and(Expression e1,
Expression e2)
Deprecated.
Returns a binary expression e1&&e2 with simplification.
|
static Expression |
binary(Expression e1,
java.lang.String op,
Expression e2)
Deprecated.
|
static int |
compare(Expression e1,
Expression e2)
Deprecated.
Compares the two expressions based on their normal forms.
|
int |
compare(NormalExpression re1,
NormalExpression re2)
Deprecated.
Compares tow normal expressions;
Comparator requires this method. |
int |
compareTo(java.lang.Object o)
Deprecated.
Compares this normal expression to the specified object.
|
static Expression |
divide(Expression e1,
Expression e2)
Deprecated.
Returns division of two expressions with simplification.
|
static Expression |
eq(Expression e1,
Expression e2)
Deprecated.
Returns an equality expression e1==e2 with simplification.
|
boolean |
equals(java.lang.Object o)
Deprecated.
Checks if this normal expression is equal to the specified object.
|
static Expression |
getClosedFormSum(Expression lb,
Expression ub,
Expression e,
Identifier id)
Deprecated.
Returns the closed form of the given summation parameters,
sum(e) s.t.
|
static Expression |
getCoefficient(Expression e,
Identifier id)
Deprecated.
Returns the symbolic coefficient of the given identifier in the
expression.
|
static java.util.List<Expression> |
getCoefficient(Expression e,
java.util.List<Identifier> id_list)
Deprecated.
Returns the list of coefficient with respect to the given set of
identifiers.
|
static long |
getConstantCoefficient(Expression e)
Deprecated.
Returns the constant term in the simplified expression.
|
static Expression |
getConstantCoefficient(Expression e,
java.util.List<Identifier> id_list)
Deprecated.
Returns the constant term with respect to the given set of variables.
|
static java.util.List<Expression> |
getPolynomialCoef(Expression e,
Identifier id)
Deprecated.
Returns a list of expressions which contains coefficients of n-th terms
when the given id is the basis.
|
static java.util.List<Identifier> |
getVariableList(Expression e)
Deprecated.
Returns the list of variables if the given expression is affine.
|
static boolean |
isAffine(Expression e,
java.util.List<Identifier> id_list)
Deprecated.
Checks if the given expression is an affine expression with respect to the
given set of identifiers.
|
static Expression |
multiply(Expression e1,
Expression e2)
Deprecated.
Returns multiplication of two expressions with simplification.
|
static Expression |
negate(Expression e)
Deprecated.
Returns a logically negated expression of the given expression.
|
static Expression |
or(Expression e1,
Expression e2)
Deprecated.
Returns a binary expression e1||e2 with simplification.
|
static Expression |
power(Expression e,
int p)
Deprecated.
Returns the given expression's p-th power.
|
static void |
runtest(Program prog)
Deprecated.
|
static Expression |
simplify(Expression e)
Deprecated.
Returns a normalized(simplified) expression of an
Expression . |
static Expression |
simplify(Expression e,
java.lang.String opt)
Deprecated.
Returns a normalized expression of an
Expression after applying
a specific option. |
static Expression |
subtract(Expression e1,
Expression e2)
Deprecated.
Returns subtraction of two expressions with simplification.
|
java.lang.String |
toString()
Deprecated.
Returns the string format of the normal expression (for debugging).
|
public static Expression simplify(Expression e)
Expression
.
It is important to notice that this method returns a normalized form and
this transformation may or may not result in reduced complexity in the
expression. Normalized expressions can be useful in analysis passes
by imposing a certain orders in the expression. Pass writers may be able
to customize the normalization process with
simplify(Expression,String)
.e
- the Expression
object to be normalized.simplify(Expression, String)
public static Expression simplify(Expression e, java.lang.String opt)
Expression
after applying
a specific option. These options include:
e
- the Expression
object to be normalized.opt
- the normalization option.public static int compare(Expression e1, Expression e2)
e1
- the first expression.e2
- the second expression.public static Expression binary(Expression e1, java.lang.String op, Expression e2)
public static Expression add(Expression e1, Expression e2)
e1
- the first operand of addition.e2
- the second operand of addition.public static Expression subtract(Expression e1, Expression e2)
e1
- the first operand of subtraction.e2
- the second operand of subtraction.public static Expression multiply(Expression e1, Expression e2)
e1
- the first operand of multiplication.e2
- the second operand of multiplication.public static Expression divide(Expression e1, Expression e2)
e1
- the first operand of division.e2
- the second operand of division.public static Expression power(Expression e, int p)
public static Expression negate(Expression e)
e
- the input expression.public static Expression eq(Expression e1, Expression e2)
e1
- the first expression.e2
- the second expression.public static Expression and(Expression e1, Expression e2)
e1
- the first expression.e2
- the second expression.public static Expression or(Expression e1, Expression e2)
e1
- the first expressione2
- the second expressionpublic java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
o
- the object compared to.public boolean equals(java.lang.Object o)
equals
in interface java.util.Comparator<NormalExpression>
equals
in class java.lang.Object
o
- the object compared to.public int compare(NormalExpression re1, NormalExpression re2)
Comparator
requires this method.compare
in interface java.util.Comparator<NormalExpression>
re1
- the first normal expression.re2
- the second normal expression.public static long getConstantCoefficient(Expression e)
e
- the expression to be examined.public static Expression getConstantCoefficient(Expression e, java.util.List<Identifier> id_list)
e
- the expression to be examined.id_list
- the list of variables (identifiers).public static Expression getCoefficient(Expression e, Identifier id)
e
- the expression to be examined.id
- the identifier.public static java.util.List<Expression> getCoefficient(Expression e, java.util.List<Identifier> id_list)
e
- the expression to be examined.id_list
- the list of identifiers.public static java.util.List<Identifier> getVariableList(Expression e)
e
- the expression to be examined.public static boolean isAffine(Expression e, java.util.List<Identifier> id_list)
e
- the expression to be examined.id_list
- the list of identifiers.public static Expression getClosedFormSum(Expression lb, Expression ub, Expression e, Identifier id)
public static java.util.List<Expression> getPolynomialCoef(Expression e, Identifier id)
e
- the input expression.id
- the basis variable.public static void runtest(Program prog)