flatten:= proc(x) options `Maple Advisor Database 1.00 for Maple V Release 4 and 5`, `Copyright (c) 1998 by Robert B. Israel. All rights reserved`; 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 else x fi end; `flatten/comp` := proc (s, t) options `Maple Advisor Database 1.00 for Maple V Release 4 and 5`, `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;