#1063 continued fractions: result not canonicalized

open
nobody
Lisp Core (471)
5
2012-11-18
2007-01-14
No

cflength : 4;
cf([1, 1, 1, 1] - [1, 2, 3, 4]);
=> [0, 4, 3, 2] /* OK */
cf([1, 2, 3, 4] - [1, 1, 1, 1]);
=> [0, - 4, - 3, - 2] /* NOT SO GOOD */
cfdisrep(cf([1, 2, 3, 4] - [1, 1, 1, 1]));
=> 1/(-4+1/(-3+1/(-2)))
''%;
=> -7/30
cf(-7/30);
=> [- 1, 1, 3, 3, 2] /* OK */
cf([1, 2, 2, 2, 2] - [1, 1, 2, 1, 2, 1, 2, 1, 2]);
=> [0, - 3, - 6, 0, - 1, - 40, - 5] /* NOT SO GOOD */
cf(sqrt(3) - 2);
=> [0, - 3, - 1, - 2, - 1, - 2, - 1, - 2] /* NOT SO GOOD */

cf should probably canonicalize its output so that any of the numbers after the first are positive.

Running a noncanonical output through cf again seems to canonicalize it:

cf(args(cf(sqrt(3) - 2)));
=> [- 1, 1, 2, 1, 2, 1, 2, 1, 2] /* OK */

(The args(...) is there to erase the CF flag in the car of the result which would otherwise prevent cf from doing anything.)

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks