MathIterators { public static ImmutableIterator<Double> divide(Iterator<Double> s, Iterator<Double> t) { return new Product(s, inverse(t)); } private  MathIterators(); static Comparator<Double> weakDoubleComparator(double epsilon); static UnaryOperator<Double> increment(Double delta); static UnaryOperator<Double> times(Double factor); static InfiniteIterator<Double> random(); static InfiniteIterator<Double> arithmeticSeries(double start, double delta); static InfiniteIterator<Double> geometricSeries(double start, double factor); static ImmutableIterator<Double> exp(); static ImmutableIterator<Double> sin(); static ImmutableIterator<Double> cos(); static ImmutableIterator<Double> add(Iterator<Double> s, double inc); @SuppressWarnings("unchecked") static Iterator<Double> inc(Iterator<Double> s, double inc); static ImmutableIterator<Double> add(Iterator<Double> s, Iterator<Double> t); static ImmutableIterator<Double> multiply(Iterator<Double> s, double factor); static ImmutableIterator<Double> multiply(Iterator<Double> s, Iterator<Double> t); static ImmutableIterator<Double> square(Iterator<Double> t); static InfiniteIterator<Double> inverse(Iterator<Double> t); static ImmutableIterator<Double> divide(Iterator<Double> s, Iterator<Double> t); static UnaryOperator<Double> polynom(Iterator<Double> t, int dim); static UnaryOperator<Double> polynom(Iterator<Double> t); static Iterator<Double> compose(Iterator<Double> t, Iterator<Double> s, int dim); static Iterator<Double> compose(Iterator<Double> t, Iterator<Double> s);  }
@Test public void testDivide() { List<Double> xs = asList(1.0, 0.0, -1.0); List<Double> ys = asList(1.0, -1.0); Iterator<Double> u = multiply(ys.iterator(), divide(xs.iterator(), ys.iterator())); assertTrue(weakEquals(xs.iterator(), u, 3)); u = multiply(xs.iterator(), divide(ys.iterator(), xs.iterator())); assertTrue(weakEquals(ys.iterator(), u, 2)); xs = asList(1.0, 1.0); u = multiply(xs.iterator(), inverse(xs.iterator())); BinaryOperator<Double> acc = (x, y) -> x + y; assertEquals(1.0, reduce(limit(u, 5), acc).doubleValue(), 0); }