Karim BELABAS on Mon, 28 Jun 1999 17:25:42 +0200 (MET DST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: divrem |
[Cc'ed to pari-users since it may be of general interest] [Rosita Wachenchauzer wrote on pari-dev (about gp-2.0.15):] > When the main variable is x, divrem works properly: > > ? p=-16*x^4+(y+1)*x^2 > %2 = -16*x^4 + (y + 1)*x^2 > ? q=x^2-1 > %3 = x^2 - 1 > ? divrem(p,q) > %4 = [-16*x^2 + (y - 15), y - 15]~ > ? reorder > %5 = [x, y, p, q] > but when the main variable is NOT x, then it does not work properly: > ? p > %7 = -16*y^4 + (x + 1)*y^2 > ? q > %8 = y^2 - 1 > ? reorder > %9 = [y, x, p, q] > ? divrem(p,q) > %10 = [(-16*y^6 + (x + 17)*y^4 + (-x - 1)*y^2)/(y^4 - 2*y^2 + 1), 0]~ User's Manual Chapter 3 : reorder({x = []}): [...] non-empty, it must be a permutation of variable names, and this permutation gives a new order of importance of the variables, for output only. For ^^^^^^^^^^^^^^^ example, if the existing order is [x,y,z], then after reorder([z,x]) the order of importance of the variables, with respect to output, will be [z,y,x]. The internal representation is unaffected. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For what you want to do, you'll need to substitute the variables before the computations. > By the way, all these bugs appear when I try to simulate maple commands > such as > rem(p,q,y) > Could you PLEASE add this feature (the possibility of choosing the > variable to perform an operation on polynomials) to the language? If you're not that bothered about efficiency, it's easy to do in GP: /* assumes MAXVAR is undefined, or at least 'MAXVAR != 'y */ rem(p,q, y) = { local(r); p = subst(p,'x, 'MAXVAR); q = subst(q,'x, 'MAXVAR); r = subst(p,y, 'x) % subst(q,y, 'x); subst(r,'MAXVAR, 'x) } Here's an idea for a generic solution (using a touch of black magic...): apply(f, p,q, y) = { local(r); p = subst(p,'x, 'MAXVAR); q = subst(q,'x, 'MAXVAR); r = Str("(" subst(p,y, 'x) ")" f "(" subst(q,y, 'x)")"); subst(eval(r),'MAXVAR, 'x) } Now apply("%", p,q, y) works in the same way as rem(p,q, y) =========================================================================== The whole concept of variable ordering in PARI is a big ad hoc kludge, in part due to the lack of a good internal representation for multivariate polynomials. To improve on that is on the TODO list, but it's highly non trivial and involves a lot of work. The kind of scripts I wrote above will have to do for a while... Karim. P.S: One more excerpt from the manual: Chapter 1: Although quite an amount of symbolic manipulation is possible in PARI, this system does very badly compared to much more sophisticated systems like Axiom, Macsyma, Magma, Maple, Mathematica or Reduce on such manipulations (e.g. multivariate polynomials, formal integration, etc...). __ Karim Belabas email: Karim.Belabas@math.u-psud.fr Dep. de Mathematiques, Bat. 425 Universite Paris-Sud Tel: (00 33) 1 69 15 57 48 F-91405 Orsay (France) Fax: (00 33) 1 69 15 60 19 -- PARI/GP Home Page: http://hasse.mathematik.tu-muenchen.de/ntsw/pari/