(define (limits M z) (let* ((ls arithmetic-shift) (p2 (λ (n) (ls 1 n))) (÷ quotient) (And bitwise-and) (num (p2 (+ M M z 2))) (topj (p2 (+ M z 1)))(msk (- (p2 54)))) (let dlp ((j (p2 (+ M z))) (maxlst #f)) (if (= j topj) maxlst ; α (let* ((df (ls j (- 52 (+ M z)))) (N (÷ num (+ j 1))) (Nd (* N df)) (nl (let rlp ((r (+ Nd Nd)) (ll '()) (rb 53)) (if (< rb 0) (cons (÷ r Nd) ll) (let* ((f (λ (x) (- (ls x M) (* (ls x -54) Nd))))) (rlp (max (f r) (f (- (And r msk) 1))) (cons (ls r -54) ll) (- rb M))))))) (dlp (+ j 1) (if maxlst (map max maxlst nl) nl))))))) ; This can be simplified and optimized but that might make it harder to understand. ; It is not easy to understand now. ; I think it agrees with b.c . (define (L M z) (list M z (limits M z))) (list (L 7 1) (L 7 2) (L 8 1) (L 8 2) (L 8 3) (L 9 1) (L 9 2)) ; => ( ;(7 1 (3 427 420 410 396 376 348 309 255)) ;(7 2 (2 322 321 319 315 309 299 282 255)) ;(8 1 (3 889 863 828 781 717 629 511)) ;(8 2 (2 642 638 630 618 598 565 511)) ;(8 3 (2 571 569 567 562 553 538 511)) ;(9 1 (3 1727 1658 1564 1436 1261 1023)) ;(9 2 (2 1306 1289 1261 1216 1142 1023)))