//SINGULAR MuPad for UNIX/Linux SINGULARlink := proc(L:DOM_LIST, P:DOM_INT, tord) local i, path, ipath, opath, tpath, fd, vars, F, p; begin F := map(L, expand); vars := indets(F); if P > 0 then p := P; else p := 0; end_if; // Create the directory where "communication files" are stored path := "Trans"; if singpath <> hold(singpath) then path := pathname(singpath, path) ; end_if; if system("mkdir ".path) <> 0 then error("Could not make the Transfer-directory") end_if; // produce input for Singular ... ipath := pathname(path)."In" ; if version() = [2, 0, 0] then fd := fopen(Text, ipath, Write) ; else // MuPAD 2.5 fd := fopen(ipath, Write, Text) ; end_if ; // Define the ring (with term order) fprint(NoNL, fd, "ring R = "); fprint(NoNL, fd, p,", ("); fprint(NoNL, fd, vars[i], ", " ) $i=1..nops(vars)-1; fprint(NoNL, fd, vars[nops(vars)], "), "); fprint(Unquoted, fd, "( ",tord," ); "); // Define the ideal ... fprint(Unquoted, fd, "ideal I ="); fprint(Unquoted, fd, F[i], ", " ) $i=1..nops(F)-1; fprint(Unquoted, fd, F[nops(F)], ";"); fprint(Unquoted, fd, "short=0;"); fprint(Unquoted, fd, "ideal b = std(I);"); opath := pathname(path)."Out" ; fprint(Unquoted, fd, "write(\"".opath."\",\"[\");"); fprint(Unquoted, fd, "write(\"".opath."\",b);"); fprint(Unquoted, fd, "write(\"".opath."\",\"];\");"); fprint(Unquoted, fd, "quit;"); fclose(fd); // Call Singular ... tpath := pathname(path)."temp" ; if system("Singular < ".ipath."> ".tpath) <> 0 then system("rm -r ".path); error("Something went wrong while executing Singular"); end_if; // Retrieve the results ... F := read(opath, Quiet): system("rm -r ".path); F := map(F,expand); end_proc: f:=x^10+x^9*y^2; g:=y^8-x^2*y^7; J:=SINGULARlink([f,g],0,"dp"): output::tableForm(J,","); proc mupad_factorize(poly p) { int saveshort = short; short = 0; string in = "mupad-in."+string(system("pid")); string out = "mupad-out."+string(system("pid")); link l = in; write(l, "res:=factor("+string(p)+");"); write(l, "if version() = [2, 0, 0] then "); write(l, "fd := fopen(Text, \""+out+"\", Write) ;"); write(l, "else"); write(l, "fd := fopen(\""+out+"\", Write, Text) ;"); write(l, "end_if;"); write(l,"fprint(Unquoted, fd, \"ideal fac=\");"); write(l,"fprint(Unquoted, fd, op(res,1));"); write(l,"for i from 2 to nops(res) step 2 do"); write(l," fprint(Unquoted, fd, \",\", op(res,i));"); write(l,"end_for;"); write(l,"fprint(Unquoted, fd, \";\");"); write(l,"fprint(Unquoted, fd, \"intvec multies=\");"); write(l,"fprint(Unquoted, fd, \"1\");"); write(l,"for i from 3 to nops(res) step 2 do"); write(l," fprint(Unquoted, fd, \",\", op(res,i));"); write(l,"end_for;"); write(l,"fprint(Unquoted, fd, \";\");"); write(l,"fprint(Unquoted, fd, \"list res=fac,multies;\");"); write(l,"fclose(fd);"); write(l,"quit;"); int dummy = system("sh","mupad <"+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 = 5*(x-y)^2*(x+y); mupad_factorize(f);