ai.krr.fol
Class NegatedSentence

java.lang.Object
  extended by ai.krr.fol.Sentence
      extended by ai.krr.fol.NegatedSentence
All Implemented Interfaces:
inf.compilers.SyntaxAdaptable, java.lang.Cloneable, java.lang.Comparable<Sentence>

public class NegatedSentence
extends Sentence

A NegatedSentence is the simplest kind of complex Sentence. It simply contains the Sentence that is negated. Note that a negated Atom can also be represented as a Literal, but a negative Literal is not equal to a negated sentence containing the same Atom.

Author:
Gerhard Wickler

Nested Class Summary
 
Nested classes/interfaces inherited from class ai.krr.fol.Sentence
Sentence.SubSentenceIterator
 
Field Summary
protected  Sentence contained
          the contained Sentence that is negated
 
Constructor Summary
NegatedSentence(Sentence stmt)
           This constructor for a NegatedSentence simply takes the Sentence that is negated.
 
Method Summary
protected  void addBoundVariables(java.util.Set<Variable> bound)
           This function adds the bound Variables in this Sentence to the given Set.
protected  void addConstants(java.util.Set<Symbol> sys)
           This function adds all the constant Symbols used in this Sentence to the given Set.
protected  void addFreeVariables(java.util.Set<Variable> free, java.util.Set<Variable> bound)
           This function adds the free Variables in this Sentence to the first given Set.
protected  void addFunctions(java.util.Map<Symbol,java.lang.Integer> sys)
           This function adds all the function Symbols used in this Sentence to the given Set.
protected  void addPredicates(java.util.Map<NamedSymbol,java.lang.Integer> sys)
           This function adds all the predicate Symbols used in this Sentence to the given Set.
 NegatedSentence clone()
           Cloning a NegatedSentence returns a new NegatedSentence containing the same contained Sentence.
 NegatedSentence clone(Substitution s)
           Returns a deep copy of this NegatedSentence with Variables replaced according to the given Substitution.
 int compareTo(NegatedSentence other)
           This function compares this NegatedSentence to the given NegatedSentence.
 int compareTo(Sentence other)
          This function compares this Sentence to the given Sentence.
 boolean equals(NegatedSentence other)
           A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.
 boolean equals(java.lang.Object obj)
           A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.
 BooleanSymbol evaluate(Interpretation ipt, Substitution s)
           This function evaluates this Sentence under the given Interpretation and Substitution for Variables.
 boolean exceedsDepth(int depth)
           This function tests whether this Sentence exceeds the given depth which should be a non-negative integer.
 int getClassOrderIndex()
           This function returns the index used for ordering Sentences across different classes.
 Sentence getContainedSentence()
           This function returns the Sentence that is contained in this NegatedSentence.
 int getDepth()
           This function returns the nesting depth of this Sentence.
 int hashCode()
           This function returns the hash code of this NegatedSentence.
protected  Sentence skolemize(boolean isNegated, Term[] uqVars, Substitution s)
           This function computes a skolemized version of this Sentence.
protected  Sentence toCNF(boolean isNegated)
           This function returns a new Literal which contains the proposition contained in this Atom.
protected  Sentence toDNF(boolean isNegated)
           This function returns a new Literal which contains the proposition contained in this Atom.
 java.lang.String toString()
           A NegatedSentence is printed as the tilde symbol '~' followed by the contained Sentence.
 
Methods inherited from class ai.krr.fol.Sentence
allSubSentences, getBoundVariables, getConstants, getFreeVariables, getFunctions, getPredicates, prettyPrint, read, skolemize, toClauseForm, toCNF, toDNF, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

contained

protected final Sentence contained
the contained Sentence that is negated

Constructor Detail

NegatedSentence

public NegatedSentence(Sentence stmt)

This constructor for a NegatedSentence simply takes the Sentence that is negated. The given Sentence must not be null.

Parameters:
stmt - the negated Sentence
Method Detail

clone

public final NegatedSentence clone()

Cloning a NegatedSentence returns a new NegatedSentence containing the same contained Sentence.

Specified by:
clone in class Sentence
Returns:
an equal shallow copy of this NegatedSentence

clone

public NegatedSentence clone(Substitution s)

Returns a deep copy of this NegatedSentence with Variables replaced according to the given Substitution. Symbols in the copy will be the same as the original ones but Variables will be replaced by the respective Terms in the given Substitution. A Variable not occurring in the Substitution will be replaced by a new (different) Variable with the same name. The given Substitution will be extended to include the mappings of old Variables to new ones.

Specified by:
clone in class Sentence
Parameters:
s - the Substitution that tells us how to replace Variables
Returns:
a new NegatedSentence that is an instance of this NegatedSentence; the Substitution s will extended with any new Variable replacements introduced

getDepth

public final int getDepth()

This function returns the nesting depth of this Sentence. The depth of a negated sentence is the depth of the contained Sentence plus one.

Specified by:
getDepth in class Sentence
Returns:
the depth of this Sentence when seen as a tree

exceedsDepth

public final boolean exceedsDepth(int depth)

This function tests whether this Sentence exceeds the given depth which should be a non-negative integer.

Specified by:
exceedsDepth in class Sentence
Parameters:
depth - the depth value that is tested for
Returns:
true iff this.getDepth() > depth

getClassOrderIndex

public final int getClassOrderIndex()

This function returns the index used for ordering Sentences across different classes. This index of this class is defined to be 3.

Specified by:
getClassOrderIndex in class Sentence
Returns:
an integer indicating how this type of Sentence is to be ordered with respect to different types of Sentence

compareTo

public int compareTo(Sentence other)

This function compares this Sentence to the given Sentence. The order between different kinds of Sentence is arbitrarily defined as (ascending): TruthValue, Atom, Literal, NegatedSentence, ConnectedSentence, BinaryConnectedSentence, QuantifiedSentence.

Specified by:
compareTo in interface java.lang.Comparable<Sentence>
Specified by:
compareTo in class Sentence
Parameters:
other - the Sentence to which this Sentence is to be compared
Returns:
0 if the two Sentences are identical; -1 if the given Sentence should come after this Sentence; and +1 if the given Sentence should come before this Sentence

evaluate

public BooleanSymbol evaluate(Interpretation ipt,
                              Substitution s)

This function evaluates this Sentence under the given Interpretation and Substitution for Variables. Note that the given Substitution must ground all the free Variables occurring in this Sentence. If this Sentence is already ground the given Substitution may be null. If all Atoms and Terms occurring in the Sentence have a value assigned by the Interpretation the result will be a BooleanSymbol. Otherwise it will be null.

Specified by:
evaluate in class Sentence
Parameters:
ipt - the Interpretation giving values for Atoms and Terms
s - the Substitution for Variables occurring in this Term
Returns:
the value of this Term under the given Interpretation

getContainedSentence

public final Sentence getContainedSentence()

This function returns the Sentence that is contained in this NegatedSentence.

Returns:
the Sentence that is negated here

compareTo

public int compareTo(NegatedSentence other)

This function compares this NegatedSentence to the given NegatedSentence. The order between NegatedSentences is defined by the order of the Sentences they contain.

Parameters:
other - the Sentence to which this Sentence is to be compared
Returns:
0 if the two Sentences are identical; -1 if the given Sentence should come after this Sentence; and +1 if the given Sentence should come before this Sentence

addConstants

protected void addConstants(java.util.Set<Symbol> sys)

This function adds all the constant Symbols used in this Sentence to the given Set.

Specified by:
addConstants in class Sentence
Parameters:
sys - the Set that will contain all the Constants

addFunctions

protected void addFunctions(java.util.Map<Symbol,java.lang.Integer> sys)

This function adds all the function Symbols used in this Sentence to the given Set.

Specified by:
addFunctions in class Sentence
Parameters:
sys - the Set that will contain all the function names

addPredicates

protected void addPredicates(java.util.Map<NamedSymbol,java.lang.Integer> sys)

This function adds all the predicate Symbols used in this Sentence to the given Set.

Specified by:
addPredicates in class Sentence
Parameters:
sys - the Set that will contain all the predicate names

addFreeVariables

protected void addFreeVariables(java.util.Set<Variable> free,
                                java.util.Set<Variable> bound)

This function adds the free Variables in this Sentence to the first given Set. Variables in the second given Set are bound and will not be added.

Specified by:
addFreeVariables in class Sentence
Parameters:
free - a Set of free Variables that will be extended
bound - a Set of bound Variables

addBoundVariables

protected void addBoundVariables(java.util.Set<Variable> bound)

This function adds the bound Variables in this Sentence to the given Set.

Specified by:
addBoundVariables in class Sentence
Parameters:
bound - a Set of bound Variables that will be extended

skolemize

protected Sentence skolemize(boolean isNegated,
                             Term[] uqVars,
                             Substitution s)

This function computes a skolemized version of this Sentence. It replaces all the existentially quantified variables in this Sentence by appropriate Skolem constants and functions. It all so removes all quantification from this sentence meaning that all remaining Variables are implicitly universally quantified. The given boolean determines whether this sub-Sentence is negated, which is necessary to determine the effective type of quantifier in a QuantifiedSentence. The given Term must all be Variables and represent all the universally quantified Variables at this point. These will be arguments to a potentially introduced Skolem function. Finally, the given Substitution must store mappings from existentially quantified Variables to Skolem Terms.

Specified by:
skolemize in class Sentence
Parameters:
isNegated - whether the Sentence is negated
uqVars - the known universally quantified Variables at this point
s - the Substitution for Variable replacements
Returns:
a new Sentence with no quantification (can be converted to CNF/DNF)

toCNF

protected Sentence toCNF(boolean isNegated)

This function returns a new Literal which contains the proposition contained in this Atom. The given boolean indicates whether the new Literal is to be negated.

Specified by:
toCNF in class Sentence
Parameters:
isNegated - whether the Literal has to be negated
Returns:
a new Literal, possibly negative

toDNF

protected Sentence toDNF(boolean isNegated)

This function returns a new Literal which contains the proposition contained in this Atom. The given boolean indicates whether the new Literal is to be negated.

Specified by:
toDNF in class Sentence
Parameters:
isNegated - whether the Literal has to be negated
Returns:
a new Literal, possibly negative

toString

public java.lang.String toString()

A NegatedSentence is printed as the tilde symbol '~' followed by the contained Sentence.

Overrides:
toString in class java.lang.Object
Returns:
the String that represents this NegatedSentence

equals

public boolean equals(java.lang.Object obj)

A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object this NegatedSentence is compared to
Returns:
whether the given Object equals this NegatedSentence

equals

public boolean equals(NegatedSentence other)

A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.

Parameters:
other - the NegatedSentence this NegatedSentence is compared to
Returns:
whether the given NegatedSentence equals this NegatedSentence

hashCode

public int hashCode()

This function returns the hash code of this NegatedSentence.

Overrides:
hashCode in class java.lang.Object
Returns:
a positive integer that may be used for hashing