## "Fossies" - the Fresh Open Source Software Archive

### Source code changes of the file "src/basemath/gen3.c" betweenpari-2.13.0.tar.gz and pari-2.13.1.tar.gz

About: PARI/GP is a computer algebra system designed for fast computations in number theory (factorizations, algebraic number theory, elliptic curves...), but also contains a large number of other mathematical functions.

gen3.c  (pari-2.13.0):gen3.c  (pari-2.13.1)
skipping to change at line 1453 skipping to change at line 1453
l = lg(a); z = cgetg(l,t_POL); z[1] = a[1]; l = lg(a); z = cgetg(l,t_POL); z[1] = a[1];
for (i = 2; i < l; i++) gel(z,i) = gmodulo(gel(a,i),b); for (i = 2; i < l; i++) gel(z,i) = gmodulo(gel(a,i),b);
return normalizepol_lg(z, l); return normalizepol_lg(z, l);
} }
GEN GEN
gsubst(GEN x, long v, GEN y) gsubst(GEN x, long v, GEN y)
{ {
long tx = typ(x), ty = typ(y), lx = lg(x), ly = lg(y); long tx = typ(x), ty = typ(y), lx = lg(x), ly = lg(y);
long l, vx, vy, ex, ey, i, j, k, jb, matn; long l, vx, vy, ex, ey, i, j, k, jb, matn;
pari_sp av, av2; pari_sp av, av2;
GEN X, t, z; GEN X, t, z;
switch(ty) switch(ty)
{ {
case t_VEC: case t_COL: case t_VEC: case t_COL:
return gsubst_v(x, v, y); return gsubst_v(x, v, y);
case t_MAT: case t_MAT:
if (ly==1) return cgetg(1,t_MAT); if (ly==1) return cgetg(1,t_MAT);
if (ly == lgcols(y)) { matn = ly - 1; break; } if (ly == lgcols(y)) { matn = ly - 1; break; }
/* fall through */ /* fall through */
case t_QFR: case t_QFI: case t_QFR: case t_QFI:
skipping to change at line 1565 skipping to change at line 1565
z = gadd(gmul(y,z), gel(x,i)); z = gadd(gmul(y,z), gel(x,i));
if (gc_needed(av,1)) if (gc_needed(av,1))
{ {
if(DEBUGMEM>1) pari_warn(warnmem,"gsubst (i = %ld)", i); if(DEBUGMEM>1) pari_warn(warnmem,"gsubst (i = %ld)", i);
z = gerepileupto(av, z); z = gerepileupto(av, z);
} }
} }
if (ex) z = gmul(z, gpowgs(y,ex)); if (ex) z = gmul(z, gpowgs(y,ex));
return gerepileupto(av,z); return gerepileupto(av,z);
} }
l = (lx-2)*ey2; l = (lx-2)*ey + 2;
if (ex) { if (l>ly) l = ly; } if (ex) { if (l>ly) l = ly; }
else if (lx != 3) else if (lx != 3)
{ {
for (i = 3; i < lx; i++) for (i = 3; i < lx; i++)
if (!isexactzero(gel(x,i))) break; if (!isexactzero(gel(x,i))) break;
= (i-2)*ey + (gequal0(y)? 2 : l = minss(l, (i-2)*ey + (gequal0(y)? 2 : ly));
} }
av = avma; av = avma; t = leafcopy(y);
t = leafcopy(y);
if (l < ly) setlg(t, l); if (l < ly) setlg(t, l);
z = z = scalarser(gen_1, varn(y), l-2);
for gel(z,2) = gel(x,2); /* ensure lg(z) = l even if x[2] = 0 */
for (i = 3, jb = ey; jb <= l-2; i++,jb += ey)
{ {
if (i < lx) { if (i < lx) {
for (jminss(l, jb+ly); j++) for (j = jb+2; j < minss(l, jb+ly); j++)
gel(z,j) = gadd(gel(z,j), gmul(gel(x,i),gel(t,j-jb))); gel(z,j) = gadd(gel(z,j), gmul(gel(x,i),gel(t,j-jb)));
} }
for (j1; j--) for (j = minss(ly-1, l-1-jb-ey); j > 1; j--)
{ {
= GEN a = gmul(gel(t,2), gel(y,j));
for (k=2; k<j; k++) for (k=2; k<j; k++) a = gadd(a, gmul(gel(t,j-k+2), gel(y,k)));
= gel(t,j) = a;
gel(t,j) =
} }
if (gc_needed(av,1)) if (gc_needed(av,1))
{ {
if(DEBUGMEM>1) pari_warn(warnmem,"gsubst"); if(DEBUGMEM>1) pari_warn(warnmem,"gsubst");
gerepileall(av,2, &z,&t); gerepileall(av,2, &z,&t);
} }
} }
if (!ex) return gerepilecopy(av,z); if (!ex) return gerepilecopy(av,z);
return gerepileupto(av, gmul(z,gpowgs(y, ex))); return gerepileupto(av, gmul(z, gpowgs(y, ex)));
case t_POL: case t_RFRAC: case t_POL: case t_RFRAC:
{ {
long N, n = lx-2; long N, n = lx-2;
vy = gvar(y); ey = gval(y,vy); vy = gvar(y); ey = gval(y,vy);
if (ey == LONG_MAX) if (ey == LONG_MAX)
{ /* y = 0 */ { /* y = 0 */
if (ex < 0) pari_err_INV("gsubst",y); if (ex < 0) pari_err_INV("gsubst",y);
if (!n) return gcopy(x); if (!n) return gcopy(x);
if (ex > 0) return Rg_get_0(ty == t_RFRAC? gel(y,2): y); if (ex > 0) return Rg_get_0(ty == t_RFRAC? gel(y,2): y);
y = Rg_get_1(ty == t_RFRAC? gel(y,2): y); y = Rg_get_1(ty == t_RFRAC? gel(y,2): y);
return gmul(y, gel(x,2)); return gmul(y, gel(x,2));
} }
if (ey < 1 || n == 0) return zeroser(vy, ey*(ex+n)); if (ey < 1 || n == 0) return zeroser(vy, ey*(ex+n));
av = avma; av = avma;
n *= ey; n *= ey;
N = ex? n: maxss(n-ey,1); N = ex? n: maxss(n-ey,1);
y = (ty == t_RFRAC)? rfrac_to_ser(y, N+2): RgX_to_ser(y, N+2); y = (ty == t_RFRAC)? rfrac_to_ser(y, N+2): RgX_to_ser(y, N+2);
if (lg(y)-2 > n) setlg(y, n+2); if (lg(y)-2 > n) setlg(y, n+2);
x = ser2pol_i(x, lx); x = ser2pol_i(x, lx);
if (varncmp(vy,vx) > 0) if (varncmp(vy,vx) > 0)
z = gadd(poleval(x, y), zeroser(vy,n)); z = gadd(poleval(x, y), zeroser(vy,n));
else else
{ {
z = RgXn_eval(x, ser2rfrac_i(y), n); z = RgXn_eval(x, ser2rfrac_i(y), n);
if (varn(z) == vy) z = RgX_to_ser(z, n+2); if (varn(z) == vy) z = RgX_to_ser(z, n+2);
} }
switch(typ(z)) switch(typ(z))
{ {
case t_SER: case t_SER:
case t_POL: case t_POL:
if (varncmp(varn(z),vy) <= 0) break; if (varncmp(varn(z),vy) <= 0) break;
default: z = scalarser(z, vy, n); default: z = scalarser(z, vy, n);
} }
if if (!ex) return gerepilecopy(av, z);
return gerepilecopy(av, z); return gerepileupto(av, gmul(z, gpowgs(y,ex)));
return gerepileupto(av,
} }
default: default:
if (isexactzero(y)) if (isexactzero(y))
{ {
if (ex < 0) pari_err_INV("gsubst",y); if (ex < 0) pari_err_INV("gsubst",y);
if (ex > 0) return gcopy(y); if (ex > 0) return gcopy(y);
if (lx > 2) return gadd(gel(x,2), y); /*add maps to correct ring*/ if (lx > 2) return gadd(gel(x,2), y); /*add maps to correct ring*/
} }
pari_err_TYPE2("substitution",x,y); pari_err_TYPE2("substitution",x,y);
} }
break; break;
case t_RFRAC: case t_RFRAC:
{
return gerepileupto(av, GEN a = gel(x,1), b = gel(x,2);
av = avma;
a = gsubst(a, v, y);
b = gsubst(b, v, y); return gerepileupto(av, gdiv(a, b));
}
case t_VEC: case t_COL: case t_MAT: case t_VEC: case t_COL: case t_MAT:
z = cgetg_copy(x, &lx); z = cgetg_copy(x, &lx);
for (i=1; i<lx; i++) gel(z,i) = gsubst(gel(x,i),v,y); for (i=1; i<lx; i++) gel(z,i) = gsubst(gel(x,i),v,y);
return z; return z;
case t_LIST: case t_LIST:
z = mklist(); z = mklist();
list_data(z) = list_data(x)? gsubst(list_data(x),v,y): NULL; list_data(z) = list_data(x)? gsubst(list_data(x),v,y): NULL;
return z; return z;
} }
End of changes. 14 change blocks.
25 lines changed or deleted 22 lines changed or added