I hope someone has solution. It looks very odd to me.

The function divides? is defined in

https://raw.githubusercontent.com/racket/math/master/math-lib/math/private/number-theory/divisibility.rkt

#lang typed/racket/base

(provide divides? coprime? pairwise-coprime? bezout)

;;;
;;; DIVISIBILITY
;;;

(: divides? : Integer Integer -> Boolean)
; a divides b <=> exists unique k s.t. a*k=b
(define (divides? a b)
  (cond [(zero? a)  #f]
        [else  (= (remainder b a) 0)]))




2015-08-24 12:41 GMT+02:00 Rickard Andersson <rickard.m.anders...@gmail.com>
:

> Hi,
>
> I noticed that the `divides?` function from math/number-theory seems to be
> a huge bottleneck for whatever reason.
>
> This seems strange to me, but I figured I'd write to the list to see if
> maybe there are trade-offs made that make sense mostly for big integers or
> something.
>
> Example with (time):
>
> #lang racket/base
>
> (require (only-in math/number-theory divides?))
>
> (define (divisible-by? x d)
>   (= (modulo x d)
>      0))
>
> (module+ main
>   (time
>     (for/sum ([x (in-range 3 500000000)])
>       (if (3 . divides? . x)
>         x
>         0))) ; cpu time: 96257 real time: 96166 gc time: 128
>   (time
>     (for/sum ([x (in-range 3 500000000)])
>       (if (x . divisible-by? . 3)
>         x
>         0))) ; cpu time: 7277 real time: 7266 gc time: 0
>   )
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to