uk.org.ogsadai.activity.files
Class Sequence

java.lang.Object
  |
  +--uk.org.ogsadai.activity.files.Sequence

public class Sequence
extends java.lang.Object

This class represents a countable, increasing chain in the set of integers under the < relation. Note that since the relation is a strict inequality, the chain may not be eventually constant.

The chain d1 < d2 < d3 < ... is defined by:

dn =def P(n)
where P(n) is the Lagrange interpolating polynomial generated from co-ordinates (pn, n), where {pn} is a sequence of "seed integers".

The seed integers are passed to the constructor of this class, from which the Lagrange interpolating polynomial is generated. This polynomial can then be used to extrapolate the sequence to infinity. The isMember method can be used to test whether a given integer n is a member of this sequence, i.e. whether P(i) = n for any positive integer i.

For example, if the seed integers are p1 = 2 and pn = 4, then P(n) = 2n, so isMember will return true when passed any even positive integer.

Note that the indiscriminant use of the Lagrange interpolating polynomial restricts the sequences we can represent. For example, we can represent linear progressions such as 1, 3, 5, ... (with P(n) = 2n - 1); quadratic progressions such as 0, 1, 4, 9 (with P(n) = n2 - 2n + 1); etc, but not exponential progressions.

Author:
The OGSA-DAI Project Team

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement
private  Lagrange mLagrange
          Lagrange polynomial
 
Constructor Summary
Sequence(int[] items)
          Construct a new Sequence with a provided array of ordered seed integers.
 
Method Summary
private  boolean increasing(int[] items)
          Test to see if the integers in the provided array are strictly increasing.
(package private) static java.lang.String intArrayToString(int[] items)
          Return a textual representation of an array of integers.
 boolean isMember(int val)
          Tests to see if a particular integer is a member of the sequence.
private static int toInt(double number)
          Return the integer nearest to the given double precision real number.
 java.lang.String toString()
          Returns a string representation of this sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement

See Also:
Constant Field Values

mLagrange

private Lagrange mLagrange
Lagrange polynomial

Constructor Detail

Sequence

public Sequence(int[] items)
         throws NonIncreasingSequenceException
Construct a new Sequence with a provided array of ordered seed integers.

Parameters:
items - The seed integers
Throws:
NonIncreasingSequenceException - If the given sequence is non-increasing.
Method Detail

toString

public java.lang.String toString()
Returns a string representation of this sequence. For debugging purposes only.

Overrides:
toString in class java.lang.Object
Returns:
a string representation

increasing

private boolean increasing(int[] items)
Test to see if the integers in the provided array are strictly increasing. That is, we test whether items[i+1] > items[i] for all integers 0 <= i < items.length-1.

Parameters:
items - The array to test
Returns:
true if the integers are strictly increasing, false otherwise.

isMember

public boolean isMember(int val)
                 throws NonIncreasingSequenceException
Tests to see if a particular integer is a member of the sequence.

Parameters:
val - The integer to test
Returns:
true if the integer is a member of the sequence, false otherwise
Throws:
NonIncreasingSequenceException - If the given sequence is non-increasing.

toInt

private static int toInt(double number)
Return the integer nearest to the given double precision real number.

Parameters:
number - the number to round
Returns:
the rounded number

intArrayToString

static java.lang.String intArrayToString(int[] items)
Return a textual representation of an array of integers. For debugging purposes only.

Parameters:
items - The array of integers
Returns:
the textual representation