diff --git a/src/matrix/auto.clj b/src/matrix/auto.clj index dbe4df4..cd0e181 100644 --- a/src/matrix/auto.clj +++ b/src/matrix/auto.clj @@ -76,7 +76,8 @@ after-g-elim (apply-all-at-once m g-elim-steps) bsub-steps (back-sub after-g-elim) after-bsub (apply-all-at-once after-g-elim bsub-steps)] - [(concat g-elim-steps bsub-steps) + [(filter (comp not is-redundant) + (concat g-elim-steps bsub-steps)) after-bsub])) (def auto-steps (comp first auto-steps-and-final)) diff --git a/src/matrix/base.clj b/src/matrix/base.clj index b8aad46..601e213 100644 --- a/src/matrix/base.clj +++ b/src/matrix/base.clj @@ -113,3 +113,14 @@ (map #(map f %)) (map to-vec) to-vec))) + +(defn is-redundant + "Takes a row op and returns whether it IS redundant" + [op] + (if-let [[op-type inner] (opspec/conform op)] + (case op-type + :swap (= (:swap inner) ; swapping a row with itself + (:with inner)) + :add (= 0 (:times inner)) ; adding 0 times a row to another row + :mul (= 1 (:by inner)) ; multiplying a row by 1 + ))) diff --git a/src/matrix/core.clj b/src/matrix/core.clj index c051ae4..7fec08c 100644 --- a/src/matrix/core.clj +++ b/src/matrix/core.clj @@ -25,4 +25,4 @@ ; DONE: solving id-matrix ; DONE: solving gaussian-eliminated matrix ; DONE: automation -; TODO: remove redundant row ops +; DONE: remove redundant row ops