Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Bugfix: ensure that build-term-list suppreses terms with zero coeffic…

  • Loading branch information...
1 parent 9862da3 commit 6341e745f60da24a9e56e724164d942991999264 @ray1729 committed
Showing with 5 additions and 4 deletions.
  1. +5 −4 src/ray1729/clojure/polynomials.clj
9 src/ray1729/clojure/polynomials.clj
@@ -34,10 +34,11 @@
[accum terms]
(if (empty? terms) accum
- (let [[order coeff] (first terms)]
- (if (gc/zero? coeff)
- (recur accum (rest terms))
- (recur (assoc accum order (ga/+ (get accum order 0) coeff)) (rest terms))))))]
+ (let [[order coeff] (first terms)
+ new-coeff (ga/+ (get accum order 0) coeff)]
+ (if (gc/zero? new-coeff)
+ (recur (dissoc accum order) (rest terms))
+ (recur (assoc accum order new-coeff) (rest terms))))))]
(build-term-list (sorted-map) (partition 2 (canonicalize-terms terms)))))
(deftype ::polynomial polynomial

0 comments on commit 6341e74

Please sign in to comment.
Something went wrong with that request. Please try again.