Post Reply 
(12C+) Bernoulli Number
07-28-2019, 01:08 AM (This post was last modified: 07-28-2019 05:42 PM by Albert Chan.)
Post: #6
RE: (12C+) Bernoulli Number
Python code for Bernoulli Number (also return the forward difference table)
Code:
from fractions import Fraction

def B_fdiff(n):
    lst = [1,1] + [i**n for i in range(2, n+2)]
    for i in range(n):
        for j in range(n,i,-1): lst[j+1] -= lst[j]  # forward diff
        lst[0] = Fraction(lst[i+2],i+2) - lst[0]    # B(n) value
    return lst

>>> B_fdiff(6)
[Fraction(1, 42), 1, 63, 602, 2100, 3360, 2520, 720]

>>> for i in range(13): print i, B_fdiff(i)[0]
...
0 1
1 -1/2
2 1/6
3 0
4 -1/30
5 0
6 1/42
7 0
8 -1/30
9 0
10 5/66
11 0
12 -691/2730
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C+) Bernoulli Number - Gamo - 07-27-2019, 06:41 AM
RE: (12C+) Bernoulli Number - Albert Chan - 07-27-2019, 12:41 PM
RE: (12C+) Bernoulli Number - Gamo - 07-27-2019, 01:40 PM
RE: (12C+) Bernoulli Number - John Keith - 07-27-2019, 07:49 PM
RE: (12C+) Bernoulli Number - Albert Chan - 07-28-2019, 12:02 AM
RE: (12C+) Bernoulli Number - John Keith - 07-28-2019, 11:21 AM
RE: (12C+) Bernoulli Number - Albert Chan - 08-30-2023, 09:46 PM
RE: (12C+) Bernoulli Number - Albert Chan - 09-11-2023, 03:48 PM
RE: (12C+) Bernoulli Number - Albert Chan - 07-28-2019 01:08 AM
RE: (12C+) Bernoulli Number - Gamo - 07-28-2019, 02:29 AM
RE: (12C+) Bernoulli Number - Albert Chan - 07-31-2019, 05:14 PM
RE: (12C+) Bernoulli Number - Albert Chan - 09-12-2023, 05:59 PM



User(s) browsing this thread: 1 Guest(s)