Post Reply 
Setting a maximum demoninator for fractions
10-03-2023, 07:58 AM (This post was last modified: 10-03-2023 08:49 AM by komame.)
Post: #5
RE: Setting a maximum demoninator for fractions
(10-03-2023 05:54 AM)parisse Wrote:  Ouch, that's a very slow method. A faster way would be to compute the expansion in continued fraction and try the partial quotients obtained by list truncations.
l:=dfc(pi); dfc2f(l[1..2]); dfc2f(l[1..3]); etc.

I know this can be heavily optimized. I wrote it quickly as a PoC, but even for a denominator of 4095 (as Gary mentioned as the limit in HP35S), this program only needs 0.3s to produce the result, so it's not that bad Wink

Nonetheless, I also tried to follow the method you indicated, and I have a question about how to calculate this for PI with a maximum denominator of 5 using your method.
My approach shows
\(\cfrac{16}{5}\) for that,
but how do I do it with your method?

Also, I have a strange behavior in HOME and in CAS as well (maybe it's intended, but it seems strange to me).
First, I execute dfc:
Code:
v:=dfc(pi);
and I get vector in 'v':
[3, 7, 15, 1, 292, 1, 1, 1, 2]

Then, I calculate the first iteration:
Code:
f:=dfc2f(SUB(v,1,2))
and I get the result
\(\cfrac{22}{7}\)
but at the same time, 'v' has changed to
[3, 7].
Is it supposed to work this way?

PK
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Setting a maximum demoninator for fractions - komame - 10-03-2023 07:58 AM



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