Post Reply 
50G fraction question Q-> function max denominator
11-09-2019, 01:46 PM
Post: #18
RE: 50G fraction question Q-> function max denominator
(11-08-2019 09:01 PM)Joe Horn Wrote:  Albert's method automatically does that, if you use a power of 2 for D, no?

(11-08-2019 10:05 PM)Albert Chan Wrote:  x' = round(x D) / D will gives you the same answer (for this case D = 2^n)

Perhaps it is easier to visualize if you consider denominator as the maximum D
In other words, fraction is not (yet) allowed to be simplified

x = (x D) / D = y / D

x' = y' / D, y' an integer

Now, what integer value of y' will minimize error ? y' = round(y)

error = |x - x'| = |y - y'| / D ≤ 0.5 / D

OIC (Oh, I see!)

So changes are in order for my last program:
1) The maximum denominator (D in your explanation) will need to be "pinned" to the greatest power-of-2 ≤ the given value
2) After determining a,b,c in 'a+b/c', the GCD for b and c will be used to simplify the rational

I'm building the rational manually instead of using the CAS so that the program is flag-agnostic (I want it to behave the same way regardless of flag settings). I also prefer -(1+1/2) to -1+-1/2 when displaying negative symbolics, which is easily done by placing the negation as its final component. I find the former easier to read than the latter when on the stack.

Thanks to both of you for the education!
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: 50G fraction question Q-> function max denominator - DavidM - 11-09-2019 01:46 PM

User(s) browsing this thread: