I'm trying to speed up computing terms of a simple recurrence where
the terms are computed modulo some value each iteration,
(defn NF-mod-limit [p q limit]
(loop [n 0, nf 0, z 0, S 290797]
(if (= n (inc q)) nf
(recur (inc n)
(mod (+ nf (* (mod S p) z)) limit)
(mod (inc (* p z)) limit)
(mod (* S S) 50515093))))))
So I added in some type hinting,
(defn NF-mod-limit [p q limit]
(let [p (long p) q (long q) limit (long limit)]
(loop [n (long 0), nf (long 0), z (long 0), S (long 290797)]
(if (= n (inc q)) nf
(recur (inc n)
(long (mod (+ nf (* (long (mod S p)) z)) limit))
(long (mod (inc (* p z)) limit))
(long (mod (* S S) 50515093)))))))
But it doesn't run any faster. Also it doesn't work without casting
to long within the recur. Is that maybe a problem with mod and
primitive arithmetic or does this simply not speed up any more in
Clojure?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en