Method on @sym: B = bernoulli (n)
Method on @sym: p = bernoulli (n, x)

Return symbolic Bernoulli numbers or Bernoulli polynomials.

With a sufficiently recent SymPy version, the first seven Bernoulli numbers are:

bernoulli (sym(0:6))
  ⇒ (sym) [1  1/2  1/6  0  -1/30  0  1/42]  (1×7 matrix)

Note there are two different definitions in use which differ in the sign of the value of B_1. As of 2023 and a sufficiently recent SymPy library, we use the definition with positive one half:

bernoulli (sym(1))
  ⇒ (sym) 1/2

Other examples:

bernoulli (sym(6))
  ⇒ (sym) 1/42
bernoulli (sym(7))
  ⇒ (sym) 0

Polynomial example:

syms x
bernoulli (2, x)
  ⇒ (sym)
       2       1
      x  - x + ─
               6

See also: @double/bernoulli, @sym/euler.

Package: symbolic