Permalink
Browse files

Simplify zero? method and implement comparison of polynomial with roo…

…t type
  • Loading branch information...
1 parent 9c36124 commit a74c7083553e3ba4cbc1e17e1d8edc9dc7144495 @ray1729 committed Jun 12, 2010
Showing with 17 additions and 3 deletions.
  1. +17 −3 src/ray1729/clojure/polynomials.clj
@@ -90,14 +90,28 @@
; Comparison operations
;
-(defmethod gc/zero? ::polynomial
- [p]
- (every? zero? (vals (terms p))))
+(defmethod gc/zero? ::polynomial [p] (empty? (terms p)))
(defmethod gc/= [::polynomial ::polynomial]
[p q]
(and (= (variable p) (variable q)) (= (terms p) (terms q))))
+(defmethod gc/= [::polynomial root-type]
+ [p c]
+ (let [f (first (terms p))
+ r (rest (terms p))]
+ (and (zero? (key f))
+ (gc/= c (val f))
+ (empty? r))))
+
+(defmethod gc/= [root-type ::polynomial]
+ [c p]
+ (let [f (first (terms p))
+ r (rest (terms p))]
+ (and (zero? (key f))
+ (gc/= c (val f))
+ (empty? r))))
+
;
; Arithmetic operations
;

0 comments on commit a74c708

Please sign in to comment.