//SINGULAR MapleVRelase5 for UNIX/Linux
f:=x^10+x^9*y^2;
g:=y^8-x^2*y^7;
interface(prettyprint=0);
interface(echo=0);
writeto( singular_input );
lprint(`ideal I = `);
f, g ;
lprint(`;`);
writeto(terminal);
ring R=0,(x,y),dp;
< "singular_input";
short=0; // output in Maple format
ideal J=std(I);
write(":w maple_input",J);
SINGULARlink:=proc(I,P,tord)
local i,j,path,vars,F,p,ele;
F:=map(expand,I);
vars:=indets(F);
if P>0 then p:=P else p:=0 fi;
path:="Trans";
if assigned(pathname) then path:=cat(pathname,path) fi;
if system("mkdir ".path)<>0 then
ERROR("Couldn't make the Transfer-directory")
fi;
writeto(cat(path,"/In"));
lprint(`ring R =`);
lprint(``.p.`,`);
lprint(`(x(1..`.(nops(vars)).`)),`);
lprint(`(`.tord.`);`);
lprint(`ideal I =`);
for i to nops(F) do
if i>1 then lprint(`,`) fi;
ele:=subs([seq(vars[j]=x(j), j=1..nops(vars))],F[i]);
if type(ele,monomial) then lprint(ele)
else # split into summands, otherwise line might get chopped!
lprint(op(1,ele));
for j from 2 to nops(ele) do
lprint(`+`,op(j,ele))
od
fi
od;
lprint(`;`);
lprint(`short=0;`);
lprint(`ideal b = std(I);`);
lprint(`write(\"`.path.`/Out\",\"[\");`);
lprint(`write(\"`.path.`/Out\",b);`);
lprint(`write(\"`.path.`/Out\",\"];\");`);
lprint(`quit;`);
writeto(terminal);
system("Singular < ".path."/In > ".path."/temp");
if %<>0 then
system("'rm' -r ".path);
ERROR("Something went wrong while executing Singular")
fi;
read(cat(path,"/Out"));
F:=%;
system("'rm' -r ".path);
F:=subs([seq(x(i)=vars[i],i=1..nops(vars))],F);
F:=map(expand,F);
F
end:
f:=x^10+x^9*y^2;
g:=y^8-x^2*y^7;
J:=SINGULARlink([f,g],0,"dp"):
interface(prettyprint=0);
J;
proc maple_factorize(poly p)
{
int saveshort=short;
short=0;
string in="maple-in."+string(system("pid"));
string out="maple-out."+string(system("pid"));
link l=in;
write(l,"res:=factors("+string(p)+");");
write(l,"interface(prettyprint=0);");
write(l,"interface(echo=0);");
write(l,"writeto(`"+out+"`);");
write(l,"lprint(`ideal fac=`);");
write(l,"lprint(op(1,res));");
write(l,"for i to nops(op(2,res)) do");
write(l," lprint(`,`);");
write(l," lprint(op(1,op(i,op(2,res))));");
write(l,"od;");
write(l,"lprint(`;`);");
write(l,"lprint(`intvec multies=`);");
write(l,"lprint(`1`);");
write(l,"for i to nops(op(2,res)) do");
write(l," lprint(`,`);");
write(l," lprint(op(2,op(i,op(2,res))));");
write(l,"od;");
write(l,"lprint(`;`);");
write(l,"lprint(`list res=fac,multies;`);");
write(l,"writeto(terminal);");
write(l,"quit;");
int dummy=system("sh","maple <"+in+" > dummy");
if (dummy <> 0) { ERROR("something went wrong"); }
string r=read(out);
execute(r);
return(res);
}
ring R = 0,(x,y),dp;
poly f = (x-y)^2*(x+y);
maple_factorize(f);