Email list hosting service & mailing list manager


Re: Last call for comments on SRFI 179: Nonempty Intervals and Generalized Arrays (Updated) Bradley Lucier 03 May 2020 00:38 UTC

On 5/2/20 6:48 PM, John Cowan wrote:
> I'm still trying to understand how APL extends the inner product to more
> than two dimensions, but I can't grasp it.  However, such a procedure
> can go in another SRFI without a problem, as it can be layered over
> either SRFI 164 or SRFI 179 without loss of efficiency.

I just looked at

Mathematical Experiments on the Computer
by
ULF GRENANDER

He gives an (intentionally) inefficient example using outer products at
the end of Chapter 11, to find a bitmap that indicates the locations of
the prime numbers, beginning at 1.  Our example is much more verbose
than his APL, but it does pretty much the same thing:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define N 1001)

(define M (make-array (make-interval '#(1) (vector N))
                       (lambda (i) i)))

(define (bool->int bool) (if bool 1 0))

(define B
   (array-map
    (lambda (x)
      (bool->int (= x 2)))
    (array-map
     (lambda (row)
       (array-reduce + row))
     (array-curry
      (array-map
       (lambda (x)
         (bool->int (zero? x)))
       (array-outer-product
        modulo
        M M))
      1))))

(array-for-each (lambda (x)
                   (display x) (display #\space))
                 B)
(newline)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
which produces:

0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0
1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0
1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0
1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0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