How to resolve the algorithm Faulhaber's formula step by step in the EchoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Faulhaber's formula step by step in the EchoLisp programming language

Table of Contents

Problem Statement

In mathematics,   Faulhaber's formula,   named after Johann Faulhaber,   expresses the sum of the p-th powers of the first n positive integers as a (p + 1)th-degree polynomial function of n,   the coefficients involving Bernoulli numbers.

Generate the first 10 closed-form expressions, starting with p = 0.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Faulhaber's formula step by step in the EchoLisp programming language

Source code in the echolisp programming language

(lib 'math) ;; for bernoulli numbers
(string-delimiter "")

;; returns list of polynomial coefficients
(define (Faulhaber p)
	(cons 0
	(for/list ([k (in-range p -1 -1)])
		(* (Cnp (1+ p) k) (bernoulli k)))))

;; prints formal polynomial
(define (task (pmax 10))
    (for ((p pmax)) 
    (writeln p '→  (/ 1 (1+ p)) '* (poly->string 'n (Faulhaber p)))))
    
;; extra credit - compute sums
(define (Faulcomp n p)
	(printf "Σ(1..%d) n^%d = %d" n p (/  (poly n (Faulhaber p)) (1+ p) )))


  

You may also check:How to resolve the algorithm Hello world/Text step by step in the Verbexx programming language
You may also check:How to resolve the algorithm Terminal control/Cursor movement step by step in the C# programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the Jsish programming language
You may also check:How to resolve the algorithm Inheritance/Single step by step in the Wren programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the F# programming language