I have been experimenting with using spire for interval arithmetic. Strangely, I can run some code fine in a scala worksheet (in eclipse scala-ide), and run it by copy pasting in the console (both sbt console and Li Haoyi's ammonite REPL), but on importing and loading I get an error. Is there something I am misunderstading, or is this a bug? Below is the full code as well as the full console session. Any help is appreciated.
regards,
Siddhartha
Code (the problem is with J, so the stream may not be relevant):
package compact_enumeration
import spire.math._
import spire.algebra._
import spire.implicits._
import spire.syntax.literals._
import annotation.tailrec
import Stream._
/**
* @author gadgil
*
* Interval bounds for exp, log, sin, cos
*/
class ApproxTrig(N: SafeLong) {
import ApproxTrig.{get, Nat}
import spire.syntax.literals._
val width = r"1" / N
lazy val J = Interval.closed(r"0", width)
import Interval._
/**
* stream of bounds on the exponential.
* At n, this is an interval containing e^(n/ N)
*/
lazy val expstream : Stream[Interval[Rational]] = Nat map ((n: SafeLong) =>
if (n ==0) Interval.point(Rational(1))
else
{
val b = get(expstream, n-1)
val a = b * Interval.closed(r"1/2" , (1 + width) / (2 - (width * width)))
(a * width * width) + (b * (width + 1))
})
}
object ApproxTrig{
val Nat: Stream[SafeLong] = 0 #:: (Nat map ((n) => n + 1))
@tailrec def get[A](as: Stream[A], n: SafeLong) : A = {
if (n ==0) as.head else get(as.tail, n-1)
}
}
Running in REPL (ammonite-repl): similar errors in sbt-console
Loading Ammonite Repl...
@ import compact_enumeration._
import compact_enumeration._
@ import compact_enumeration.ApproxTrig
import compact_enumeration.ApproxTrig
@ import spire.math._
import import spire.math._
@ import spire.algebra._
import spire.algebra._
@ import spire.implicits._
import spire.implicits._
@ import spire.syntax.literals._
import spire.syntax.literals._
@ val apr = new ApproxTrig(500)
apr: compact_enumeration.ApproxTrig = compact_enumeration.ApproxTrig@1c6ff4b
@ apr.width
res7: spire.math.Rational = 1/500
@ apr.J
java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
ammonite.repl.interp.Evaluator$$anon$3.ammonite$repl$interp$Evaluator$$anon$$evalMain(Evaluator.scala:148)
ammonite.repl.interp.Evaluator$$anon$3$$anonfun$processLine$1$$anonfun$apply$15$$anonfun$apply$16$$anonfun$apply$1.apply$mcV$sp(Evaluator.scala:208)
java.lang.NoSuchMethodError: spire.math.Interval$.closed(Ljava/lang/Object;Ljava/lang/Object;Lspire/algebra/Order;Lspire/algebra/AdditiveMonoid;)Lspire/math/Interval;
compact_enumeration.ApproxTrig.J$lzycompute(Unknown Source)
compact_enumeration.ApproxTrig.J(Unknown Source)
cmd8$.<init>(Main.scala:741)
cmd8$.<clinit>(Main.scala)
cmd8.$main(Main.scala)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
ammonite.repl.interp.Evaluator$$anon$3.ammonite$repl$interp$Evaluator$$anon$$evalMain(Evaluator.scala:148)
ammonite.repl.interp.Evaluator$$anon$3$$anonfun$processLine$1$$anonfun$apply$15$$anonfun$apply$16$$anonfun$apply$1.apply$mcV$sp(Evaluator.scala:208)