|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uk.org.ogsadai.activity.files.Sequence
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.
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 |
private static final java.lang.String COPYRIGHT_NOTICE
private Lagrange mLagrange
Constructor Detail |
public Sequence(int[] items) throws NonIncreasingSequenceException
Sequence
with a provided array of ordered seed integers.
items
- The seed integersNonIncreasingSequenceException
- If the given sequence is non-increasing.Method Detail |
public java.lang.String toString()
toString
in class java.lang.Object
private boolean increasing(int[] items)
items[
i+1]
> items[
i]
for all integers 0 <= i < items.length
-1.
items
- The array to testtrue
if the integers are strictly increasing, false
otherwise.public boolean isMember(int val) throws NonIncreasingSequenceException
val
- The integer to testtrue
if the integer is a member of the sequence, false
otherwiseNonIncreasingSequenceException
- If the given sequence is non-increasing.private static int toInt(double number)
number
- the number to roundstatic java.lang.String intArrayToString(int[] items)
items
- The array of integers
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |