50G fraction question Q-> function max denominator
11-09-2019, 01:46 PM
Post: #18
 DavidM Senior Member Posts: 979 Joined: Dec 2013
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!
 « Next Oldest | Next Newest »

 Messages In This Thread 50G fraction question Q-> function max denominator - 100LL - 10-24-2019, 02:58 PM RE: 50G fraction question Q-> function max denominator - ijabbott - 10-24-2019, 04:24 PM RE: 50G fraction question Q-> function max denominator - burkhard - 10-24-2019, 09:09 PM RE: 50G fraction question Q-> function max denominator - Joe Horn - 10-24-2019, 09:59 PM RE: 50G fraction question Q-> function max denominator - cdmackay - 10-24-2019, 11:02 PM RE: 50G fraction question Q-> function max denominator - Joe Horn - 10-25-2019, 05:26 AM RE: 50G fraction question Q-> function max denominator - 100LL - 10-25-2019, 01:47 PM RE: 50G fraction question Q-> function max denominator - cdmackay - 10-25-2019, 04:52 PM RE: 50G fraction question Q-> function max denominator - 100LL - 10-25-2019, 09:42 PM RE: 50G fraction question Q-> function max denominator - Joe Horn - 10-25-2019, 11:42 PM RE: 50G fraction question Q-> function max denominator - ijabbott - 10-26-2019, 08:56 AM RE: 50G fraction question Q-> function max denominator - DavidM - 10-29-2019, 02:16 PM RE: 50G fraction question Q-> function max denominator - DavidM - 11-08-2019, 05:54 PM RE: 50G fraction question Q-> function max denominator - Albert Chan - 11-08-2019, 07:01 PM RE: 50G fraction question Q-> function max denominator - DavidM - 11-08-2019, 08:43 PM RE: 50G fraction question Q-> function max denominator - Joe Horn - 11-08-2019, 09:01 PM RE: 50G fraction question Q-> function max denominator - Albert Chan - 11-08-2019, 10:05 PM RE: 50G fraction question Q-> function max denominator - DavidM - 11-09-2019 01:46 PM

User(s) browsing this thread: