History:
உலகின் முதல் நிரல் இயற்றிய அரசி அடா லவ்லேஸ், (Bernoulli numbers) பெர்னொல்லீ எண்களை கணக்கிட்டார்! #Computing #AdaLovelace #Ezhil
Bernoulli number’s have the historic significance in computer programming – Lady Ada Lovelace’s “first” computer program for the Babbage Analytical engine calculated the Bernoulli number sequence. Here we do the same operations using a slightly easier method of recursion using the recurrence relation:
Code:
You can see the full code listing at Ezhil-Language repository
# பெர்னொல்லீ எண்களை கணக்கிடு நிரல்பாகம் பெர்னொல்லீ_எண் ( m, n ) @( m == 0 ) ஆனால் # பெர்னொல்லீ_எண்( 0, n ) = 1 பின்கொடு 1.0 இல்லை பெர்னொல்லீ = 0.0 மொத்தம் = 0.0 எண்கள் = range(0,m) @(எண்கள் இல் இவ்வெண்) ஒவ்வொன்றாக மொத்தம் = மொத்தம் + binomial_coeff(m,இவ்வெண்)*பெர்னொல்லீ_எண்(இவ்வெண்,n)/(m - இவ்வெண் + 1.0) #பதிப்பி இவ்வெண், மொத்தம் முடி பெர்னொல்லீ = n^(m*1.0) - மொத்தம் பின்கொடு பெர்னொல்லீ முடி முடி
Tests:
You can run the code to verify the first few Bernoulli numbers:
B1 = பெர்னொல்லீ_எண்(1,0) பதிப்பி "B1 = B(1,0)", B1 assert( (B1 - 0.5) < 1e-3 ) பதிப்பி "B2 = B(2,0)", பெர்னொல்லீ_எண்(2,0) பதிப்பி "B4 = B(4,0)", பெர்னொல்லீ_எண்(4,0) B6 = பெர்னொல்லீ_எண்(6,0) பதிப்பி "B6 = B(6,0)", B6 assert( (B6 - 0.02380) < 1e-3 ) பதிப்பி "B4 = B(4,1)", பெர்னொல்லீ_எண்(4,1)
Credits: Photo from Flickr user.