## #1136 cf(sqrt(8)) wrong

open
nobody
5
2007-03-03
2007-02-23
Stavros Macrakis
No

makelist(cf(sqrt(8)),cflength,1,7) =>
[3, [2, 1, 4], [2, 1, 5], [2, 1, 4, 1, 4], [2, 1, 4, 1, 5], [2, 1, 4, 1, 4, 1, 4], [2, 1, 4, 1, 4, 1, 5]]

There are two problems here.

* The cflength=0 result is not a continued fraction at all, but cf(xxx) is always supposed to return a continued fraction, even for integers: cf(3) => [3].

* cflength=n is documented to mean that you get n periods. The period here is [1,4] (length 2), so the results should be
[2,1,4], [2,1,4,1,4], [2,1,4,1,4,1,4] etc.
compare
makelist(cf(sqrt(3)),cflength,1,7);
=> [[1, 1, 2], [1, 1, 2, 1, 2], [1, 1, 2, 1, 2, 1, 2], ...

Same problem with cf(sqrt(32)), cf(sqrt(27)), etc. On the other hand, cf(2^(3/2)) etc. does NOT cause this problem.

By the way, cflength gives you 1 period, not 0....

## Discussion

• Robert Dodier
2007-03-03

• labels: --> Lisp Core

• not just sqrt(8), there are many others... I've run this expression but I cannot see a clear pattern:

for i:2 thru 10000 do if not listp(cf(sqrt(i))) then display(i, cf(sqrt(i)));