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 an
* @throws IllegalArgumentException if n < 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(an, start <= n < 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(an, 0 <= n < 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 -> 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(an, start <= n < 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(an, 0 <= n < 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));
}
*/
}
}