Permalink
Browse files

Benchmarks extracted from Math.js

  • Loading branch information...
pavpanchekha committed Oct 31, 2013
1 parent 7a4fb34 commit c2dd17380b7eab0fc8397cf0347c0d42092f41c9
Showing with 140 additions and 0 deletions.
  1. +20 −0 bench/mathjs/README.txt
  2. +89 −0 bench/mathjs/arithmetic.scm
  3. +7 −0 bench/mathjs/complex.scm
  4. +6 −0 bench/mathjs/probability.scm
  5. +18 −0 bench/mathjs/trigonometry.scm
View
@@ -0,0 +1,20 @@
Extracted Test Suite from Math.js
=================================
Math.js is a math library for JavaScript. It supports matrices,
complex numbers, and basic units. All code appears to be written from
scratch and cites no literature beyond Wikipedia.
All code examples from Math.js, which can be found on Github at
https://github.com/josdejong/mathjs/blob/master/. All code is
distributed under an Apache 2 license. All floating point code in
`lib/` was extracted, except the `lib/matrix/` determinant and inverse
routines (contains complex control flow) and the `lib/trigonometry/`
functions `acos`, `asin`, `atan`, `cot`, `csc`, `sec`, and `tan`
(expansion was too large).
= To Do =
Finish extracting the `lib/trigonometry` functions missed above; it
simply requires a lot of manual work or an automatic tool to rewrite
`let` blocks into equivalent call-by-name blocks.
@@ -0,0 +1,89 @@
; All code examples from mathjs
; https://github.com/josdejong/mathjs/blob/master/
; /lib/function/arithmetic/abs.js math.abs for complex arguments
(lambda (re im)
(sqrt (+ (* re re) (* im im))))
; /lib/function/arithmetic/cube.js math.cube for real arguments
(lambda (x)
(* (* x x) x))
; /lib/function/arithmetic/cube.js math.cube for complex arguments
; Manually expanded math.multiply
(lambda (re im) ; real part
(- (* (- (* x.re x.re) (* x.im x.im)) ; x^2.re
x.re)
(* (+ (* x.re x.im) (* x.im x.re)) ; x^2.im
x.im)))
(lambda (re im) ; imag part
(+ (* (- (* x.re x.re) (* x.im x.im)) ; x^2.re
x.im)
(* (+ (* x.re x.im) (* x.im x.re)) ; x^2.im
x.re)))
; /lib/function/arithmetic/divide.js _divideComplex
(lambda (x.re x.im y.re y.im) ; real part
(/ (+ (* x.re y.re) (* x.im y.im))
(+ (* y.re y.re) (* y.im y.im))))
(lambda (x.re x.im y.re y.im) ; imag part
(/ (- (* x.im y.re) (* x.re y.im))
(+ (* y.re y.re) (* y.im y.im))))
; /lib/function/arithmetic/exp.js math.exp for complex arguments
(lambda (re im) ; real part
(* (exp re) (cos im)))
(lambda (re im) ; imag part
(* (exp re) (sin im)))
; /lib/function/arithmetic/log.js math.log for complex arguments, with one argument
(lambda (re im) ; real part
(log (sqrt (+ (* re re) (* im im)))))
(lambda (re im) ; imag part
(atan2 im re))
; /lib/function/arithmetic/log.js math.log for complex arguments, with two arguments
; Manually expanded math.divide
(lambda (re im base) ; real part
(/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0))
(+ (* (log base) (log base)) (* 0 0))))
(lambda (re im base) ; imag part
(/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0))
(+ (* (log base) (log base)) (* 0 0))))
; /lib/function/arithmetic/log10.js math.log10 for complex arguments, with one argument
(lambda (re im) ; real part
(/ (log (sqrt (+ (* re re) (* im im)))) ln10))
(lambda (re im) ; imag part
(/ (atan2 im re) ln10))
; /lib/function/arithmetic/multiply.js _multiplyComplex
(lambda (x.re x.im y.re y.im) ; real part
(- (* x.re y.re) (* x.im y.im)))
(lambda (x.re x.im y.re y.im) ; imag part
(+ (* x.re y.im) (* x.im y.re)))
; /lib/function/arithmetic/pow.js powComplex
; Manually expanded math.log, math.multiply, math.exp
(lambda (x.re x.im y.re y.im) ; real part
(* (exp (- (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re) (* (atan2 x.im x.re) y.im)))
(cos (+ (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im) (* (atan2 x.im x.re) y.re)))))
(lambda (x.re x.im y.re y.im) ; imag part
(* (exp (- (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re) (* (atan2 x.im x.re) y.im)))
(sin (+ (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im) (* (atan2 x.im x.re) y.re)))))
; /lib/function/arithmetic/sqrt.js math.sqrt for complex arguments
(lambda (re im) ; real part
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(lambda (re im) ; imag part
(if (> im 0)
(* 0.5 (sqrt (* 2.0 (+ (sqrt (- (* re re) (* im im))) re))))
(* -0.5 (sqrt (* 2.0 (+ (sqrt (- (* re re) (* im im))) re))))))
; /lib/function/arithmetic/square.js math.square for complex arguments
; Manually expanded math.multiply
(lambda (re im) ; real part
(- (* re re) (* im im)))
(lambda (re im) ; imag part
(+ (* re im) (* im re)))
View
@@ -0,0 +1,7 @@
; All code examples from mathjs
; https://github.com/josdejong/mathjs/blob/master/
; /lib/function/complex/arg.js math.arg for complex arguments
(lambda (re im)
(atan2 im re))
@@ -0,0 +1,6 @@
; All code examples from mathjs
; https://github.com/josdejong/mathjs/blob/master/
; /lib/function/probability/random.js normal
(lambda (u1 u2)
(+ (* (* (/ 1 6) (expt (* -2 (log u1)) 0.5)) (cos (* (* 2 pi) u2))) 0.5))
@@ -0,0 +1,18 @@
; All code examples from mathjs
; https://github.com/josdejong/mathjs/blob/master/
; TODO : The inverse functions acos, asin, and atan were too complex to expand fully.
; /lib/function/trigonometry/cos.js math.cos for complex arguments
(lambda (re im) ; real part
(* (* 0.5 (cos re)) (+ (exp (- 0 im)) (exp im))))
(lambda (re im) ; imag part
(* (* 0.5 (sin re)) (- (exp (- 0 im)) (exp im))))
; TODO : The reciprocal functions cot, csc, sec, and tan were too complex to expand fully.
; /lib/function/trigonometry/sin.js math.sin for complex arguments
(lambda (re im) ; real part
(* (* 0.5 (sin re)) (+ (exp (- 0 im)) (exp im))))
(lambda (re im) ; imag part
(* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

0 comments on commit c2dd173

Please sign in to comment.