# uwplse/herbie

Recorded all problems and examples in Ch. 3 of NMSE

pavpanchekha committed Dec 5, 2013
1 parent 975256c commit 763250b594817b32aa1c4f22711bebf094ac1918
 @@ -0,0 +1,8 @@ #lang racket (require casio/test) (casio-test (x) "Hamming (NMSE) example 3.1, √(x+1) - √x" (- (sqrt (+ x 1)) (sqrt x)) (/ 1 (+ (sqrt (+ x 1)) (sqrt x))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) example 3.10, ln(1 - x)/ln(1+x)" (/ (log (- 1 x)) (log (+ 1 x))))
 @@ -0,0 +1,9 @@ #lang racket (require casio/racket) (casio-bench (x) "Hamming (NMSE) example 3.2, sin(x) / x" (if (= x 0) 1 (/ (sin x) x)))
 @@ -0,0 +1,8 @@ #lang racket (require casio/test) (casio-test (x eps) "Hamming (NMSE) example 3.3, sin(x + ε) - sin(x)" (- (sin (+ x eps)) (sin x)) (* 2 (* (cos (+ x (/ eps 2))) (sin (/ eps 2)))))
 @@ -0,0 +1,8 @@ #lang racket (require casio/test) (casio-test (x) "Hamming (NMSE) example 3.4, (1 - cos(x)) / sin(x)" (/ (- 1 (cos x)) (sin x)) (tan (/ x 2)))
 @@ -0,0 +1,8 @@ #lang racket (require casio/test) (casio-test (N) "Hamming (NMSE) example 3.5, atan(N + 1) - atan(N)" (- (atan (+ N 1)) (atan N)) (atan (/ 1 (+ 1 (* N (- N 1))))))
 @@ -0,0 +1,8 @@ #lang racket (require casio/test) (casio-test (x) "Hamming (NMSE) example 3.6, 1/√(x + 1) - 1/√x" (- (/ 1 (+ x 1)) (/ 1 x)) (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1))))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) example 3.7, e^x - x" (- (exp x) x))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (N) "Hamming (NMSE) example 3.8, (N+1) ln(N+1) - N ln(N) - 1" (- (- (* (+ N 1) (log (+ N 1))) (* N (log N))) 1))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) example 3.9, 1/x - ctn(x)" (- (/ 1 x) (cot x)))
 @@ -0,0 +1,9 @@ #lang racket (require casio/test) (casio-test (a x) "Hamming (NMSE) example in section 3.5" (- (exp (* a x)) 1) (if (< (abs (* a x)) 1/10) (* (* a x) (+ 1 (+ (/ (* a x) 2) (/ (expt (* a x) 2) 6)))) (- (exp (* a x)) 1)))
 @@ -0,0 +1,13 @@ #lang racket (require casio/test) (casio-bench (a b/2 c) "Hamming (NMSE) problem 3.2.1, the modified quadratic formula (first root)" (let* ((d (sqrt (- (* (* 2 b/2) (* 2 b/2)) (* 4 (* a c)))))) (/ (+ (* -2 b/2) d) (* 2 a)))) (casio-bench (a b/2 c) "Hamming (NMSE) problem 3.2.1, the modified quadratic formula (second root)" (let* ((d (sqrt (- (* (* 2 b/2) (* 2 b/2)) (* 4 (* a c)))))) (/ (+ (* -2 b/2) d) (* 2 a))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) problem 3.3.1, 1/(x + 1) - 1/x" (- (/ 1 (+ x 1)) (/ 1 x)))
 @@ -0,0 +1,7 @@ #lang racket (require casio/test) (casio-test (x eps) "Hamming (NMSE) problem 3.3.2, tan(x + ε) - tan(x)" (- (tan (+ x eps)) (tan x)) (/ (sin eps) (* (cos x) (cos (+ x eps)))))
 @@ -0,0 +1,7 @@ #lang racket (require casio/test) (casio-test (x) "Hamming (NMSE) problem 3.3.3, 1/(x + 1) - 2/x + 1/(x - 1)" (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))) (/ 2 (* x (- (* x x) 1))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-test (x) "Hamming (NMSE) problem 3.3.4, ³√(x + 1) - ³√x" (- (expt (+ x 1) (/ 1 3)) (expt x (/ 1 3))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-test (x eps) "Hamming (NMSE) problem 3.3.5, cos(x + ε) - cos(x)" (- (cos (+ x eps)) (cos x)))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (N) "Hamming (NMSE) problem 3.3.6, ln(N + 1) - ln(N)" (- (log (+ N 1)) (log N)))
 @@ -0,0 +1,7 @@ #lang racket (require casio/test) (casio-test (x) "Hamming (NMSE) problem 3.3.7, e^x - 2 + e^-x" (+ (- (exp x) 2) (exp (- x))) (* 4 (expt (sinh (/ x 2)) 2)))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) problem 3.4.1, (1 - (cos x)) / x^2" (/ (- 1 (cos x)) (expt x 2)))
 @@ -0,0 +1,7 @@ #lang racket (require casio/test) (casio-bench (a b eps) "Hamming (NMSE) problem 3.4.2" (/ (* eps (- (exp (* (+ a b) eps)) 1)) (* (- (exp (* a eps)) 1) (- (exp (* b eps)) 1))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) problem 3.4.3, log(1 - x / 1 + x)" (log (/ (- 1 x) (+ 1 x))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) problem 3.4.4, √(e^2x - 1 / e^x - 1)" (sqrt (/ (- (exp (* 2 x)) 1) (- (exp x) 1))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x) "Hamming (NMSE) problem 3.4.5, (x - sin(x)) / (x - tan(x))" (/ (- x (sin x)) (- x (tan x))))
 @@ -0,0 +1,6 @@ #lang racket (require casio/test) (casio-bench (x n) "Hamming (NMSE) problem 3.4.6, (x + 1)^(1/n) - x^(1/n)" (- (expt (+ x 1) (/ 1 n)) (expt x (/ 1 n))))
 @@ -0,0 +1,7 @@ #lang racket (require casio/test) (casio-test (x) "Hamming (NMSE) example in section 3.11" (/ (exp x) (- (exp x) 1)) (/ 1 (- 1 (exp (- x)))))
 @@ -1,15 +1,26 @@ #lang racket (require casio/test) ; quadratic formula (λ (a b c) (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (list (/ (+ (- b) d) (* 2 a)) (/ (- (- b) d) (* 2 a))))) (casio-test (a b c) "Hamming (NMSE) p42, the quadratic formula (first root)" (let* ((d (sqrt (- (* b b) (* 4 (* a c)))))) (/ (+ (- b) d) (* 2 a))) (let* ((d (sqrt (- (* b b) (* 4 (* a c))))) (r1 (/ (+ (- b) d) (* 2 a))) (r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2))))) ; Hamming's rewriting of the quadratic formula (λ (a b c) (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let* ((x1 (if (< b 0) (/ (+ (- b) d) (* 2 a)) (/ (- (- b) d) (* 2 a))) (x2 (/ c (* a x1))))) (list x1 x2)))) (casio-test (a b c) "Hamming (NMSE) p42, the quadratic formula (second root)" (let* ((d (sqrt (- (* b b) (* 4 (* a c)))))) (/ (+ (- b) d) (* 2 a))) (let* ((d (sqrt (- (* b b) (* 4 (* a c))))) (r1 (/ (+ (- b) d) (* 2 a))) (r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) r2 (/ c (* a r1)))))