kodkod.ast
Class Formula

java.lang.Object
  extended by kodkod.ast.Formula
All Implemented Interfaces:
Node
Direct Known Subclasses:
BinaryFormula, ComparisonFormula, ConstantFormula, IntComparisonFormula, MultiplicityFormula, NotFormula, QuantifiedFormula, RelationPredicate

public abstract class Formula
extends java.lang.Object
implements Node

A first-order formula. Unless otherwise noted, all methods in this class throw a NullPointerException when given null arguments.

Implementation Note: The compose method performs constant folding, so that, for example, calling f.and(Formula.TRUE) returns f. If it is necessary to have a new Formula returned in such cases, then f.and(triviallyTrue) should be called instead, where triviallyTrue is a trivially true formula such as Expression.NONE.no().

Author:
Emina Torlak

Field Summary
static Formula FALSE
          Constant formula false
static Formula TRUE
          Constant formula true
 
Method Summary
abstract
<E,F,D,I> F
accept(ReturnVisitor<E,F,D,I> visitor)
          Accepts the given visitor and returns the result.
 Formula and(Formula formula)
          Returns the conjunction of this and the specified formula.
 Formula compose(BinaryFormula.Operator op, Formula formula)
          Returns the composition of this and the specified formula using the given binary operator.
 Expression comprehension(Decls decls)
          Returns the comprehension expression constructed from this formula and the given declarations.
 Formula forAll(Decls decls)
          Returns a formula that represents a universal quantification of this formula over the given declarations.
 Formula forSome(Decls decls)
          Returns a formula that represents an existential quantification of this formula over the given declarations.
 Formula iff(Formula formula)
          Returns a formula that equates this and the specified formula.
 Formula implies(Formula formula)
          Returns the implication of the specified formula by this.
 Formula not()
          Returns the negation of this formula.
 Formula or(Formula formula)
          Returns the conjunction of this and the specified formula.
 Formula quantify(QuantifiedFormula.Quantifier quantifier, Decls decls)
          Returns a quantification of this formula using the given quantifier over the specified declarations.
 Expression thenElse(Expression thenExpr, Expression elseExpr)
          Returns the if expression constructed from this formula and the specified then and else expressions.
 IntExpression thenElse(IntExpression thenExpr, IntExpression elseExpr)
          Returns the if expression constructed from this formula and the specified then and else integer expressions.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface kodkod.ast.Node
accept
 

Field Detail

TRUE

public static final Formula TRUE
Constant formula true


FALSE

public static final Formula FALSE
Constant formula false

Method Detail

and

public final Formula and(Formula formula)
Returns the conjunction of this and the specified formula. The effect of this method is the same as calling this.compose(BinaryFormula.Operator.AND, formula).

Returns:
{f : Formula | f <=> (this && formula)}

or

public final Formula or(Formula formula)
Returns the conjunction of this and the specified formula. The effect of this method is the same as calling this.compose(BinaryFormula.Operator.OR, formula).

Returns:
{f : Formula | f <=> (this || formula)}

iff

public final Formula iff(Formula formula)
Returns a formula that equates this and the specified formula. The effect of this method is the same as calling this.compose(BinaryFormula.Operator.IFF, formula).

Returns:
{f : Formula | f <=> (this <=> formula)}

implies

public final Formula implies(Formula formula)
Returns the implication of the specified formula by this. The effect of this method is the same as calling this.compose(BinaryFormula.Operator.IMPLIES, formula).

Returns:
{f : Formula | f <=> (this => formula)}

compose

public final Formula compose(BinaryFormula.Operator op,
                             Formula formula)
Returns the composition of this and the specified formula using the given binary operator.

Returns:
{f: Formula | f <=> (this op formula) }

forAll

public final Formula forAll(Decls decls)
Returns a formula that represents a universal quantification of this formula over the given declarations. The effect of this method is the same as calling this.quantify(QuantifiedFormula.Quantifier.ALL, decls).

Returns:
{f: Formula | f <=> (all decls | this) }

forSome

public final Formula forSome(Decls decls)
Returns a formula that represents an existential quantification of this formula over the given declarations. The effect of this method is the same as calling this.quantify(QuantifiedFormula.Quantifier.SOME, decls).

Returns:
{f: Formula | f <=> (some decls | this) }

quantify

public final Formula quantify(QuantifiedFormula.Quantifier quantifier,
                              Decls decls)
Returns a quantification of this formula using the given quantifier over the specified declarations.

Returns:
{f: Formula | f <=> (quantifier decls | this) }

comprehension

public final Expression comprehension(Decls decls)
Returns the comprehension expression constructed from this formula and the given declarations.

Returns:
{e: Expression | e = {decls | this} }

thenElse

public final Expression thenElse(Expression thenExpr,
                                 Expression elseExpr)
Returns the if expression constructed from this formula and the specified then and else expressions.

Returns:
{e: Expression | e = if this then thenExpr else elseExpr}

thenElse

public final IntExpression thenElse(IntExpression thenExpr,
                                    IntExpression elseExpr)
Returns the if expression constructed from this formula and the specified then and else integer expressions.

Returns:
{e: IntExpression | e = if this then thenExpr else elseExpr}

not

public final Formula not()
Returns the negation of this formula.

Returns:
{f : Formula | f <=> (!this)}

accept

public abstract <E,F,D,I> F accept(ReturnVisitor<E,F,D,I> visitor)
Accepts the given visitor and returns the result.

Specified by:
accept in interface Node
Returns:
the result of being visited by the given visitor
See Also:
Node.accept(kodkod.ast.visitor.ReturnVisitor)