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)
Any ideas about this?
On May 2, 1:44 am, Brian Watkins wrote:
> 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
>
On Mon, May 3, 2010 at 4:21 PM, Brian Watkins wrote:
> Any ideas about this?
>
> On May 2, 1:44 am, Brian Watkins wrote:
> > 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]
> >
Using unchecked-remainder and adding a type declaration to the last
constant keeps the primitives unboxed and improves performance by a
factor of 6 for me. I couldn't say whether there's a reason rem and
mod don't work like you'd expect here.
(defn NF-mod-limit [p q limit]
(let [p (long p) q (lo
The main example is
(NF-mod-limit 61 1000 (reduce * (repeat 10 61)))
It runs in about 10 seconds but this is somewhat typical of other
computations I want to be able to do that take longer. I'd just like
to be able to make the integer math as fast as is reasonable in
Clojure.
I'll try rem f
Thank you for the pointer to unchecked-remainder. That runs much
better.
-B
On May 3, 6:23 pm, kaukeb wrote:
> Using unchecked-remainder and adding a type declaration to the last
> constant keeps the primitives unboxed and improves performance by a
> factor of 6 for me. I couldn't say whether t
Brian Watkins writes:
> I'll try rem for time but I see that I still have to cast to long;
> Clojure doesn't think (rem (long ) (long x)) is a long. The
> error is "recur arg for primitive local: nf must be matching
> primitive."
Looks like it's casting it back to an integer. Also look