Compose Functions
- Subject: Compose Functions
- From: Barton Willis
- Date: Fri, 17 Jun 2005 12:36:49 -0500
-----maxima-admin@math.utexas.edu wrote: -----
>Is there some function in Maxima, to work compose functions?
(%i1) infix("@")$
(%i2) infix("@n")$
(%i3) load("c:/maxima/compose.lisp")$
(%i4) f @ g;
(%o4) LAMBDA([X],f(g(X)))
(%i5) (f @ g)(a+b);
(%o5) f(g(b+a))
(%i6) (f @ (g @ h))(0);
(%o6) f(g(h(0)))
(%i7) (f @n 5)(w);
(%o7) f(f(f(f(f(w)))))
(%i8) f(x) := x^2$
(%i9) g(x) := x^3$
(%i10) (f @ g)(a);
(%o10) a^6
--start compose.lisp----------
(defun $@ (f g)
`((lambda) ((mlist) x) ((,f) ((,g) x))))
(defun $@n (f n)
(let ((acc `((,f) x)))
(decf n)
(dotimes (i n `((lambda) ((mlist) x) ,acc))
(setq acc `((,f) ,acc)))))
---end of file-----------------
Barton