flatten:= proc(x) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 1998 by Robert B. Israel. All rights reserved`; local d; if type(x,set) then op(map(flatten,[op(x)])) elif type(x,list) then op(map(flatten,x)) elif type(x,{table,array}) then if nargs = 2 and args[2] = false then op(map(flatten,[entries(x)])) else op(map(flatten@rhs,sort(op(-1,eval(x)),`flatten/comp`))) fi elif type(x,rtable) then d:=rtable_num_dims(x); if d = 0 then [] elif d = 1 then op(map(flatten,convert(x,list))) else op(map(flatten,convert(x,listlist))) fi else x fi end; `flatten/comp` := proc (s, t) options `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 1998 by Robert B. Israel. All rights reserved`; local is, it, ns, nt, R; is := op(1,s); it := op(1,t); ns := nops([is]); nt := nops([it]); if ns <> nt then RETURN(ns < nt) elif ns > 1 then if is[1] = it[1] then `flatten/comp`((is[2 .. ns])=0,(it[2 .. ns])=0) else `flatten/comp`(is[1]=0,it[1]=0) fi elif type([is, it],list(realcons)) then evalb(is < it) elif type([is, it],list(string)) then lexorder(is,it) else R := [is, it]; evalb(R = sort(R)) fi end;