Skip to content

Instantly share code, notes, and snippets.

@aakashns
Created April 3, 2015 13:34
Show Gist options
  • Select an option

  • Save aakashns/6d96372c7ae59d5168f4 to your computer and use it in GitHub Desktop.

Select an option

Save aakashns/6d96372c7ae59d5168f4 to your computer and use it in GitHub Desktop.
pari group for rationsl
object RationalGroup extends Group[(Int, Int)] {
val zero = (0, 0)
def plus(x: (Int, Int), y: (Int, Int)): (Int, Int) = (x, y) match {
case ((x1, x2), (y1, y2)) => (x1*y2 + x2*y1, x2*y2)
}
def inverse(x: (Int, Int)) = (-x._1, x._2)
}
sum(Seq((1, 1), (4, 8), (9, 27), (25, 125), (64, 512)))(RationalGroup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment