Skip to content

Commit

Permalink
Merge branch 'main' into sritchie/proto
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie committed Apr 24, 2024
2 parents 9489e58 + f3ac544 commit 8de774d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/emmy/series.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -872,16 +872,18 @@
(defmethod g/exact? [::series] [_] false)
(defmethod g/exact? [::power-series] [_] false)
(defmethod g/freeze [::power-series] [^PowerSeries s]
(let [prefix (->> (g/simplify (take 4 (.-xs s)))
(g/freeze)
(filter (complement g/zero?))
(map-indexed
(fn [n a]
(if (g/one? a)
`(~'expt ~'_ ~n)
`(~'* ~a (~'expt ~'_ ~n))))))]
`(~'+ ~@prefix ~'...)))
(let [prefix (->> (g/simplify (take 4 (.-xs s)))
(g/freeze)
(into [] (comp
(map-indexed
(fn [n a]
(cond (g/zero? a) []
(g/one? a) [(list 'expt '_ n)]
:else [(list '* a (list 'expt '_ n))])))
cat)))]
`(~'+ ~@prefix ~'...)))

(defmethod g/freeze [::series] [^Series s]
(let [prefix (g/freeze
(g/simplify (take 4 (.-xs s))))]
`(~'+ ~@prefix ~'...)))
(let [prefix (g/freeze
(g/simplify (take 4 (.-xs s))))]
`(~'+ ~@prefix ~'...)))
12 changes: 11 additions & 1 deletion test/emmy/series_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,17 @@
(is (= "(+ (* 4 (expt _ 0)) (* 5 (expt _ 1)) (* 6 (expt _ 2)) (* 7 (expt _ 3)) ...)"
(str p)))
(is (= (str s) (str (g/freeze s))))
(is (= (str p) (str (g/freeze p))))))))
(is (= (str p) (str (g/freeze p))))

(is (= "(+ (expt _ 0) (* (/ -1 2) (expt _ 2)) ...)"
(str
(g/freeze s/cos-series)))
"cosine representation has the initial 1, drops correct zeros")

(is (= "(+ (expt _ 1) (* (/ -1 6) (expt _ 3)) ...)"
(str
(g/freeze s/sin-series)))
"sine representation drops correct zeros")))))

(deftest series-as-fn-tests
(let [f (fn [i] #(g/* %1 %2 i))
Expand Down

0 comments on commit 8de774d

Please sign in to comment.