tom.library.sl
Class Position

java.lang.Object
  extended by tom.library.sl.Position
All Implemented Interfaces:
Cloneable, Path

public class Position
extends Object
implements Cloneable, Path

Object that represents a position in a term


Method Summary
 Path add(Path p)
          Computes the path from the source of this to the target of the parameter p.
 Position changePrefix(Position oldprefix, Position prefix)
           
 Object clone()
           
 int compare(Path path)
          Compares two positions
 Path conc(int i)
          Add the move i to the end of the current path
 Position down(int i)
           
 boolean equals(Object o)
          Tests if two positions are equals
 Path getCanonicalPath()
          Gives the canonical form of a path.
 int getHead()
          Gives the first move of the path which is represented by an integer i.
 Strategy getOmega(Strategy v)
          create s=omega(v) such that s[subject] returns subject[ s[subject|omega] ]|omega
 Strategy getOmegaPath(Strategy v)
          create s=omegaPath(v) such that s[subject] applies s to all nodes in the path of omega in a bottom-up way
 Strategy getReplace(Object t)
          create s=omega(x->t) such that s[subject] returns subject[t]|omega
 Strategy getSubterm()
          create s=x->t|omega such that s[subject] returns subject|omega
 Path getTail()
          Gives the tail of the path which is also a path.
 int hashCode()
           
 boolean hasPrefix(Position prefix)
           
 Path inverse()
          Computes the path from the target of this to the source of this.
 int length()
          Get the length of the position in the tree
static Position make()
           
static Position makeFromArray(int[] array)
           
static Position makeFromPath(Path p)
           
static Position makeFromSubarray(int[] src, int srcIndex, int length)
           
 Path sub(Path p)
          Computes the path from the target of this to the target of the parameter p.
 int[] toIntArray()
           
 String toString()
          Returns a String object representing the position.
 Position up()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

make

public static Position make()

makeFromSubarray

public static Position makeFromSubarray(int[] src,
                                        int srcIndex,
                                        int length)

makeFromArray

public static Position makeFromArray(int[] array)

makeFromPath

public static Position makeFromPath(Path p)

clone

public Object clone()
Overrides:
clone in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Tests if two positions are equals

Overrides:
equals in class Object

compare

public int compare(Path path)
Compares two positions


toString

public String toString()
Returns a String object representing the position. The string representation consists of a list of elementary positions

Overrides:
toString in class Object
Returns:
a string representation of this position

add

public Path add(Path p)
Description copied from interface: Path
Computes the path from the source of this to the target of the parameter p. The addition of two paths must respect the following equations:

t1.add(t2) = (t1.getTail().add(t2)).conc(t1.getHead()) if t1.length()>0,

t1.add(t2) = t2 otherwise.

Specified by:
add in interface Path
Parameters:
p - the path to add.
Returns:
the path corresponding to the addition of this and the parameter p.

sub

public Path sub(Path p)
Description copied from interface: Path
Computes the path from the target of this to the target of the parameter p. The subtraction of two paths must respect the following equation:

t1.sub(t2) = t2.inverse().add(t1),

Specified by:
sub in interface Path
Parameters:
p - the path to subtract.
Returns:
the path corresponding to the subtraction of this and the parameter p.

inverse

public Path inverse()
Description copied from interface: Path
Computes the path from the target of this to the source of this. The inverse operation must respect the following equations:

t.inverse() = t.getTail().inverse().add(-t.getHead()) if t.length()>0,

t.inverse() = t otherwise

Specified by:
inverse in interface Path
Returns:
the path corresponding to the inverse path of this.

length

public int length()
Get the length of the position in the tree

Specified by:
length in interface Path
Returns:
length of the path

getHead

public int getHead()
Description copied from interface: Path
Gives the first move of the path which is represented by an integer i. When i is positive, it corresponds to a move from the parent to th i-th child of the current location. Otherwise, it signifies a move from the i-th child to the parent.

Specified by:
getHead in interface Path
Returns:
the first move.

getTail

public Path getTail()
Description copied from interface: Path
Gives the tail of the path which is also a path.

Specified by:
getTail in interface Path
Returns:
the path after the first move.

conc

public Path conc(int i)
Description copied from interface: Path
Add the move i to the end of the current path

Specified by:
conc in interface Path
Parameters:
i - the move to insert.
Returns:
the path corresponding to the insersion of i into this.

getCanonicalPath

public Path getCanonicalPath()
Description copied from interface: Path
Gives the canonical form of a path. Two paths are equivalent if for every source the corresponding targets are the same. In an equivalence class, the canonical form is the smallest path.

Specified by:
getCanonicalPath in interface Path
Returns:
its canonical form

toIntArray

public int[] toIntArray()
Specified by:
toIntArray in interface Path
Returns:
an array containing all of the elements in this path in proper sequence (from first to last element).

up

public Position up()

down

public Position down(int i)

hasPrefix

public boolean hasPrefix(Position prefix)

changePrefix

public Position changePrefix(Position oldprefix,
                             Position prefix)

getOmega

public Strategy getOmega(Strategy v)
create s=omega(v) such that s[subject] returns subject[ s[subject|omega] ]|omega

Parameters:
v - strategy subterm of the omega strategy
Returns:
the omega strategy corresponding to the position

getOmegaPath

public Strategy getOmegaPath(Strategy v)
create s=omegaPath(v) such that s[subject] applies s to all nodes in the path of omega in a bottom-up way

Parameters:
v - strategy subterm of the omega strategy
Returns:
the omegaPath strategy corresponding to the position

getReplace

public Strategy getReplace(Object t)
create s=omega(x->t) such that s[subject] returns subject[t]|omega

Parameters:
t - the constant term that should replace the subterm
Returns:
the omega strategy the performs the replacement

getSubterm

public Strategy getSubterm()
create s=x->t|omega such that s[subject] returns subject|omega

Returns:
the omega strategy that retrieves the corresponding subterm