Ilya Zakharevich on Sun, 23 Feb 2003 01:17:32 -0800 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PATCH CVS] yet better subst() |
This patch a) removes a stupid lift(Mod(pol,M), variable(M)) which should be equivalent to pol % M; b) enables substitution of rational expressions, as below. Enjoy, Ilya ? subst(x^2,(x^2+1)/(x^2-1),t) -t - 1 %1 = ------ -t + 1 ? subst(%1,t,(x^2+1)/(x^2-1)) \\ test the previous one 2 %2 = x --- ./src/basemath/gen3.c~ Sat Feb 22 18:58:44 2003 +++ ./src/basemath/gen3.c Sun Feb 23 01:12:00 2003 @@ -1318,8 +1318,11 @@ gconvsp(GEN x, int flpile) subst_poly(pol, from, to) = { local(t='subst_poly_t, M); + \\ if fraction + M = numerator(from) - t * denominator(from); + \\ else M = from - t; - subst(lift(Mod(pol,M), variable(M)),t,to) + subst(pol % M, t, to) } */ GEN @@ -1327,15 +1330,19 @@ gsubst_expr(GEN pol, GEN from, GEN to) { pari_sp av = avma; long v = fetch_var(); /* XXX Need fetch_var_low_priority() */ - GEN tmp = gsub(from, polx[v]); /* M */ + GEN tmp; + + switch (typ(from)) { + case t_RFRAC: case t_RFRACN: /* M= numerator(from) - t * denominator(from) */ + tmp = gsub((GEN)from[1], gmul(polx[v], (GEN)from[2])); + break; + default: + tmp = gsub(from, polx[v]); /* M = from - t */ + } if (v <= gvar(from)) err(talker, "subst: unexpected variable precedence"); - tmp = gmodulcp(pol, tmp); - if (typ(tmp) == t_POLMOD) - tmp = (GEN)tmp[2]; /* optimize lift */ - else /* Vector? */ - tmp = lift0(tmp, gvar(from)); + tmp = gmod(pol, tmp); tmp = gsubst(tmp, v, to); (void)delete_var(); return gerepilecopy(av, tmp);