Skip to content

Instantly share code, notes, and snippets.

@larsrh
Last active September 14, 2018 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsrh/b4bb402616e43b1e9792a5be4968ee3d to your computer and use it in GitHub Desktop.
Save larsrh/b4bb402616e43b1e9792a5be4968ee3d to your computer and use it in GitHub Desktop.
LX Scala 2018/Scala Italy 2018 demo code: "Numeric programming with spire"
val cities1 = Map("Portugal" -> List("Lisbon"), "Spain" -> List("Madrid"))
val cities2 = Map("Portugal" -> List("Coimbra"))
cities1 |+| cities2
RingLaws[Int].ring.all.check()
RingLaws[Float].ring.all.check()
val score = r"5/7"
def twice[A : AdditiveMonoid](a: A) = a + a
twice(score)
twice(3)
twice(Map("Score" -> score))
score.toBigDecimal()
Real.pi
Real.pi.doubleValue()
Real.pi.toRational(1).toBigDecimal()
Real.pi.toRational(2).toBigDecimal()
Real.pi.toRational(4).toBigDecimal()
val score = r"5/7"
val confidence = score ± r"1/7"
confidence.intersects(r"3/4" ± r"1/8")
confidence.intersect(r"3/4" ± r"1/8")
import $ivy.`org.typelevel::spire:0.15.0`
import $ivy.`org.typelevel::spire-laws:0.15.0`
import spire._
import spire.algebra._
import spire.math._
import spire.implicits._
import spire.laws._
import spire.syntax.literals._
import org.scalacheck._
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment