diff --git a/src/kibit/rules/arithmetic.clj b/src/kibit/rules/arithmetic.clj index c4d8b69..456104a 100644 --- a/src/kibit/rules/arithmetic.clj +++ b/src/kibit/rules/arithmetic.clj @@ -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)] +) + diff --git a/test/kibit/test/arithmetic.clj b/test/kibit/test/arithmetic.clj index ab76034..c7c3fc8 100644 --- a/test/kibit/test/arithmetic.clj +++ b/test/kibit/test/arithmetic.clj @@ -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)))