1. I was thinking something along the lines of:
(defn new-partial-diff [p idx]
(vec
(for [expr p
:let [v (get expr idx)]
:when (not (zero? v))]
(-> expr
(update 0 * v)
(update idx dec)))))
(defn new-diff [p order]
(letfn [(diff-vars [p idx]
(map #(vector (conj idx %)
(new-partial-diff p %))
(range 1 (count (first p)))))
(diff-loop [n outer-acc polynomials]
(reduce (fn [acc [dervied-orders partial-derive]]
(if (< n order)
(let [next-ps (diff-vars partial-derive
(update dervied-orders 0 inc))]
(diff-loop (inc n)
(reduce (fn [x [y z]] (assoc-in x y z))
acc next-ps)
next-ps))
(assoc-in acc dervied-orders partial-derive)))
outer-acc polynomials))]
(diff-loop 0 {0 p} [[[0] p]])))
2, 3: My bad - I didn't realize that there's a usage guide under README.
On benchmarking, I believe there might be a slight error:
When using the original code:
Evaluation count : 490692 in 6 samples of 81782 calls.
Execution time mean : 1.235797 µs
Execution time std-deviation : 32.931879 ns
Execution time lower quantile : 1.198058 µs ( 2.5%)
Execution time upper quantile : 1.277707 µs (97.5%)
Overhead used : 11.260916 ns
When I changed
(map #(diff-loop (inc n) (diff-vars (first %) m (update (second %) 0 inc))) p)
to
(dorun (map #(diff-loop (inc n) (diff-vars (first %) m (update (second
%) 0 inc))) p))
Evaluation count : 1092 in 6 samples of 182 calls.
Execution time mean : 563.245309 µs
Execution time std-deviation : 18.833803 µs
Execution time lower quantile : 540.161599 µs ( 2.5%)
Execution time upper quantile : 582.791399 µs (97.5%)
Overhead used : 11.260916 ns
> --
> You received this message because you are subscribed to the Google Groups
> "Numerical Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
numerical-cloj...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.
--
Fu Yong Quah