ua.gradsoft.termware
Class AbstractComplexTerm

java.lang.Object
  extended by ua.gradsoft.termware.Term
      extended by ua.gradsoft.termware.AbstractComplexTerm
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AbstractSetTerm, ArgsPatternTerm, ClassPatternTerm, ComplexTerm, ListInArrayTerm, ListTerm, SetPatternTerm

public abstract class AbstractComplexTerm
extends Term

Abstract complex term. This is term like f(x1,.. xN). Contains some subclass-specific storage for subterms.

See Also:
Serialized Form

Field Summary
protected  boolean emptyFv_
           
 
Constructor Summary
AbstractComplexTerm()
           
 
Method Summary
 boolean boundEquals(Term t)
          equality, when propositional variables are already bounded.
 boolean boundUnify(Term t, Substitution s)
          unification when we already have s and when same propositional variables means same things
 Object clone()
           
abstract  Term createSame(Term[] newBody)
          create term, with same name but new body.
 boolean emptyFv()
          true, if term does not contains free propositional variables.
 int findSubtermIndexBoundEqualsTo(Term t)
           
 boolean freeEquals(Term x)
          Equality when all propositional variables are equal
 boolean freeUnify(Term t, Substitution s)
          return unification of this and t and store in s substitution.
abstract  int getArity()
          get arity of term.
 BigDecimal getBigDecimal()
          in this interface throws UnsupportedOperationException
 BigInteger getBigInteger()
          in this interface throws UnsupportedOperationException
 boolean getBoolean()
          in this class throws UnsupportedOperationException
 byte getByte()
          in this interface throws UnsupportedOperationException
 char getChar()
          in this interface throws UnsupportedOperationException
 double getDouble()
          get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.
 float getFloat()
          in this interface throws UnsupportedOperationException
 int getInt()
          in this interface throws UnsupportedOperationException
 Object getJavaObject()
          in this class throws UnsupportedOperationException
 long getLong()
          in this interface throws UnsupportedOperationException
abstract  String getName()
          get name of term.
abstract  Object getNameIndex()
          get name index in bounded symbol table or sust string, if name in symbol table does not exists.
 Number getNumber()
          in this class throws UnsupportedOperationException
 String getPatternName()
          get name, for which we can forse unfication.
 Object getPatternNameIndex()
          get index for pattern name.
 int getPrimaryType0()
          get primary type of the term.
 short getShort()
          in this class throws UnsupportedOperationException
 String getString()
          in this interface throws UnsupportedOperationException
abstract  Term getSubtermAt(int i)
          get i-th subterm.
 Term getTerm()
          return term
 int getXIndex()
          in this class throws UnsupportedOperationException
 boolean isAtom()
          is this term is Atom ?
 boolean isBigDecimal()
          is this tern is BigDecimal ?
 boolean isBigInteger()
          is this tern is BigInteger ?
 boolean isBoolean()
          is this term is Boolean ?
 boolean isByte()
          is this term is Byte ?
 boolean isChar()
          is this term is Char ?
 boolean isComplexTerm()
          is this term is ComplexTerm ?
 boolean isDouble()
          is this tern is Double ?
 boolean isFloat()
          is this term is Float ?
 boolean isInt()
          is this term is Int ?
 boolean isJavaObject()
          is this term is Java Object ?
 boolean isLong()
          is this term is Long ?
 boolean isNil()
          is this term is nil ?
 boolean isNumber()
          is this term is Number ?
 boolean isShort()
          is this term is Short ?
 boolean isString()
          is this tern is String ?
 boolean isX()
          is this term is X ?
 int maxFv()
          get maximum index of free propositional variable in term
 int minFv()
          get minimal index of free propositional variable in term.
 void normalizeFv(int i)
           
 void print(PrintWriter out)
          print term on out
protected  void recheckEmptyFv()
          recheck existance of propositional variables in subterms.
protected  void resetFV()
           
abstract  void setSubtermAt(int i, Term t)
          set i-th subterm.
 void shiftFv(int newMinFv)
          shift set of propositional variables to start from newMinFv
 Term subst(Substitution s)
          receive new term, which is sibstution of current term and s
 boolean substInside(Substitution s)
          apply substitution s to current term.
abstract  Term termClone()
          do 'deep-clone' of object.
 int termCompare(Term t)
          compare function.
 
Methods inherited from class ua.gradsoft.termware.Term
concreteOrder, containsSubtermBoundEqualsTo, getAsBigDecimal, getAsBigInteger, getAsBoolean, getAsByte, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsJavaObject, getAsLong, getAsNumber, getAsShort, getAsString, getPrimaryType1, print, println, println
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emptyFv_

protected transient boolean emptyFv_
Constructor Detail

AbstractComplexTerm

public AbstractComplexTerm()
Method Detail

getPrimaryType0

public final int getPrimaryType0()
get primary type of the term.

Specified by:
getPrimaryType0 in class Term
Returns:
PrimaryTypes.COMPLEX_TERM
See Also:
PrimaryTypes

getName

public abstract String getName()
get name of term. (i. e. functional symbold)

Specified by:
getName in class Term
Returns:
name

getNameIndex

public abstract Object getNameIndex()
get name index in bounded symbol table or sust string, if name in symbol table does not exists.

Specified by:
getNameIndex in class Term

getPatternName

public String getPatternName()
get name, for which we can forse unfication.

Overrides:
getPatternName in class Term

getPatternNameIndex

public Object getPatternNameIndex()
get index for pattern name.

Overrides:
getPatternNameIndex in class Term

getArity

public abstract int getArity()
get arity of term.

Specified by:
getArity in class Term
Returns:
arity of term

getSubtermAt

public abstract Term getSubtermAt(int i)
get i-th subterm.

Specified by:
getSubtermAt in class Term
Parameters:
i - - index of subterm to get.
Returns:
subterm, which located by index i
Throws:
TermIndexOutOfBoundsException - when i>getArity()
InvalidArgumentException - when i < 0

setSubtermAt

public abstract void setSubtermAt(int i,
                                  Term t)
                           throws TermWareException
set i-th subterm.

Specified by:
setSubtermAt in class Term
Parameters:
i - - indext of subterm to set.
t - - subterm to set.
Throws:
TermWareException

createSame

public abstract Term createSame(Term[] newBody)
                         throws TermWareException
Description copied from class: Term
create term, with same name but new body. If this term have arity 0, or other than original - throws exception.

Specified by:
createSame in class Term
Throws:
TermWareException

termClone

public abstract Term termClone()
                        throws TermWareException
do 'deep-clone' of object. i. e. after calling termClone we sure, that call of setSubtermAt() in any subtree of deepClone of original term does not affect original term.

Specified by:
termClone in class Term
Throws:
TermWareException

clone

public final Object clone()
Overrides:
clone in class Object

isNil

public final boolean isNil()
is this term is nil ?

Specified by:
isNil in class Term
Returns:
false

isAtom

public final boolean isAtom()
is this term is Atom ?

Specified by:
isAtom in class Term
Returns:
false

isBoolean

public final boolean isBoolean()
is this term is Boolean ?

Specified by:
isBoolean in class Term
Returns:
false

getBoolean

public final boolean getBoolean()
in this class throws UnsupportedOperationException

Specified by:
getBoolean in class Term
Returns:
boolean value

isNumber

public final boolean isNumber()
is this term is Number ?

Specified by:
isNumber in class Term
Returns:
false

getNumber

public final Number getNumber()
in this class throws UnsupportedOperationException

Specified by:
getNumber in class Term
Returns:
number value

isByte

public final boolean isByte()
is this term is Byte ?

Specified by:
isByte in class Term
Returns:
false

getByte

public final byte getByte()
in this interface throws UnsupportedOperationException

Specified by:
getByte in class Term
Returns:
value

isShort

public final boolean isShort()
is this term is Short ?

Specified by:
isShort in class Term
Returns:
false

getShort

public final short getShort()
in this class throws UnsupportedOperationException

Specified by:
getShort in class Term
Returns:
short value

isInt

public final boolean isInt()
is this term is Int ?

Specified by:
isInt in class Term
Returns:
false

getInt

public final int getInt()
                 throws UnsupportedOperationException
in this interface throws UnsupportedOperationException

Specified by:
getInt in class Term
Returns:
int value
Throws:
UnsupportedOperationException

isLong

public final boolean isLong()
is this term is Long ?

Specified by:
isLong in class Term
Returns:
false

getLong

public final long getLong()
                   throws UnsupportedOperationException
in this interface throws UnsupportedOperationException

Specified by:
getLong in class Term
Returns:
short value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

isFloat

public final boolean isFloat()
is this term is Float ?

Specified by:
isFloat in class Term
Returns:
false

getFloat

public final float getFloat()
in this interface throws UnsupportedOperationException

Specified by:
getFloat in class Term
Returns:
float value

isDouble

public final boolean isDouble()
is this tern is Double ?

Specified by:
isDouble in class Term
Returns:
false

getDouble

public final double getDouble()
Description copied from class: Term
get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.

Specified by:
getDouble in class Term
Returns:
double value
See Also:
here throws UnsupportedOperationException

isBigDecimal

public final boolean isBigDecimal()
is this tern is BigDecimal ?

Specified by:
isBigDecimal in class Term
Returns:
false

getBigDecimal

public final BigDecimal getBigDecimal()
in this interface throws UnsupportedOperationException

Specified by:
getBigDecimal in class Term
Returns:
number value

isBigInteger

public final boolean isBigInteger()
is this tern is BigInteger ?

Specified by:
isBigInteger in class Term
Returns:
false

getBigInteger

public final BigInteger getBigInteger()
                               throws UnsupportedOperationException
in this interface throws UnsupportedOperationException

Specified by:
getBigInteger in class Term
Returns:
value
Throws:
UnsupportedOperationException - raised if this term does not represent BigInteger value.

isChar

public final boolean isChar()
is this term is Char ?

Specified by:
isChar in class Term
Returns:
false

getChar

public final char getChar()
in this interface throws UnsupportedOperationException

Specified by:
getChar in class Term
Returns:
char value

isString

public final boolean isString()
is this tern is String ?

Specified by:
isString in class Term
Returns:
false

getString

public final String getString()
in this interface throws UnsupportedOperationException

Specified by:
getString in class Term
Returns:
string value

isJavaObject

public final boolean isJavaObject()
is this term is Java Object ?

Specified by:
isJavaObject in class Term
Returns:
false.

getJavaObject

public final Object getJavaObject()
in this class throws UnsupportedOperationException

Specified by:
getJavaObject in class Term
Returns:
Java Object, if this term holds opaque Java Object, otherwise throw UnsupportedOperationException

isX

public final boolean isX()
is this term is X ?

Specified by:
isX in class Term
Returns:
false.

getXIndex

public final int getXIndex()
in this class throws UnsupportedOperationException

Specified by:
getXIndex in class Term

isComplexTerm

public final boolean isComplexTerm()
is this term is ComplexTerm ?

Specified by:
isComplexTerm in class Term
Returns:
true.

getTerm

public Term getTerm()
return term

Specified by:
getTerm in class Term

freeUnify

public boolean freeUnify(Term t,
                         Substitution s)
                  throws TermWareException
return unification of this and t and store in s substitution.

Specified by:
freeUnify in class Term
Returns:
true, if unification was succesfull.
Throws:
TermWareException

boundUnify

public boolean boundUnify(Term t,
                          Substitution s)
                   throws TermWareException
Description copied from class: Term
unification when we already have s and when same propositional variables means same things

Specified by:
boundUnify in class Term
Throws:
TermWareException

substInside

public boolean substInside(Substitution s)
                    throws TermWareException
apply substitution s to current term.

Specified by:
substInside in class Term
Throws:
TermWareException

subst

public Term subst(Substitution s)
           throws TermWareException
receive new term, which is sibstution of current term and s

Specified by:
subst in class Term
Throws:
TermWareException

freeEquals

public boolean freeEquals(Term x)
                   throws TermWareException
Equality when all propositional variables are equal

Specified by:
freeEquals in class Term
Parameters:
x - - term to compare.
Returns:
true, if terms are free-equals.
Throws:
TermWareException

boundEquals

public boolean boundEquals(Term t)
                    throws TermWareException
Description copied from class: Term
equality, when propositional variables are already bounded.

Specified by:
boundEquals in class Term
Parameters:
t - - term to compare.
Returns:
true, if terms are bound-equals.
Throws:
TermWareException

findSubtermIndexBoundEqualsTo

public int findSubtermIndexBoundEqualsTo(Term t)
                                  throws TermWareException
Specified by:
findSubtermIndexBoundEqualsTo in class Term
Throws:
TermWareException

termCompare

public int termCompare(Term t)
compare function.

Specified by:
termCompare in class Term
Parameters:
t - - term to compare

emptyFv

public boolean emptyFv()
Description copied from class: Term
true, if term does not contains free propositional variables. (fv-set for this term is empty.)

Specified by:
emptyFv in class Term
Returns:
true, if fv_set does not contains free proporsitional variables.

minFv

public int minFv()
          throws TermWareException
Description copied from class: Term
get minimal index of free propositional variable in term.

Specified by:
minFv in class Term
Returns:
index of propositional variable with minimal index.
Throws:
TermWareException

maxFv

public int maxFv()
          throws TermWareException
Description copied from class: Term
get maximum index of free propositional variable in term

Specified by:
maxFv in class Term
Returns:
index of propositional variable with maximal index.
Throws:
TermWareException

shiftFv

public void shiftFv(int newMinFv)
             throws TermWareException
shift set of propositional variables to start from newMinFv

Specified by:
shiftFv in class Term
Parameters:
newMinFv - new minimal index of propositional variable in term
Throws:
TermWareException

normalizeFv

public void normalizeFv(int i)
                 throws TermWareException
Throws:
TermWareException

print

public void print(PrintWriter out)
Description copied from class: Term
print term on out

Specified by:
print in class Term
Parameters:
out - - PrintWriter, where to print term.

recheckEmptyFv

protected void recheckEmptyFv()
recheck existance of propositional variables in subterms. (called by childrens afer non-optimized structure-unsafe operations)


resetFV

protected final void resetFV()