Continued fraction/Arithmetic/Construct from rational number: Difference between revisions

Line 295:
The task is vague about how the "lazy evaluation" works, and it seems to me a function with side effects suffices. Nevertheless, what I did was write such a function that has side effects, and then wrap that function in a thunk (a closure taking no arguments). One might wish to go farther and produce a lazy stream, but I did not do that.
 
I hope the point is not that one must use lazy evaluation to do this algorithm! Rather,That itwould shouldbeg bethe that,question atof eachwhat step,"lazy youevaluation" aremeans. performingRather, the samepoint process,seems merelyto withwrite a''some'' differentmethod startingof point. Ifproducing the functiondigits returnedof the nextcontinued N1fraction. and''This N2,process alongitself'' withwill thebe nextregarded digit,as youthe wouldvalue haveof a purely functionalthe versionnumber.
 
(I have, by the way, long viewed "a real number" as such a process. It does not matter whether or not the process involves continued fractions, as long as it produces an arbitrarily precise rational number.)
 
I demonstrate concretely that the method of integer division matters. I use 'Euclidean division' (see ACM Transactions on Programming Languages and Systems, Volume 14, Issue 2, pp 127–144. https://doi.org/10.1145/128861.128862) and show that you get a different continued fraction if you start with (-151)/77 than if you start with 151/(-77). I verified that both continued fractions do equal -(151/77).
1,448

edits