Bill Allombert on Sat, 16 Jun 2018 12:39:43 +0200


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

Re: Counting signs in a polynomial of many variables


On Sat, Jun 16, 2018 at 10:18:33AM +0000, Jacques Gélinas wrote:
> This works on the examples in EX, but signs(1/x) crashes GP.
> 
> 
> signs(p) = if(!#variables(p), sign(p),\
>        if(nvs(p=apply(signs,Vec(simplify(p)))), UNK, p[1]));
> 
> nvs(V) = my(r,s); sum(k=1,#V,if(s,r=s);s=V[k];r&s&(r!=s));
> 
> EX = [0, 1, -1, 0*x, 1+a*x^2, 1-a-b+n*a*b, exp(a*x), 1-x/tan(x)];
> 
> apply(signs,EX) == [0, 1, -1, 0, 1, UNK, 1, 1]

This is an infinite recursion: signs(1/x) is calling signs(1/x)

  ***   in function apply: ...bles(p),sign(p),if(nvs(p=apply(signs,Vec(simpl
  ***                                                  ^---------------------
  ***   in function apply: ...bles(p),sign(p),if(nvs(p=apply(signs,Vec(simpl
  ***                                                  ^---------------------
  *** apply: deep recursion.

Cheers,
Bill.