/* Calculate the coefficients of an
   integral polynomial using Newton's
   method of repeated differences */

#include bob:string.polystr


/* Alter this by hand - a polynomial
   of degree < 8 */
f(x)
{ return ((1-x)*(1+x)); }

main()
{
 max = 8;
 c = newvector(max);
 for (i = 0; i < max; i++)
  c[i] = f(i);                // get values of f at 0, 1, ...
 for (i = 1; i < max; i++)
  for (j = max-1; j >= i; j--)
    {
     c[j] -= c[j-1];         // get repeated differences
     c[j] /= i;
    }
 for (i = max-2; i >= 0; i--)
  for (j = i; j < max-1; j++)
    c[j] -= i*c[j+1];        // get coefficients
 print(poly2str(c,"x"),"\n");
}
