--- /dev/null
+#lang racket
+
+(require "utils.rkt")
+
+(define (horner-eval x coefficient-sequence)
+ (accumulate (lambda (this-coeff higher-terms) (+ (* x this-coeff) higher-terms))
+ 0
+ coefficient-sequence))
+
+(horner-eval 2 '(1 3 0 5 0 1))
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(require "utils.rkt")
+
+(define (count-leaves t)
+ (accumulate +
+ 0
+ (map (lambda (x) (if (pair? x) (count-leaves x) 1)) t)))
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(require "utils.rkt")
+
+(define (accumulate-n op init seqs)
+ (if (null? (car seqs))
+ '()
+ (cons (accumulate op init (map car seqs))
+ (accumulate-n op init (map cdr seqs)))))
+
+(provide accumulate-n)
+
+;; (accumulate-n + 0 '((1 2 3) (4 5 6) (7 8 9) (10 11 12)))
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(require "utils.rkt"
+ "ex2_36.rkt")
+
+;; dot product
+(define (dot-product v w)
+ (accumulate + 0 (map * v w)))
+
+(define (matrix-*-vector m v)
+ (map (lambda (r) (dot-product r v)) m))
+
+;; (matrix-*-vector '((1 2 3 4) (4 5 6 6) (6 7 8 9)) '(1 2 3 4))
+
+(define (transpose m)
+ (accumulate-n cons '() m))
+
+;; (transpose '((1 2 3) (4 5 6) (7 8 9)))
+
+(define (matrix-*-matrix m n)
+ (let ([cols (transpose n)])
+ (map (lambda (v) (matrix-*-vector cols v)) m)))
+
+;; (matrix-*-matrix '((0 -1 2) (4 11 2)) '((3 -1) (1 2) (6 1)))
\ No newline at end of file