Charles Greathouse on Sat, 30 Sep 2023 03:06:42 +0200


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

Re: evaluation of Bernoulli polynomials


The implementation is straightforward:

GEN
bernpol_const(long k, GEN x)
{
  GEN C, S;
  long i;
  pari_sp btop;
  constbern(k >> 1); /* cache B_2, ..., B_2[k/2] */
  C = vecbinomial(k);
  S = gen_0;
  btop = avma;
  for (i = 0; i <= k; ++i)
  {
    S = gadd(gmul(S, x), gmul(gel(C,i+1), bernfrac(i)));
    if (gc_needed(btop, 1)) S = gerepileuptoint(btop, S);
  }
  return S;
}

(You could even delete the three lines doing garbage collection, bernpol_i doesn't bother.)

But I'd have to study the other examples to figure out how to handle an argument that can be a variable or a value, the parser codes will need to change.

On Fri, Sep 29, 2023 at 5:54 PM Max Alekseyev <maxale@gmail.com> wrote:
CORRECTION: polchebyshev() example was not complete - I meant to show this:

? polchebyshev(7,2,2)
%3 = 10864

On Fri, Sep 29, 2023 at 5:44 PM Max Alekseyev <maxale@gmail.com> wrote:
Most named polynomials in PARI allow upfront evaluation at a given point - like

? polcyclo(7,2)
%1 = 127
? polchebyshev(7,2)
%2 = 128*x^7 - 192*x^5 + 80*x^3 - 8*x

However, this is not the case with Bernoulli polynomials:

? bernpol(7,2)
  ***   variable name expected: bernpol(7,2)
  ***                                     ^--

Can this be fixed please?

PS. On a cosmetic side, bernpol() should have been better called polbern() to be consistent with naming of other pol*() functions.

Regards,
Max