Last active
September 14, 2018 14:18
-
-
Save larsrh/b4bb402616e43b1e9792a5be4968ee3d to your computer and use it in GitHub Desktop.
LX Scala 2018/Scala Italy 2018 demo code: "Numeric programming with spire"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val cities1 = Map("Portugal" -> List("Lisbon"), "Spain" -> List("Madrid")) | |
val cities2 = Map("Portugal" -> List("Coimbra")) | |
cities1 |+| cities2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RingLaws[Int].ring.all.check() | |
RingLaws[Float].ring.all.check() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val score = r"5/7" | |
def twice[A : AdditiveMonoid](a: A) = a + a | |
twice(score) | |
twice(3) | |
twice(Map("Score" -> score)) | |
score.toBigDecimal() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Real.pi | |
Real.pi.doubleValue() | |
Real.pi.toRational(1).toBigDecimal() | |
Real.pi.toRational(2).toBigDecimal() | |
Real.pi.toRational(4).toBigDecimal() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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