kodkod.ast
Class Relation

java.lang.Object
  extended by kodkod.ast.Expression
      extended by kodkod.ast.LeafExpression
          extended by kodkod.ast.Relation
All Implemented Interfaces:
Node

public class Relation
extends LeafExpression

A relation is a leaf expression. Two relations are the same if and only if they refer to the same object. That is, r1.equals(r2) <=> r1 == r2. Each variable has a name, which is basically a comment for the purpose of printing, viewing, etc. The name has no meaning otherwise.

Four methods for creating commonly used predicates over binary relations are provided: function(Expression, Expression), functional(Expression, Expression), acyclic(), and totalOrder(Relation, Relation, Relation). Using these methods to generate desired predicates will result in faster constraint solving than creating the same predicates via other API calls.

Author:
Emina Torlak
invariant:
no children
specfield:
name: String
arity: int

Field Summary
 
Fields inherited from class kodkod.ast.Expression
IDEN, INTS, NONE, UNIV
 
Method Summary
<E,F,D,I> E
accept(ReturnVisitor<E,F,D,I> visitor)
          Accepts the given visitor and returns the result.
 void accept(VoidVisitor visitor)
          Accepts the given visitor.
 Formula acyclic()
          Returns a formula stating that this relation is acyclic.
static Relation binary(java.lang.String name)
          Returns a new binary relation with the given name.
 Formula function(Expression domain, Expression range)
          Returns a formula stating that this relation is a total function with the specified domain and range.
 Formula functional(Expression domain, Expression range)
          Returns a formula stating that this relation is a partial function with the specified domain and range.
static Relation nary(java.lang.String name, int arity)
          Returns a new relation with the given name and arity.
static Relation ternary(java.lang.String name)
          Returns a ternary relation with the specified name.
 Formula totalOrder(Relation ordered, Relation first, Relation last)
          Returns a formula stating that this relation imposes a total ordering over the atoms in the set ordered, and that thet first and last elements in the ordering are given by the relations first and last.
static Relation unary(java.lang.String name)
          Returns a new unary relation with the given name.
 
Methods inherited from class kodkod.ast.LeafExpression
arity, name, toString
 
Methods inherited from class kodkod.ast.Expression
apply, apply, apply, closure, compose, compose, count, difference, eq, in, intersection, join, lone, no, one, override, product, project, reflexiveClosure, some, sum, transpose, union
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

nary

public static Relation nary(java.lang.String name,
                            int arity)
Returns a new relation with the given name and arity.

Returns:
{r: Relation | r.arity = arity && r.name = name }
Throws:
java.lang.IllegalArgumentException - - arity < 1

unary

public static Relation unary(java.lang.String name)
Returns a new unary relation with the given name. The effect of this method is the same as calling Relation.nary(name,1).

Returns:
{r: Relation | r.arity = 1 && r.name = name }

binary

public static Relation binary(java.lang.String name)
Returns a new binary relation with the given name. The effect of this method is the same as calling Relation.nary(name,2).

Returns:
{r: Relation | r.arity = 2 && r.name = name }

ternary

public static Relation ternary(java.lang.String name)
Returns a ternary relation with the specified name.

Returns:
{r: Relation | r.name = name && r.arity = 3}

accept

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

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

accept

public void accept(VoidVisitor visitor)
Accepts the given visitor.

See Also:
Node.accept(kodkod.ast.visitor.VoidVisitor)

acyclic

public Formula acyclic()
Returns a formula stating that this relation is acyclic.

Returns:
{f: Formula | f <=> no ^this & iden}
Throws:
java.lang.IllegalArgumentException - - this.arity != 2

function

public Formula function(Expression domain,
                        Expression range)
Returns a formula stating that this relation is a total function with the specified domain and range.

Returns:
{f: Formula | f <=> this in domain->range && all v: domain | one v.this }
Throws:
java.lang.NullPointerException - - domain = null || range = null
java.lang.IllegalArgumentException - - domain.arity != 1 || range.arity != 1
java.lang.IllegalArgumentException - - this.arity != 2

functional

public Formula functional(Expression domain,
                          Expression range)
Returns a formula stating that this relation is a partial function with the specified domain and range.

Returns:
{f: Formula | f <=> this in domain->range && all v: domain | lone v.this }
Throws:
java.lang.NullPointerException - - domain = null || range = null
java.lang.IllegalArgumentException - - domain.arity != 1 || range.arity != 1
java.lang.IllegalArgumentException - - this.arity != 2

totalOrder

public Formula totalOrder(Relation ordered,
                          Relation first,
                          Relation last)
Returns a formula stating that this relation imposes a total ordering over the atoms in the set ordered, and that thet first and last elements in the ordering are given by the relations first and last.

Returns:
{f: Formula | f <=> one first && one last && last in ordered && no this.first && no last.this && ordered = first.*this && all e: ordered - last | one e.this }
Throws:
java.lang.NullPointerException - - any of the arguments are null
java.lang.IllegalArgumentException - - any of the argument relations' arities are greater than one
java.lang.IllegalArgumentException - - this.arity != 2