flatten



I wrote  (what is suppose to be) a clone of Macsyma Inc's flatten 
function. 
You can get my code from 
http://www.unk.edu/acad/math/people/willisb/home.html
Let me know if you have questions or find bugs in my code. 

;; Flatten is somewhat difficult to define -- essentially it evaluates an 
;; expression as if its main operator had been declared nary; however, 
there 
;; is a difference.  We have

;; (C1) load("flatten.lisp");
;; (D1)         flatten.lisp
;; (C2) flatten(f(g(f(f(x)))));
;; (D2)         f(g(f(f(x))))
;; (C3) declare(f,nary);
;; (D3)         DONE
;; (C4) ev(d2);
;; (D4)         f(g(f(x)))
;; (C5) 

;; Unlike declaring the main operator of an expression to be nary, flatten 

;; doesn't recurse into other function arguments. 

Here is a short demo using Maxima 5.5 under XP

(C2) load("l:/flatten/flatten.lisp")$
Loading l:/flatten/flatten.lisp
Finished loading l:/flatten/flatten.lisp
(C3) flatten([x,[y], [[z]]]);
(D3)                           [x, y, z]
(C4) flatten(f(f(f(g(x)))));
(D4)                            f(g(x))
(C5) m : matrix([a,b],[c,d])$
(C6) flatten(args(m));
(D6)                         [a, b, C, D]

I developed and tested flatten using Maxima 5.9.0rc3 under CMUCL.    On 
Mike Clarkson
advice (thank you), I installed the latest tcl and now xmaxima works.  By 
the way, 
installing tcl  and Maxima 5.9.0rc3 from sources and installing CMUCL went 
smoothly
for me even on my very outdated RedHat 6.2 box.

Barton