diff --git a/src/matrix/auto.clj b/src/matrix/auto.clj new file mode 100644 index 0000000..6f63917 --- /dev/null +++ b/src/matrix/auto.clj @@ -0,0 +1,28 @@ +(ns matrix.auto + (:require [matrix.base :refer :all])) + +(defn get-before-bar-row + "Get the side of a row of an augmented matrix before the bar" + [r] + (let [width (count r) + to-take (dec width)] + (into [] (take to-take r)))) + +(defn get-before-bar + "Get the side of an augmented matrix before the bar" + [m] + (let [width (matrix-width m) + to-take (dec width)] + (->> m + (map get-before-bar-row) + (into [])))) + +(defn is-id-matrix + "Determines if a matrix is *exactly* the id-matrix" + [m] + (= (id-matrix (matrix-height m)) + m)) + +;; (defn apply-operations-with-steps +;; "Takes a matrix and a list of operations and returns a seq of matrices" +;; ) diff --git a/src/matrix/core.clj b/src/matrix/core.clj index ea4b180..c7daa86 100644 --- a/src/matrix/core.clj +++ b/src/matrix/core.clj @@ -1,6 +1,7 @@ (ns matrix.core (:require [matrix.base :refer :all]) (:require [matrix.interactive :refer :all]) + (:require [matrix.auto :refer :all]) (:gen-class)) (defn -main diff --git a/src/matrix/render.clj b/src/matrix/render.clj index af26752..06ae39f 100644 --- a/src/matrix/render.clj +++ b/src/matrix/render.clj @@ -1,7 +1,20 @@ +; TODO: actually use the render options lol, and merging provided with default + (ns matrix.render (:require [clojure.string :as str]) (:require [matrix.base :refer :all])) +(def default-render-options + {:bar? false + :bar-char "│" + + :tl-char "┏" + :tr-char "┓" + :bl-char "┗" + :br-char "┛" + + :pprint-row-ops? false}) + (defn surround-with "Surround a string with the given left and right" ([left right] #(surround-with left right %)) @@ -117,3 +130,48 @@ z (if (not-empty z) " ") "= " eq)))) + +(defn shrink-digit + "Takes a digit and returns the subscript version" + [d] + (case (str d) + "0" "₀" + "1" "₁" + "2" "₂" + "3" "₃" + "4" "₄" + "5" "₅" + "6" "₆" + "7" "₇" + "8" "₈" + "9" "₉")) + +(defn shrink-number + "Takes a number and returns the subscript version" + [n] + (str/join (map shrink-digit (str n)))) + +(defn pretty-swap [op] + (str "R" (shrink-number (:a op)) + " ↔ " + "R" (shrink-number (:b op)))) + +(defn pretty-mul [op] + (str (:n op) "R" (shrink-number (:row op)))) + +(defn pretty-add [op] + (let [n (if (= 1 (:n op)) + "" + (str (:n op)))] + (str n + "R" (shrink-number (:from op)) + " + " + "R" (shrink-number (:to op))))) + +(defn pretty-row-op + "Returns a pretty string of a row operation" + [op] + (cond + (:swap op) (pretty-swap op) + (:mul op) (pretty-mul op) + (:add op) (pretty-add op))) diff --git a/test/matrix/core_test.clj b/test/matrix/core_test.clj index 6748a50..d337a25 100644 --- a/test/matrix/core_test.clj +++ b/test/matrix/core_test.clj @@ -1,6 +1,6 @@ (ns matrix.core-test (:require [clojure.test :refer :all] - [matrix.core :refer :all])) + [matrix.base :refer :all])) (deftest test-mul-row (testing "Multiplying by one remains the same"