ZINTEL Gerhard <gerhard.zintel <at> faurecia.com> writes:
>
> Obviously I'm a bit stubborn, but in my mind optimized should give:
> block([%1,%2],
> %1:i+h+g,
> %2:%1*(f+e+d),
> %2*(c+b+a)
A little improvement:
inflag:true;
mostoften(e):=block([c,el,maxi,lv],lv:[],
if atom(e) then return(false),
if inpart(e,0)="*" then return(false),
if inpart(e,0)#"+" then return(false),
for x in args(e) do
if not(atom(x)) then
for y in args(x) do
if not(numberp(y)) then
(if numberp(subvar(c,y)) then ''(subvar(c,y)):subvar(c,y)+1
else (lv:cons(y,lv),''(subvar(c,y)):1)),
maxi:0,
for x in lv do
if c[x] > maxi then (maxi:subvar(c,x), el:x),
kill(c),
if maxi > 1 then return(el) else return(false));
rompe(e):=block([y],y:mostoften(e), if y=false then false else
[y,subst(1,y,e),subst(0,y,e)]);
da(e):= block([l],if not(atom(e)) and inpart(e,0)="*" then map(da,e) else
(l:rompe(e), if l=false then return(e) else
return(l[1]*(da(l[2]-l[3]))+da(l[3]))));
Example:
(%i5) e1:expand((a+b+c)*(d+e+f)*(g+h+i));
(%o5) c*f*i+b*f*i+a*f*i+c*e*i+b*e*i+a*e*i+c*d*i+b*d*i+a*d*i+c*f*h+
b*f*h+a*f*h+c*e*h+b*e*h+a*e*h+c*d*h+b*d*h+a*d*h+c*f*g+b*f*g+a*f*g+
c*e*g+b*e*g+a*e*g+c*d*g+b*d*g+a*d*g
(%i6) da(%);
(%o6)((c+b+a)*f+(c+b+a)*e+(c+b+a)*d)*i+((c+b+a)*f+(c+b+a)*e+(c+b+a)*d)*h+
((c+b+a)*f+(c+b+a)*e+(c+b+a)*d)*g
(%i7) da(%);
(%o7) ((c+b+a)*f+(c+b+a)*e+(c+b+a)*d)*(i+h+g)
(%i8) da(%);
(%o8) (c+b+a)*(f+e+d)*(i+h+g)
-Miguel