How to resolve the algorithm Faulhaber's triangle step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Faulhaber's triangle step by step in the Racket programming language
Table of Contents
Problem Statement
Named after Johann Faulhaber, the rows of Faulhaber's triangle are the coefficients of polynomials that represent sums of integer powers, which are extracted from Faulhaber's formula:
where
B
n
{\displaystyle B_{n}}
is the nth-Bernoulli number.
The first 5 rows of Faulhaber's triangle, are:
Using the third row of the triangle, we have:
∑
k
1
n
k
2
=
1 6
n +
1 2
n
2
1 3
n
3
{\displaystyle \sum _{k=1}^{n}k^{2}={1 \over 6}n+{1 \over 2}n^{2}+{1 \over 3}n^{3}}
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Faulhaber's triangle step by step in the Racket programming language
Source code in the racket programming language
#lang racket
(require math/number-theory)
(define (second-bernoulli-number n)
(if (= n 1) 1/2 (bernoulli-number n)))
(define (faulhaber-row:formulaic p)
(let ((p+1 (+ p 1)))
(reverse
(for/list ((j (in-range p+1)))
(* (/ p+1) (second-bernoulli-number j) (binomial p+1 j))))))
(define (sum-k^p:formulaic p n)
(for/sum ((f (faulhaber-row:formulaic p)) (i (in-naturals 1)))
(* f (expt n i))))
(module+ main
(map faulhaber-row:formulaic (range 10))
(sum-k^p:formulaic 17 1000))
(module+ test
(require rackunit)
(check-equal? (sum-k^p:formulaic 17 1000)
(for/sum ((k (in-range 1 (add1 1000)))) (expt k 17))))
You may also check:How to resolve the algorithm Pythagorean triples step by step in the Rust programming language
You may also check:How to resolve the algorithm Loops/For step by step in the REBOL programming language
You may also check:How to resolve the algorithm Bernstein basis polynomials step by step in the Python programming language
You may also check:How to resolve the algorithm Runtime evaluation step by step in the Insitux programming language
You may also check:How to resolve the algorithm Filter step by step in the J programming language