added java.lang.Math-functions pow, hypot, round, expm1 and trivial identities

This commit is contained in:
Linus Ericsson 2013-09-11 18:15:09 +02:00 committed by Daniel Compton
parent e6ea25ec49
commit 5f442bc393
2 changed files with 50 additions and 2 deletions

View file

@ -7,5 +7,29 @@
[(- ?x 1) (dec ?x)]
[(* ?x (* . ?xs)) (* ?x . ?xs)]
[(+ ?x (+ . ?xs)) (+ ?x . ?xs)])
[(+ ?x (+ . ?xs)) (+ ?x . ?xs)]
;;trivial identites
[(+ ?x 0) ?x]
[(- ?x 0) ?x]
[(* ?x 1) ?x]
[(/ ?x 1) ?x]
[(* ?x 0) 0]
;;Math/pow
[(* ?x ?x) (Math/pow ?x 2) ]
[(* ?x ?x ?x) (Math/pow ?x 3) ]
[(* ?x ?x ?x ?x) (Math/pow ?x 4) ]
[(* ?x ?x ?x ?x ?x) (Math/pow ?x 5) ]
;;Math/hypot
[(Math/sqrt (+ (Math/pow ?x 2) (Math/pow ?y 2))) (Math/hypot ?x ?y)]
;;Math/expm1
[(dec (Math/exp ?x)) (Math/expm1 ?x)]
;;ugly rounding tricks
[(long (+ ?x 0.5)) (Math/round ?x)]
)

View file

@ -9,4 +9,28 @@
'(inc num) '(+ 1 num)
'(dec num) '(- num 1)
'(* x y z) '(* x (* y z))
'(+ x y z) '(+ x (+ y z))))
'(+ x y z) '(+ x (+ y z))
;;hypot
'(Math/hypot x y) '(Math/sqrt (+ (Math/pow x 2) (Math/pow y 2)))
'(Math/hypot x y) '(Math/sqrt (+ (* x x) (* y y)))
;;special exponential form
'(Math/expm1 x) '(- (Math/exp x) 1)
'(Math/expm1 x) '(dec (Math/exp x))
;;not that ugly rounding trick, thank you
'(Math/round x) '(long (+ x 0.5))
;;trivial identities
'x '(+ x 0)
'x '(- x 0)
'x '(* x 1)
'x '(/ x 1)
'0 '(* x 0)
;;pow
'(Math/pow x 5) '(* x x x x x)
'(Math/pow x 4) '(* x x x x)
'(Math/pow x 3) '(* x x x)
'(Math/pow x 2) '(* x x)))