RealSequence.java

You can download this shell code on the left. The javadoc for this code can be viewed here. The file sequences.pdf discusses sequences from a mathematical viewpoint. You will want to read this. The code here compiles as-is.


import java.util.function.IntToDoubleFunction;
import java.util.function.DoubleUnaryOperator;
/**
 * This is a class of immutable zero-based immutible sequences
 * taking on real values.
 */
public class RealSequence
{

    private final IntToDoubleFunction seq;
    private static final double TOL = 1e-6;
    /**
     * This is the zero sequence.
     */
    private static final RealSequence ZERO = null;
    /**
     * This constructor accepts as parameter a lambda that maps
     * nonnegaative integers to doubles.
     * @param seq a lambda mapping nonnegative integers to doubles
     */
    public RealSequence(IntToDoubleFunction seq)
    {
        this.seq = null;
    }
    /**
     * this returns the sequence's value at n
     * @param n the index we are evaluating the sequence at
     * @return a<sub>n</sub>
     * @throws IllegalArgumentException if n &lt; 0
     */
    public double at(int n)
    {
        return 0;
    }
    /**
     * This sums the sequence between indices start and finish.
     * @param start the index where we begin summing
     * @param finish the index we end summing at
     * @return sum(a<sub>n</sub>, start &lt;= n &lt; finish)
     */
    public double sum(int start, int finish)
    {
        return 0;
    }
    /**
     * This sums the sequence between 0 and finish.
     * @param finish the index we end summing at
     * @return sum(a<sub>n</sub>, 0 &lt;= n &lt; finish)
     */
    public double sum(int finish)
    {
        return 0;
    }
    /**
     * This computes the entrywise sum of two sequences
     * @param that the RealSequence we are adding to this RealSequence
     * @return this + that
     */
    public RealSequence add(RealSequence that)
    {
        return null;
    }
    /**
     * This computes the entrywise difference of two sequences
     * @param that the RealSequence we are subtracting from this RealSequence
     * @return this - that
     */
    public RealSequence subtract(RealSequence that)
    {
        return null;
    }
    /**
     * This computes the entrywise product of two sequences
     * @param that the RealSequence we are multiplying by this RealSequence
     * @return this*that
     */
    public RealSequence multiply(RealSequence that)
    {
        return null;
    }
    /**
     * This computes the entrywise quotient of two sequences
     * @param that the RealSequence we are dividing by this RealSequence
     * @return this/that
     */
    public RealSequence divide(RealSequence that)
    {
        return null;
    }
    /**
     * This computes the convolution of two sequences
     * @param that the RealSequence we are convolving with this RealSequence
     * @return a sequence based on the mapping n -&gt; sum(at(k)*that.at(n-k))
     */

    public RealSequence convolution(RealSequence that)
    {
        return null;
    }
    /**
     * This multiplies the sequence between indices start and finish.
     * @param start the index where we begin summing
     * @param finish the index we end summing at
     * @return product(a<sub>n</sub>, start &lt;= n &lt; finish)
     */
    public double product(int start, int finish)
    {
        return 1;
    }
    /**
     * This multiples the sequence between 0 and finish.
     * @param finish the index we end summing at
     * @return product(a<sub>n</sub>, 0 &lt;= n &lt; finish)
     */
    public double product(int finish)
    {
        return 1;
    }
    //use this instead of testing for equality of doubles.
    private static boolean closeEnough(double x, double y)
    {
        return Math.abs(x -  y) < TOL;
    }
    /**
     * This butters a real function of a real variable over a sequence
     * @param f a lambda that maps doubles to doubles.
     * @return a new sequence with f applied to each entry.
     */
    public RealSequence butter(DoubleUnaryOperator f)
    {
        return null;
    }
    /**
     * This is your testing playground. 
     * @param args command-line arguments
     */
    public static void main(String[] args)
    {
        /*RealSequence h = new RealSequence(n -> 1.0/(n + 1));
        RealSequence s = h.butter(x -> x*x);
        System.out.println(h.sum(1000));
        System.out.println(s.sum(1000));
        System.out.println(Math.PI*Math.PI/6);
        RealSequence id = new RealSequence(n -> n);
        for(int k = 0; k < 10; k++)
        {
            System.out.println(id.convolution(id).at(k));
        }
        */
    }
}