Can someone give me an explanation as to how the following function works recursively. I can understand simpler recursive examples, but I don't understand how (smooth n (- k 1)) gives the value desired under the or statement here.
(define (divides a b)
(= (modulo b a) 0))
(define (smooth n k)
(and (>= k 2)
(or (divides k n)
(smooth n (- k 1)))))
(define (isprime p)
(if (< p 2)
#f
(not (smooth p (floor (sqrt p))))))
I wrote an isprime function that doesn't use 1 as a prime number, but I still don't quite understand how the above function works/how it works with this example.
smooth n k = Exists i In (k,k-1,...,2) SuchThat (n%i==0).isprime p = p>=2 && not (smooth p [sqrt p]). The name choice is unfortunate: smooth numbers are something else. The reverse testing order is better - numbers are more likely to have smaller factors than bigger factors.