Expansion over a rectangle of real functions in Bernoulli polynomials and applications