tom.library.sl
Class Position

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

public class Position
extends java.lang.Object
implements java.lang.Cloneable, Path

Object that represents a position in a term


Constructor Summary
Position()
           
Position(int[] omega)
           
Position(Position prefix, Position suffix)
           
 
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 newprefix)
           
 java.lang.Object clone()
           
 int compare(Path path)
          Compares two positions
 Path conc(int i)
          Add the move i to the begining of the current path
 int depth()
          Get the depth of the position in the tree
 Position down(int i)
          For compatibility with mutraveler positions
 boolean equals(java.lang.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(Visitable 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
 Position getSuffix(Position prefix)
           
 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()
          Computes the length which corresponds to the number of moves needed to go from the source to the target.
static Position make(Path p)
           
 Path sub(Path p)
          Computes the path from the target of this to the target of the parameter p.
 int[] toArray()
           
 java.lang.String toString()
          Returns a String object representing the position.
 Position up()
          For compatibility with mutraveler positions
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Position

public Position()

Position

public Position(int[] omega)

Position

public Position(Position prefix,
                Position suffix)
Method Detail

toArray

public int[] toArray()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

depth

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

Returns:
depth on the position

equals

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

Overrides:
equals in class java.lang.Object

compare

public int compare(Path path)
Compares two positions


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(Visitable 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

toString

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

Overrides:
toString in class java.lang.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.inv().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.inv() = t.getTail().inv().add(-t.getHead()) if t1.length()>0,

t.inv() = t otherwise

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

make

public static Position make(Path p)

length

public int length()
Description copied from interface: Path
Computes the length which corresponds to the number of moves needed to go from the source to the target.

Specified by:
length in interface Path
Returns:
the 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 begining 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.

up

public Position up()
For compatibility with mutraveler positions


down

public Position down(int i)
For compatibility with mutraveler positions


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

hasPrefix

public boolean hasPrefix(Position prefix)

getSuffix

public Position getSuffix(Position prefix)

changePrefix

public Position changePrefix(Position oldprefix,
                             Position newprefix)