%I #57 Sep 02 2024 14:47:39
%S 0,1,2,3,2,3,2,5,4,5,4,5,4,5,6,7,6,5,6,7,6,7,6,9,6,7,8,9,8,9,8
%N a(n) = maximal number of real roots of any of the 2^(n+1) polynomials c_0 + c_1*x + c_2*x^2 + ... + c_n*x^n where the coefficients c_i are +1 or -1.
%C The roots are counted with multiplicity.
%C Since (+/-)P((+/-)x) has the same number of real roots as P(x), we need consider only the cases where the x^0 and x^1 coefficients are +1. - _Robert Israel_, Feb 23 2017
%e a(1) = 1 from 1 + x.
%e a(2) = 2 from 1 + x - x^2.
%e a(3) = 3 from 1 + x - x^2 - x^3 = (1+x)*(1-x^2).
%e a(5) = 3 from x^5 - x^4 + x^3 - x^2 - x + 1. - _Robert Israel_, Feb 26 2017
%e a(7) = 5 from x^7 + x^6 - x^5 - x^4 - x^3 - x^2 + x + 1 = (x - 1)^2*(x + 1)^3*(x^2 + 1). - _Chai Wah Wu_ and _W. Edwin Clark_, Feb 23 2017
%p # Maple program using _Robert Israel_'s suggestion (above) for the computation of a(n) using Sturm's Theorem and the squarefree factorization of the 1,-1 polynomials, from _W. Edwin Clark_, Feb 23 2017:
%p numroots:=proc(p,x)
%p local s:
%p sturm(sturmseq(p,x),x,-infinity,infinity):
%p end proc:
%p a:=proc(n)
%p local m,T,L,L1,p,P,s,k,q,u;
%p m:=0;
%p T:=combinat:-cartprod([seq([1,-1],i=1..n-1)]):
%p while not T[finished] do
%p L:=T[nextvalue]();
%p L1:=[1,1,op(L)];
%p p:=add(L1[i]*x^(i-1),i=1..n+1);
%p q:=sqrfree(p,x);
%p k:=0;
%p for u in q[2] do k:=k+numroots(u[1],x)*u[2]; od;
%p if k > m then m:=k; fi;
%p end do:
%p return m;
%p end proc:
%t Do[Print[Max[CountRoots[Internal`FromCoefficientList[#, x], x] & /@ Tuples[{1, -1}, n]]], {n, 1, 23}] (* _Luca Petrone_, Feb 23 2017 *)
%o (Sage)
%o import itertools
%o def a(n):
%o if n==0: return 0
%o R = ZZ['x']; ans = 0
%o for c in itertools.product([-1,1], repeat=(n-1)):
%o p = R([1,1]+list(c))
%o num_roots = sum([f[0].number_of_real_roots()*f[1] for f in p.factor()])
%o ans = max(ans, num_roots)
%o return ans # _Robin Visser_, Sep 02 2024
%Y Cf. A282692, A282701.
%K nonn,more
%O 0,3
%A Oanh Nguyen and _N. J. A. Sloane_, Feb 23 2017
%E a(7) corrected and a(15)-a(16) added by _Chai Wah Wu_, Feb 23 2017; a(7) also corrected by _W. Edwin Clark_, Feb 23 2017
%E a(17)-a(22) added by _Luca Petrone_, Feb 23 2017
%E a(23) added by _W. Edwin Clark_, Feb 24 2017
%E a(24)-a(30) from _Robin Visser_, Sep 02 2024