com.evelopers.unimod.analysis
Class BooleanSimplifier

java.lang.Object
  extended bycom.evelopers.unimod.analysis.BooleanSimplifier

public class BooleanSimplifier
extends java.lang.Object

This class may be used to simplify formula, to merge set of formulae as conjunction or disjunction, to negate formula.

To check if set of formulae is complete, i.e. conjunction of the set is identical to true, call

 BooleanSimplifier bs = BooleanSimplifier.createBooleanSimplifier();
 AST node = bs.identicalToTrue(bs.or(formulaeSet));
 if (node.getType() == TRUE) {
   // Formulae set is complete
 } else {
  // node contains the conjunction. Disjunction of this node negated and formulaeSet
  //  will be identical to true
 }
 
To check if two of formulae are orthogonal, i.e. disjucntion of this formulae is identical to false, call
 BooleanSimplifier bs = BooleanSimplifier.createBooleanSimplifier();
 AST node = bs.identicalToFalse(bs.and(Arrays.asList(new AST[] {firstFormula, secondFormula})));
 if (node.getType() == FALSE) {
   // Formulae are orthogonal
 } else {
   // node contains the intersection of formulae. Conjunction of formulae and
   // negated node will be identical to false.
 }
 


Method Summary
 antlr.collections.AST and(java.util.Set astSet)
          Merges astSet to conjunction.
static BooleanSimplifier createBooleanSimplifier()
           
 boolean equal(antlr.collections.AST f, antlr.collections.AST g)
          Checks is f is equal to g.
 antlr.collections.AST identicalToFalse(antlr.collections.AST ast)
          Checks if ast is identical to false.
 antlr.collections.AST identicalToTrue(antlr.collections.AST ast)
          Checks if ast is identical to true.
 antlr.collections.AST not(antlr.collections.AST ast)
          Negates ast.
 antlr.collections.AST or(java.util.Set astSet)
          Merges astSet to disjunction.
 antlr.collections.AST simplify(antlr.collections.AST ast)
          Converts formula to DNF and simplifies it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createBooleanSimplifier

public static BooleanSimplifier createBooleanSimplifier()
Returns:
instance of BooleanSimplifier

and

public antlr.collections.AST and(java.util.Set astSet)
Merges astSet to conjunction.

Parameters:
astSet - set to merge
Returns:
conjunction of astSet

or

public antlr.collections.AST or(java.util.Set astSet)
Merges astSet to disjunction.

Parameters:
astSet - set to merge
Returns:
disjunction of astSet

not

public antlr.collections.AST not(antlr.collections.AST ast)
Negates ast.

Parameters:
ast - formula to negate.
Returns:
negated formula.

simplify

public antlr.collections.AST simplify(antlr.collections.AST ast)
                               throws InterpreterException
Converts formula to DNF and simplifies it. If formula is identical to false then it is guaranteed that will be returned node with type FALSE.

Parameters:
ast - formula to simplify.
Returns:
simplified formula.
Throws:
InterpreterException - if ast isn't correct

identicalToFalse

public antlr.collections.AST identicalToFalse(antlr.collections.AST ast)
                                       throws InterpreterException
Checks if ast is identical to false.

Parameters:
ast - formula to check
Returns:
node with type FALSE if ast is identical to false. Simplified formula elsewise.
Throws:
InterpreterException

identicalToTrue

public antlr.collections.AST identicalToTrue(antlr.collections.AST ast)
                                      throws InterpreterException
Checks if ast is identical to true.

Parameters:
ast - formula to check
Returns:
node with type TRUE if ast is identical to true. Simplified formula elsewise.
Throws:
InterpreterException

equal

public boolean equal(antlr.collections.AST f,
                     antlr.collections.AST g)
              throws InterpreterException
Checks is f is equal to g.

Returns:
true if f is equal to g.
Throws:
InterpreterException