If I understand you correctly, you're recommending the following sequence of operations: To find a Pythagorean approximation for floating point (x+iy)/|x+iy|. Denote atan2(y,x) by phi. So tan(phi)=y/x, cos(phi)=x/sqrt(x^2+y^2), sin(phi)=y/sqrt(x^2+y^2). What we really want is a rational approximation to tan(phi/2). tan(phi/2) = sin(phi)/(1+cos(phi)) = y/(sqrt(x^2+y^2)+x), or = (1-cos(phi))/sin(phi) = (sqrt(x^2+y^2)-x)/y, depending upon the sign of x, so we get the most accurate answer. We then use continued fractions to produce a '1/2-length' rational approximation to t=tan(phi/2). The Pythagorean result is ((t^2-1)+2it)/(t^2+1), which is 'full length'. --- I ran this procedure on the test case: cos(phi)+i*sin(phi), where phi=2*%pi/100000. The best my previous procedure was able to achieve was 506,605,917 + 31,831*i, which is _not_ Pythagorean. However, the above procedure produces (using one of the rational continued fraction approximations for tan(phi/2)): 506,606,280 + 31,831*i, which _is_ Pythagorean, with hypotenuse 506,606,281 !! So maybe there is hope for a 'Pythagorean number system' after all ! I now need to check all 100,000 points -- phi=2pik/100000, k=0..99999 -- to make sure that they can all be represented with reasonable size denominators. At 01:46 PM 8/14/2013, Warren D Smith wrote:
Henry Baker wanted to approximate reals x by "pythagorean rationals" x =approx= a/b with squareroot(a^2+b^2)=integer.
Obviously, yes, any such pythagorean (a,b) does have a continued fraction (namely just use the CF for a/b); and as Asimov remarked the set of rational points on the unit circle is dense, hence any x can be approximated arbitrarily closely by a pythagorean rational.
The pythagorean rationals form a group in the sense that any two rational points on the unit circle can be multiplied (viewed as complex numbers). That is, if v+iw has v,w rational with v^2+w^1, then view that (v,w) as the rational (v*LCM(vdenominator,wdenominator)) / (w*LCM(vdenominator,wdenominator)).
Euclid found all pythagorean triples (a,b,c) namely a = (m-n)*(m+n), b=2*m*n, c=m^2+n^2 which enables easily finding arbitrarily many arbitrarily close pythagorean rational approximations to x by this method: 1. use CFs to find large a,b so x =approx= a/b 2. solve for m,n satisfying above two simultaneous quadratic equations (as real numbers) 3. round off m,n to nearest integers 4. find resulting pythagorean a,b.