Permalink
Browse files

Record sampling distributions, merge casio-test and casio-bench

Use the syntax `(casio-test ([var dist] ...) body ...)` for
a test where `var` should be sampled according to `dist`,
where `dist` can currently either be `float` (default) or
`positive` (only positive floats).
  • Loading branch information...
pavpanchekha committed Sep 1, 2014
1 parent a5e0551 commit f97d2f946b8ece1b490c6d1b87566c6c90affd43
View
@@ -32,6 +32,6 @@
(- (sqr a) (sqr b))
(* (+ a b) (- a b)))
(casio-bench (a b c)
(casio-test (a b c)
"A la Freetype's FT_MulDiv"
(/ (+ a (/ c 2)) b))
@@ -25,12 +25,12 @@
(/ c (* a r1))
r2)))
(casio-bench (a b/2 c)
(casio-test (a b/2 c)
"NMSE problem 3.2.1"
(let* ((d (sqrt (- (* (* 2 b/2) (* 2 b/2)) (* 4 (* a c))))))
(/ (+ (* -2 b/2) d) (* 2 a))))
(casio-bench (a b/2 c)
(casio-test (a b/2 c)
"NMSE problem 3.2.1"
(let* ((d (sqrt (- (* (* 2 b/2) (* 2 b/2)) (* 4 (* a c))))))
(/ (+ (* -2 b/2) d) (* 2 a))))
View
@@ -1,19 +1,19 @@
#lang racket
(require casio/test)
(casio-bench (x)
(casio-test (x)
"NMSE example 3.7"
(- (exp x) 1))
(casio-bench (N)
(casio-test (N)
"NMSE example 3.8"
(- (- (* (+ N 1) (log (+ N 1))) (* N (log N))) 1))
(casio-bench (x)
(casio-test (x)
"NMSE example 3.9"
(- (/ 1 x) (cotan x)))
(casio-bench (x)
(casio-test (x)
"NMSE example 3.10"
(/ (log (- 1 x)) (log (+ 1 x))))
@@ -22,23 +22,23 @@
(/ (- 1 (cos x)) (expt x 2))
(/ (sqr (sin x)) (* (+ 1 (cos x)) (sqr x))))
(casio-bench (a b eps)
(casio-test (a b eps)
"NMSE problem 3.4.2"
(/ (* eps (- (exp (* (+ a b) eps)) 1))
(* (- (exp (* a eps)) 1) (- (exp (* b eps)) 1))))
(casio-bench (x)
(casio-test (x)
"NMSE problem 3.4.3"
(log (/ (- 1 x) (+ 1 x))))
(casio-bench (x)
(casio-test (x)
"NMSE problem 3.4.4"
(sqrt (/ (- (exp (* 2 x)) 1) (- (exp x) 1))))
(casio-bench (x)
(casio-test (x)
"NMSE problem 3.4.5"
(/ (- x (sin x)) (- x (tan x))))
(casio-bench (x n)
(casio-test (x n)
"NMSE problem 3.4.6"
(- (expt (+ x 1) (/ 1 n)) (expt x (/ 1 n))))
View
@@ -1,16 +1,16 @@
#lang racket
(require casio/test)
(casio-bench (x)
(casio-test (x)
"Hyperbolic sine"
(/ (- (exp x) (exp (- x))) 2))
(casio-bench (x)
(casio-test (x)
"Hyperbolic tangent"
(/ (- (exp x) (exp (- x)))
(+ (exp x) (exp (- x)))))
(casio-bench (x)
(casio-test (x)
"Hyperbolic secant"
(/ 2 (+ (exp x) (exp (- x)))))
@@ -21,14 +21,14 @@
(log (/ -1 (- x (sqrt (+ (sqr x) 1)))))
(log (+ x (sqrt (+ (sqr x) 1))))))
(casio-bench (x)
(casio-test (x)
"Hyperbolic arc-cosine"
(log (+ x (sqrt (- (sqr x) 1)))))
(casio-bench (x)
(casio-test (x)
"Hyperbolic arc-(co)tangent"
(* (/ 1 2) (log (/ (+ 1 x) (- 1 x)))))
(casio-bench (x)
(casio-test (x)
"Hyperbolic arc-(co)secant"
(log (+ (/ 1 x) (/ (sqrt (- 1 (sqr x))) x))))
View
@@ -4,7 +4,7 @@
;; Code from Jmat.js, commit 79a386deb5e19c0ee7896e820f3f90855a27fa17
;; https://raw.githubusercontent.com/lvandeve/jmat/79a386deb5e19c0ee7896e820f3f90855a27fa17/jmat.js
(casio-bench (z)
(casio-test (z)
"Jmat.Real.gamma, branch z > 0.5"
(let* ([z* (- z 1)]
[g 7]
@@ -20,7 +20,7 @@
[t (+ z* g 0.5)])
(* (sqrt (* pi 2)) (expt t (+ z* 0.5)) (exp (- t)) x)))
(casio-bench (z)
(casio-test (z)
"Jmat.Real.gamma, branch z < 0.5"
(let* ([z* (- (- 1 z) 1)]
[g 7]
@@ -36,7 +36,7 @@
[t (+ z* g 0.5)])
(* (/ pi (sin (* pi z))) (* (sqrt (* pi 2)) (expt t (+ z* 0.5)) (exp (- t)) x))))
(casio-bench (x)
(casio-test (x)
"Jmat.Real.lambertw, estimator"
(- (log x) (log (log x))))
@@ -47,7 +47,7 @@
(let* ([ew (exp wj)])
(- wj (- (/ wj (+ wj 1)) (/ x (+ ew (* wj ew)))))))
(casio-bench (x)
(casio-test (x)
"Jmat.Real.dawson"
(let* ([x2 (* x x)]
[x4 (* x2 x2)]
@@ -62,7 +62,7 @@
(+ 1 (* q1 x2) (* q2 x4) (* q3 x6) (* q4 x8) (* q5 x10) (* 2 p5 x12)))
x)))
(casio-bench (x)
(casio-test (x)
"Jmat.Real.erfi, branch x <= 0.5"
(let* ([sqrtpi (sqrt pi)]
[ps (/ 1 sqrtpi)]
@@ -72,7 +72,7 @@
[t (+ (* 2 x) (* (/ 2 3) x3) (* (/ 1 5) x5) (* (/ 1 21) x7))])
(* ps t)))
(casio-bench (x)
(casio-test (x)
"Jmat.Real.erfi, branch x >= 5"
(let* ([sqrtpi (sqrt pi)]
[ps (/ 1 sqrtpi)]
@@ -84,7 +84,7 @@
[t (+ xi (* (/ 1 2) xi3) (* (/ 3 4) xi5) (* (/ 15 8) xi7))])
(* ps e t)))
(casio-bench (x)
(casio-test (x)
"Jmat.Real.erf"
(let* ([t (/ 1 (+ 1 (* 0.3275911 x)))]
[p (* t (+ 0.254829592 (* t (+ -0.284496736 (* t (+ 1.421413741 (* t (+ -1.453152027 (* t 1.061405429)))))))))])
@@ -6,7 +6,7 @@
; from files in
; /lib/function/arithmetic/
(casio-bench (re im)
(casio-test (re im)
"math.abs on complex"
(sqrt (+ (* re re) (* im im))))
@@ -16,73 +16,73 @@
(expt x 3))
; Manually expanded math.multiply
(casio-bench (x.re x.im) ; real part
(casio-test (x.re x.im) ; real part
"math.cube on complex, 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)))
(casio-bench (x.re x.im) ; imag part
(casio-test (x.re x.im) ; imag part
"math.cube on complex, imaginary 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)))
(casio-bench (x.re x.im y.re y.im) ; real part
(casio-test (x.re x.im y.re y.im) ; real part
"_divideComplex, real part"
(/ (+ (* x.re y.re) (* x.im y.im))
(+ (* y.re y.re) (* y.im y.im))))
(casio-bench (x.re x.im y.re y.im) ; imag part
(casio-test (x.re x.im y.re y.im) ; imag part
"_divideComplex, imaginary part"
(/ (- (* x.im y.re) (* x.re y.im))
(+ (* y.re y.re) (* y.im y.im))))
(casio-bench (re im) ; real part
(casio-test (re im) ; real part
"math.exp on complex, real part"
(* (exp re) (cos im)))
(casio-bench (re im) ; imag part
(casio-test (re im) ; imag part
"math.exp on complex, imaginary part"
(* (exp re) (sin im)))
(casio-bench (re im) ; real part
(casio-test (re im) ; real part
"math.log/1 on complex, real part"
(log (sqrt (+ (* re re) (* im im)))))
(casio-bench (re im) ; imag part
(casio-test (re im) ; imag part
"math.log/1 on complex, imaginary part"
(atan2 im re))
; Manually expanded math.divide
(casio-bench (re im base) ; real part
(casio-test (re im base) ; real part
"math.log/2 on complex, real part"
(/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0))
(+ (* (log base) (log base)) (* 0 0))))
(casio-bench (re im base) ; imag part
(casio-test (re im base) ; imag part
"math.log/2 on complex, imaginary part"
(/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0))
(+ (* (log base) (log base)) (* 0 0))))
(casio-bench (re im) ; real part
(casio-test (re im) ; real part
"math.log10 on complex, real part"
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10)))
(casio-bench (re im) ; imag part
(casio-test (re im) ; imag part
"math.log10 on complex, imaginary part"
(/ (atan2 im re) (log 10)))
(casio-bench (x.re x.im y.re y.im) ; real part
(casio-test (x.re x.im y.re y.im) ; real part
"_multiplyComplex, real part"
(- (* x.re y.re) (* x.im y.im)))
(casio-bench (x.re x.im y.re y.im) ; imag part
(casio-test (x.re x.im y.re y.im) ; imag part
"_multiplyComplex, imaginary part"
(+ (* x.re y.im) (* x.im y.re)))
; Manually expanded math.log, math.multiply, math.exp
(casio-bench (x.re x.im y.re y.im) ; real part
(casio-test (x.re x.im y.re y.im) ; real part
"powComplex, 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)))))
(casio-bench (x.re x.im y.re y.im) ; imag part
(casio-test (x.re x.im y.re y.im) ; imag part
"powComplex, imaginary 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)))))
@@ -95,15 +95,15 @@
(- (sqrt (+ (sqr re) (sqr im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re))))))
(casio-bench (re im) ; imag part
(casio-test (re im) ; imag part
"math.sqrt on complex, imaginary part, im > 0 branch"
(* 0.5 (sqrt (* 2.0 (+ (sqrt (- (* re re) (* im im))) re)))))
; Manually expanded math.multiply
(casio-bench (re im) ; real part
(casio-test (re im) ; real part
"math.square on complex, real part"
(- (* re re) (* im im)))
(casio-bench (re im) ; imag part
(casio-test (re im) ; imag part
"math.square on complex, imaginary part"
(+ (* re im) (* im re)))
View
@@ -4,7 +4,7 @@
; All code examples from mathjs
; https://github.com/josdejong/mathjs/blob/master/
(casio-bench (re im)
(casio-test (re im)
"math.arg on complex"
(atan2 im re))
@@ -6,7 +6,7 @@
; from files in
; /lib/function/probability/
(casio-bench (u1 u2)
(casio-test (u1 u2)
"normal distribution"
(+ (* (* (/ 1 6) (expt (* -2 (log u1)) 0.5))
(cos (* (* 2 pi) u2))) 0.5))
@@ -8,18 +8,18 @@
; TODO : The inverse functions acos, asin, and atan were too complex to expand fully.
(casio-bench (re im) ; real part
(casio-test (re im) ; real part
"math.cos on complex, real part"
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
(casio-bench (re im) ; imag part
(casio-test (re im) ; imag part
"math.cos on complex, imaginary part"
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
; TODO : The reciprocal functions cot, csc, sec, and tan were too complex to expand fully.
(casio-bench (re im) ; real part
(casio-test (re im) ; real part
"math.sin on complex, real part"
(* (* 0.5 (sin re)) (+ (exp (- 0 im)) (exp im))))
(casio-bench (re im) ; imag part
(casio-test (re im) ; imag part
"math.sin on complex, imaginary part"
(* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))
@@ -3,30 +3,30 @@
;; From the GNU Octave 3.8 release, in file CollocWt.cc
(casio-bench (alpha beta)
(casio-test (alpha beta)
"Octave 3.8, jcobi/1"
(let* ([ab (+ alpha beta)]
[ad (- beta alpha)]
[ap (* beta alpha)])
(/ (+ (/ ad (+ ab 2.0)) 1.0) 2.0)))
(casio-bench (alpha beta i)
(casio-test (alpha beta i)
"Octave 3.8, jcobi/2"
(let* ([ab (+ alpha beta)]
[ad (- beta alpha)]
[ap (* beta alpha)]
[z (+ ab (* 2 i))])
(/ (+ (/ (* ab ad) z (+ z 2.0)) 1.0) 2.0)))
(casio-bench (alpha beta i)
(casio-test (alpha beta i)
"Octave 3.8, jcobi/3"
(let* ([ab (+ alpha beta)]
[ad (- beta alpha)]
[ap (* beta alpha)]
[z (+ ab (* 2 i))])
(/ (+ ab ap 1.0) z z (+ z 1.0))))
(casio-bench (alpha beta i)
(casio-test (alpha beta i)
"Octave 3.8, jcobi/4"
(let* ([ab (+ alpha beta)]
[ad (- beta alpha)]
@@ -3,7 +3,7 @@
; From the GNU Octave 3.8 release, in file randgamma.c
(casio-bench (a rand)
(casio-test (a rand)
"Octave 3.8, oct_fill_randg"
; Test on a > 1
(let* ([d (- a (/ 1.0 3.0))]
@@ -5,15 +5,15 @@
; D. Maksimov and A. Kolovsky
; Phys. Rev. A 89, 063612 (2014), https://links.aps.org/doi/10.1103/PhysRevA.89.063612,
(casio-bench (J K U)
(casio-test (J K U)
"Maksimov and Kolovsky, Equation (3)"
(* -2 J (cos (/ K 2)) (sqrt (+ 1 (sqr (/ U (* 2 J (cos (/ K 2)))))))))
(casio-bench (J l K U)
(casio-test (J l K U)
"Maksimov and Kolovsky, Equation (4)"
(+ (* J (- (exp l) (exp (- l))) (cos (/ K 2))) U))
(casio-bench (K m n M l)
(casio-test (K m n M l)
"Maksimov and Kolovsky, Equation (32)"
(* (cos (- (/ (* K (+ m n)) 2) M))
(exp (- (- (sqr (- (/ (+ m n) 2) M))) (- l (abs (- m n)))))))
Oops, something went wrong.

0 comments on commit f97d2f9

Please sign in to comment.