From 0e215c74756a539a503a2fd8fe784e081778ab8c Mon Sep 17 00:00:00 2001 From: mehbark Date: Sun, 15 Jan 2023 20:36:26 -0500 Subject: [PATCH] remove redundant row-ops --- src/matrix/auto.clj | 3 ++- src/matrix/base.clj | 11 +++++++++++ src/matrix/core.clj | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) 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