管理员 on Sun, 04 Jan 2026 01:37:51 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Implementation of trans_eval2


GEN trans_eval2(const char *fun, void *E, GEN (*f)(void*,GEN,GEN,long), GEN x, GEN y, long prec) {
	pari_sp av = avma, av2;
	long i, lx = 0, ly = 0, l = 0, t = 0;
	GEN X, Y, res;

	if (prec < LOWDEFAULTPREC) pari_err_BUG("trans_eval [prec < 3]");
	if (is_matvec_t(typ(x))) lx = lg(x);
	if (is_matvec_t(typ(y))) ly = lg(y);
	if (!lx && !ly) {
		if (typ(x) == t_POLMOD) { x = polmod_to_embed(x,prec); lx = lg(x); }
		if (typ(y) == t_POLMOD) { y = polmod_to_embed(y,prec); ly = lg(y); }
		if (!lx && !ly) {
			if (is_const_t(typ(x)) && !isinexact(x)) x = gtofp(x,prec);
			if (is_const_t(typ(y)) && !isinexact(y)) y = gtofp(y,prec);
			if (av != avma) return gerepileupto(av,f(E,x,y,prec));
		}
	}
	if (!lx == !ly) pari_err_TYPE2(fun,x,y);
	if (lx) {
		l = lx; t = typ(x);
	} else {
		l = ly; t = typ(y);
	}

	av2 = avma;
	res = cgetg(l, t);
	for (i = 1; i < l; i++) {
		X = lx ? gel(x,i) : x;
		Y = ly ? gel(y,i) : y;
		gel(res,i) = f(E,X,Y,prec);
	}
	if (av != av2) res = gerepileupto(av,res);
	return res;
}