(define (pairs-i a b)
(let ((out (list)) (x nil))
(for (y (if (odd? a) a (inc a)) b 2)
(if (1 (factor y)) (setf y nil) x (push (list x y) out -1))
(setf x y))
out))
You will gain a bit in speed for handling larger numbers by checking if the modulus of a prime product include any of the product primes. The code could be something like the following:
(define (pairs-i1 a b)
(let ((out (list)) (x nil) (FX (* 2 3 5 7 11 13)) (M 0))
(for (y (if (odd? a) a (inc a)) b 2)
(if (if (< y FX) (1 (factor y))
(or (= (setf M (% y FX))) (if (factor M) (<= ($it 0) 13)) (1 (factor y))))
(setf y nil)
x (push (list x y) out -1))
(setf x y))
out))
That example uses the prime product (* 2 3 5 7 11 13). For numbers greater than that, it checks if the modulus is a product of any of those primes, in which case the number as whole is divisible by that prime (and therefore not a prime itself). Notably, the factorization of the modulus is typically faster, and the end result is a faster filtering out of these. The speed up for handling large numbers is significant (~30%).