(01-03-2023 04:26 AM)Thomas Klemm Wrote: [ -> ] (01-02-2023 09:16 PM)Albert Chan Wrote: [ -> ]BTW, there was a typo, the number have no radix point.
Believe it or not, that was on purpose.
I get it now ... it is not a typo.
Test with horner's rule code that allowed variable base (in a table)
Code:
function peval(a, b, s)
s = s or 0
if type(b) == 'table' then
for i=1,#a do s = s*b[i] + a[i] end
else
for i=1,#a do s = s*b + a[i] end
end
return s
end
For example, 2 weeks 3 days 4 hours 5 minutes, convert to weeks only.
We could convert it all to minutes, then divide by minutes in 1 week.
lua> peval({2,3,4,5}, {1,7,24,60}), peval({1,0,0,0}, {1,7,24,60})
24725 10080
lua> 24725 / 10080
2.452876984126984
We could also do this in 1 shot: 2 + 1/7*(3 + 1/24*(4 + 1/60*5))
lua> peval({5,4,3,2}, {1,1/60,1/24,1/7})
2.452876984126984
Note: base first element is only a placeholder, that's why it stay put.
From Lua peval(a, b) code. With default s = 0, s*b[1] + a[1] = a[1]
As long as b[1] is finite, it will not affect result.
If we set s = a[1], and skip innermost factor, we get the same reult.
lua> peval({4,3,2}, {1/60,1/24,1/7}, 5)
2.452876984126984
(12-26-2022 02:00 PM)Thomas Klemm Wrote: [ -> ]\(
\begin{align}
\pi = 2 + \frac{1}{3}\left(2 + \frac{2}{5}\left(2 + \frac{3}{7}\left(2 + \cdots \right)\right)\right)
\end{align}
\)
Thus we can write in this specific basis: \(\pi = 2.2222\cdots\).
To make pi = (2.2222 ...)
b, we do the same way.
(2.2222)
b = (22222 / 10000)
b
lua> b = {1, 3/1, 5/2, 7/3, 9/4}
lua> peval({2,2,2,2,2}, b), peval({1,0,0,0,0}, b)
122 39.375
lua> 122 / 39.375 -- = 3 + 31/315
3.0984126984126985