Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.lsmp.djep.sjep
Class PolynomialCreator

    java.lang.Object
      org.lsmp.djep.xjep.DoNothingVisitor
          org.lsmp.djep.sjep.PolynomialCreator

All Implemented Interfaces:
  ParserVisitor

    public class PolynomialCreator

extends DoNothingVisitor

Main entry point for simplification routines.

Uses a complete reworking of the ways equations are represented. A tree structure is built from Polynomials, Monomials, PVariable etc. An equation like

    1+2 x^2+3 x y+4 x sin(y)

is represented as

    Polynomial([
      Monomial(2.0,[PVariable(x)],[2])]),
      Monomial(3.0,[x,y],[1,1]),
      Monomial(4.0,[x,Function(sin,arg)],[1,1])
    ])

A total ordering of all expressions is used. As the representation is constructed the total ordering of terms is maintained. This helps ensure that polynomials are always in their simplest form and also allows comparison of equations.

The following sequence illustrates current ordering. This ordering may change without warning.

- -1 numbers sorted by values
- 0
- 1 numbers before monomials
- a^-2 powers in increasing order
- a^-1
- a
- a^2
- a^3
- a^x numeric powers before symbolic powers
- a b single variable monomials before multiple variables
- a^2 b
- b variables sorted alphabetically
- cos(a) monomials before functions
- sin(a) function names sorted alphabetically
- a+b functions before polynomials
- a+b+c

Author:
  Rich Morris Created on 14-Dec-2004

Constructor Summary
`PolynomialCreator(XJep j)`

Method Summary
`int` | `compare(Node node1, Node node2)` Compares two nodes.
`PNodeI` | `createPoly(Node node)` Converts an expression into the polynomial representation.
`boolean` | `equals(Node node1, Node node2)` Compares two nodes.
`Node` | `expand(Node node)` Expands an expression.
`Node` | `simplify(Node node)` Simplifies an expression.
`java.lang.Object` | `visit(ASTConstant node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTFunNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTVarNode node, java.lang.Object data)`

Methods inherited from class org.lsmp.djep.xjep.DoNothingVisitor
`acceptChildrenAsArray, visit, visit`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PolynomialCreator

    public PolynomialCreator(XJep j)

Method Detail

### createPoly

    public PNodeI createPoly(Node node)
                      throws ParseException

  Converts an expression into the polynomial representation.

  Parameters:
    `node` - top node of expression
  Returns:
    top node of polynomial form of expression
  Throws:
    `ParseException` - if expression cannot be converted.

### simplify

    public Node simplify(Node node)
                  throws ParseException

  Simplifies an expression.

  Parameters:
    `node` - top node to expression to be simplified.
  Returns:
    a simplified expression
  Throws:
    `ParseException`

### expand

    public Node expand(Node node)
                throws ParseException

  Expands an expression. Will always expand brackets for multiplication and simple powers. For instance `(1+x)^3 -> 1+3x+3x^2+x^3`

  Parameters:
    `node` - top node to expression to be simplified.
  Returns:
    a simplified expression
  Throws:
    `ParseException`

### compare

    public int compare(Node node1,
                       Node node2)
                throws ParseException

  Compares two nodes. Uses a total ordering of expressions. Expands equations before comparison.

  Parameters:
    `node1` -
    `node2` -
  Returns:
    -1 if node1node2
  Throws:
    `ParseException`

### equals

    public boolean equals(Node node1,
                          Node node2)
                   throws ParseException

  Compares two nodes. Uses a total ordering of expressions. May give some false negatives is simplification cannot reduce two equal expressions to the same canonical form. Expands equations before comparison.

  Parameters:
    `node1` -
    `node2` -
  Returns:
    true if two nodes represents same expression.
  Throws:
    `ParseException`

### visit

    public java.lang.Object visit(ASTConstant node,
                                  java.lang.Object data)
                           throws ParseException

  Specified by:
    `visit` in interface `ParserVisitor`
  Overrides:
    `visit` in class `DoNothingVisitor`
  Throws:
    `ParseException`

### visit

    public java.lang.Object visit(ASTVarNode node,
                                  java.lang.Object data)
                           throws ParseException

  Specified by:
    `visit` in interface `ParserVisitor`
  Overrides:
    `visit` in class `DoNothingVisitor`
  Throws:
    `ParseException`

### visit

    public java.lang.Object visit(ASTFunNode node,
                                  java.lang.Object data)
                           throws ParseException

  Specified by:
    `visit` in interface `ParserVisitor`
  Overrides:
    `visit` in class `DoNothingVisitor`
  Throws:
    `ParseException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

http://www.singularsys.com/jep Copyright © 2007 Singular Systems