Posted 23 May 2005 - 12:00 AM
3) Brute force (best match) approach, use: exact2(value,precision)
Define exact2(v,p)=exact2b(v,int(1/(4*p)),int(1/(2*p)))
Define exact2b(v,a,b)=exact2c(max(seq(intg(v*x)/x,x,a,b,1)),min(seq(-intg(-v*x)/x,x,a,b,1)),v)
Define exact2c(a,b,c)=piecewise(c-a<b-c,a,b)
Note:
The above is fast enough (15s) only for p>=0.01. Things would be MUCH faster even in Basic (CFX version I wrote some time ago is faster even though it displays partial matches). The problem is, Basic program on Classpad would be less useful, because you can't run Basic in Main. Of course, hardcoded function would be even better.
Pi is the only interesting number I know that has SO good precision at 355/113. Most of the non-fractional real numbers do not have fractional approximations that would be significantly (orders) better than decimal fraction up to the needed precision (compared to denominator)... This could be probably proven... anyone? So usefulness of exact(val,prec) function is questionable.
Just my two cents...
Best regards,
Lianna