cetus.hir
Class Symbolic

java.lang.Object
  extended by cetus.hir.SimpleExpression
      extended by cetus.hir.Symbolic
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<SimpleExpression>, java.util.Comparator<SimpleExpression>

public class Symbolic
extends SimpleExpression

Class Symbolic provides static utility methods that simplifies expressions symbolically. This class holds only wrapper methods that utilizes the normalization functionalities in SimpleExpression.


Field Summary
 
Fields inherited from class cetus.hir.SimpleExpression
ADD, AND, BAND, BCMP, BOR, BXOR, DISTRIBUTE, DIV, DIVIDE, EQ, FACTORIZE, FOLD, GE, GT, ID, LE, LEAF, LIT, LOGIC, LT, MAX, MIN, MOD, MUL, NE, NEG, OR, SFTL, SFTR, sone, szero, TREE, verbosity
 
Method Summary
static Expression add(Expression e1, Expression e2)
          Returns addition of the two expressions with simplification.
static Expression addAll(java.util.List<Expression> exprs)
          Returns an expression that adds all expressions in the given expression list.
static Expression and(Expression e1, Expression e2)
          Returns and of two expressions with simplification.
static Expression decrement(Expression e)
          Returns the given expression decremented by one.
static Expression divide(Expression e1, Expression e2)
          Returns division of two expressions with simplification.
static Expression eq(Expression e1, Expression e2)
          Returns comparison(==) of two expressions with simplification.
static Expression ge(Expression e1, Expression e2)
          Returns comparison(>=) of two expressions with simplification.
static Expression getClosedFormSum(Identifier id, Expression lb, Expression ub, Expression e)
          Returns the closed form of the given summation parameters, sum(e) s.t.
static Expression getClosedFormSum(Identifier id, Expression lb, Expression ub, Expression e, java.lang.Boolean divisible)
          Computes and returns the closed form expression of the given expression, index, and bounds with the divisibility property of the given expression.
static Expression getCoefficient(Expression e, Identifier id)
          Returns the symbolic coefficient of the given identifier in the expression.
static java.util.List<Expression> getCoefficient(Expression e, java.util.List<Identifier> ids)
          Returns the list of coefficient with respect to the given set of identifiers.
static long getConstantCoefficient(Expression e)
          Returns the constant term in the simplified expression.
static Expression getConstantCoefficient(Expression e, java.util.List<Identifier> ids)
          Returns the constant term with respect to the given set of variables.
static java.util.List<Expression> getDenominators(Expression e)
          Returns a list of denominators if the expression contains divisions.
static java.util.List<Expression> getFactors(Expression e)
           
static Expression getLeastCommonDenominator(Expression e)
           
static java.util.List<Expression> getPolynomialCoef(Expression e, Identifier id)
          Returns a list of expressions which contains coefficients of n-th terms when the given id is the basis.
static java.util.List<Expression> getTerms(Expression e)
          Returns a list of terms for expressions with addition.
static java.util.List<Identifier> getVariables(Expression e)
          Returns the list of variables if the given expression is affine.
static java.util.List<java.lang.Object> getVariablesOnLHS(Expression e)
          Returns a list of comparison expressions equivalent to the given expression.
static Expression gt(Expression e1, Expression e2)
          Returns comparison(>) of two expressions with simplification.
static Expression increment(Expression e)
          Returns the given expression incremented by one.
static boolean isAffine(Expression e, java.util.List<Identifier> ids)
          Checks if the given expression is an affine expression with respect to the given list of identifiers.
static Expression le(Expression e1, Expression e2)
          Returns comparison(<=) of two expressions with simplification.
static Expression lt(Expression e1, Expression e2)
          Returns comparison(<) of two expressions with simplification.
static Expression mod(Expression e1, Expression e2)
          Returns modulus of two expressions with simplification.
static Expression multiply(Expression e1, Expression e2)
          Returns multiplication of two expressions with simplification.
static Expression multiplyAll(java.util.List<Expression> exprs)
          Returns an expression that multiplies all expressions in the given expression list.
static Expression multiplyByLCM(Expression e)
          Returns an expression multiplied by LCM of the denominators present in the terms in the specified expression.
static Expression ne(Expression e1, Expression e2)
          Returns comparison(!=) of two expressions with simplification.
static Expression negate(Expression e)
          Returns negation of the given expression.
static Expression or(Expression e1, Expression e2)
          Returns or of two expressions with simplification.
static Expression power(Expression e, int order)
          Returns
static Expression simplify(Expression e)
          Returns a simplified expression of the given expression with the default option which turns on every suboptions.
static Expression simplify(Expression e, int opt)
          Returns a simplified expression of the given expression with the user-specified option.
static Expression simplifyDivisible(Expression e)
          Returns a simplified expression assuming the given expression is divisible.
static Expression subtract(Expression e1, Expression e2)
          Returns subtraction of two expressions with simplification.
 
Methods inherited from class cetus.hir.SimpleExpression
add, add, addAll, addAll, clone, compare, compareTo, containsChildOfType, divide, equals, exchangeOp, getCetusOP, getChild, getChildren, getCoef, getDouble, getExpression, getExprRef, getInt, getLCD, getLCM, getOP, getOption, getOrder, getTerm, getValue, isCommAssoc, isCompare, mod, multiply, multiplyByLCM, negateOp, normalize, normalizeDivisible, setChild, setOption, sort, subtract, toDivision, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

simplify

public static Expression simplify(Expression e)
Returns a simplified expression of the given expression with the default option which turns on every suboptions.

Parameters:
e - the given expression.
Returns:
the simplified expression.

simplify

public static Expression simplify(Expression e,
                                  int opt)
Returns a simplified expression of the given expression with the user-specified option.

Parameters:
e - the given expression.
opt - the composable simplification option. e.g., Symbolic.FOLD, Symbolic.FOLD+Symbolic.FACTORIZE, ...
Returns:
the simplified expression.

add

public static Expression add(Expression e1,
                             Expression e2)
Returns addition of the two expressions with simplification.


subtract

public static Expression subtract(Expression e1,
                                  Expression e2)
Returns subtraction of two expressions with simplification.


multiply

public static Expression multiply(Expression e1,
                                  Expression e2)
Returns multiplication of two expressions with simplification.


divide

public static Expression divide(Expression e1,
                                Expression e2)
Returns division of two expressions with simplification.


mod

public static Expression mod(Expression e1,
                             Expression e2)
Returns modulus of two expressions with simplification.


and

public static Expression and(Expression e1,
                             Expression e2)
Returns and of two expressions with simplification.


or

public static Expression or(Expression e1,
                            Expression e2)
Returns or of two expressions with simplification.


eq

public static Expression eq(Expression e1,
                            Expression e2)
Returns comparison(==) of two expressions with simplification.


ne

public static Expression ne(Expression e1,
                            Expression e2)
Returns comparison(!=) of two expressions with simplification.


le

public static Expression le(Expression e1,
                            Expression e2)
Returns comparison(<=) of two expressions with simplification.


lt

public static Expression lt(Expression e1,
                            Expression e2)
Returns comparison(<) of two expressions with simplification.


ge

public static Expression ge(Expression e1,
                            Expression e2)
Returns comparison(>=) of two expressions with simplification.


gt

public static Expression gt(Expression e1,
                            Expression e2)
Returns comparison(>) of two expressions with simplification.


negate

public static Expression negate(Expression e)
Returns negation of the given expression.


power

public static Expression power(Expression e,
                               int order)
Returns
e
's power to the
order
with simplification.


increment

public static Expression increment(Expression e)
Returns the given expression incremented by one.


decrement

public static Expression decrement(Expression e)
Returns the given expression decremented by one.


getVariablesOnLHS

public static java.util.List<java.lang.Object> getVariablesOnLHS(Expression e)
Returns a list of comparison expressions equivalent to the given expression. Each element in the returned list has an identifier on the right-hand side.

Parameters:
e - the given comparison expression.
Returns:
a list of equivalent/normalized comparison expressions.

getConstantCoefficient

public static long getConstantCoefficient(Expression e)
Returns the constant term in the simplified expression.

Parameters:
e - the expression to be examined.
Returns:
the constant term in "long" type.

getConstantCoefficient

public static Expression getConstantCoefficient(Expression e,
                                                java.util.List<Identifier> ids)
Returns the constant term with respect to the given set of variables.

Parameters:
e - the expression to be examined.
ids - the list of variables (identifiers).
Returns:
the symbolic constant term.

getCoefficient

public static Expression getCoefficient(Expression e,
                                        Identifier id)
Returns the symbolic coefficient of the given identifier in the expression.

Parameters:
e - the expression to be examined.
id - the identifier.
Returns:
the symbolic coefficient of the identifier, null if the expression is too complicated.

getCoefficient

public static java.util.List<Expression> getCoefficient(Expression e,
                                                        java.util.List<Identifier> ids)
Returns the list of coefficient with respect to the given set of identifiers. The last element of the returned list is symbolic constant coefficient.

Parameters:
e - the expression to be examined.
ids - the list of identifiers.
Returns:
the list of coefficients.

getVariables

public static java.util.List<Identifier> getVariables(Expression e)
Returns the list of variables if the given expression is affine. This method replaces NormalExpression.getVariableList(e).

Parameters:
e - the expression to be examined.
Returns:
the list of variables if e is affine, null otherwise.

isAffine

public static boolean isAffine(Expression e,
                               java.util.List<Identifier> ids)
Checks if the given expression is an affine expression with respect to the given list of identifiers.

Parameters:
e - the expression to be examined.
ids - the list of identifiers.
Returns:
true if it is affine, false otherwise.

getClosedFormSum

public static Expression getClosedFormSum(Identifier id,
                                          Expression lb,
                                          Expression ub,
                                          Expression e)
Returns the closed form of the given summation parameters, sum(e) s.t. 0
Parameters:
id - the index variable.
lb - the lower bound of id.
ub - the upper bound of id.
e - the given expression.
Returns:
the closed form of the given expression.

simplifyDivisible

public static Expression simplifyDivisible(Expression e)
Returns a simplified expression assuming the given expression is divisible.


getClosedFormSum

public static Expression getClosedFormSum(Identifier id,
                                          Expression lb,
                                          Expression ub,
                                          Expression e,
                                          java.lang.Boolean divisible)
Computes and returns the closed form expression of the given expression, index, and bounds with the divisibility property of the given expression.


getPolynomialCoef

public static java.util.List<Expression> getPolynomialCoef(Expression e,
                                                           Identifier id)
Returns a list of expressions which contains coefficients of n-th terms when the given id is the basis. e.g.) (2*i*i+1-i,i) returns [1, -1, 2].

Parameters:
e - the input expression.
id - the basis variable.
Returns:
the list of coefficients.

getTerms

public static java.util.List<Expression> getTerms(Expression e)
Returns a list of terms for expressions with addition. e.g., a+b*c --> {a, b*c}.


getFactors

public static java.util.List<Expression> getFactors(Expression e)

getDenominators

public static java.util.List<Expression> getDenominators(Expression e)
Returns a list of denominators if the expression contains divisions. e.g., 2/a+b/c --> {a, c}.


addAll

public static Expression addAll(java.util.List<Expression> exprs)
Returns an expression that adds all expressions in the given expression list.


multiplyAll

public static Expression multiplyAll(java.util.List<Expression> exprs)
Returns an expression that multiplies all expressions in the given expression list.


multiplyByLCM

public static Expression multiplyByLCM(Expression e)
Returns an expression multiplied by LCM of the denominators present in the terms in the specified expression.


getLeastCommonDenominator

public static Expression getLeastCommonDenominator(Expression e)