You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, here is a version of sicmutils.algebra.fold/kbk-n that generates summation functions that are 3-4x faster than using the fold. We COULD generate both...
(defn-klein-term"Takes symbolic variables for - `acc`, the accumulating term we're compensating for - `delta`, the shared symbol used for deltas and generates let-binding entries updating `acc` to `(+ acc delta)` and `delta` to the new compensation amount in `(+ acc delta)`."
[acc delta]
`[sum# (+ ~acc ~delta)
~delta (if (ud/fork:clj (>= (Math/abs ~acc)
(Math/abs ~delta))
:cljs (>= (.abs js/Math ~acc)
(.abs js/Math ~delta)))
(+ (- ~acc sum#) ~delta)
(+ (- ~delta sum#) ~acc))
~acc sum#])
(defmacro ^:no-doc kbk-n-sum"Given some order `n`, generates a function implementing fast `n`-th order Kahan-Babushka-Klein summation. See [[kbk-n]] for more detail."
[n]
(let [syms (into [] (repeatedly (inc n) gensym))
zeros (map (fn [i] `(~'double ~i)) (repeat0.0))
prefix (pop syms)
final (peek syms)
delta (gensym)]
`(fn [xs#]
(loop [i# (long0)
~@(interleave syms zeros)]
(let [~(with-meta delta {:tag 'double}) (nth xs# i# nil)]
(if (not ~delta)
(+ ~@syms)
(let [~@(mapcat #(klein-term % delta)
prefix)]
(recur (inc i#) ~@prefix (+ ~final ~delta)))))))))
The text was updated successfully, but these errors were encountered:
For example, here is a version of
sicmutils.algebra.fold/kbk-n
that generates summation functions that are 3-4x faster than using the fold. We COULD generate both...The text was updated successfully, but these errors were encountered: