-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexpand-power.sls
More file actions
39 lines (25 loc) · 772 Bytes
/
expand-power.sls
File metadata and controls
39 lines (25 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!r6rs
(library (mpl expand-power)
(export expand-power)
(import (mpl rnrs-sans)
(mpl misc)
(mpl arithmetic)
(mpl factorial)
(mpl expand-product))
(define (expand-power u n)
(if (sum? u)
(let ((f (list-ref u 1)))
(let ( (r (- u f)) )
(let loop ( (s 0)
(k 0) )
(if (> k n)
s
(let ((c (/ (! n)
(* (! k)
(! (- n k))))))
(loop (+ s
(expand-product (* c (^ f (- n k)))
(expand-power r k)))
(+ k 1)))))))
(^ u n)))
)