(wat-aro)

生きてます

SICP 問題 2.37

(define (dot-product v w)
  (accumulate + 0 (map * v w)))

(define (matrix-*-vector m v)
  (map (lambda (x) (dot-product x v)) m))

(define (transpose mat)
  (accumulate-n cons nil mat))

(define (matrix-*-matrix m n)
  (let ((cols (transpose n)))
    (map (lambda (x)
           (matrix-*-vector cols x))
         m)))
gosh> (matrix-*-vector '((1 2)
                        (3 4))
                      '(5 6))
(17 39)
gosh> (dot-product '(1 2) '(3 4))
11
gosh> (matrix-*-vector '((1 2)
                        (3 4))
                      '(5 6))
(17 39)
gosh> (matrix-*-matrix '((1 2 3)
                         (4 5 6))
                       '((7 10)
                         (8 11)
                         (9 12)))
((50 68) (122 167))