The first element of a is always 1. The last element of a is always an integer and so can never be 0.5.
So the loop can never terminate. -- Raul On Tue, Oct 18, 2011 at 12:52 PM, David Vaughan <[email protected]> wrote: > Why does this not work? I had to interrupt it because it just froze doing > nothing. > > cf =: 3 : 0 > r=.%:y > a=.<.1r2+r > while. ({.a)~:2*{:a do. a=.a,<.1r2+{:r ] r=.r,1%({:r)-{:a end. > ]a > ) > cf 2 > |attention interrupt: cf > | cf 2 > > > On 18 Oct 2011, at 17:23, Raul Miller wrote: > >> The best I can think of at the moment is using x: on the floating >> point value for an initial value and then newton's method to gain the >> extra precision you want. >> >> -- >> Raul >> >> On Tue, Oct 18, 2011 at 12:09 PM, David Vaughan >> <[email protected]> wrote: >>> I'm hoping to write a verb to compute the continued fraction expansion of a >>> square root. I've done it in Java though there are accuracy issues with >>> floating points and speed issues with using exact numbers (you end up >>> multiplying massive numbers in some cases). Is J equipped to deal with >>> these problems or should I be looking for an alternative method entirely? >>> >>> On 18 Oct 2011, at 16:50, Raul Miller wrote: >>> >>>> On Tue, Oct 18, 2011 at 11:30 AM, David Vaughan >>>> <[email protected]> wrote: >>>>> Can J represent surds exactly instead of reverting to floating point? It >>>>> would be more convenient if I could do that rather than storing the >>>>> squared version. >>>> >>>> Yes, but by generating a verb which would generate the floating point >>>> value and not as a number. >>>> >>>> cubeRootOf5=: %:&5 bind 3 >>>> >>>> Of course you can manipulate the resulting numbers but those results >>>> are still floating point: >>>> >>>> (cubeRootOf5 ^ 3:) '' >>>> 5 >>>> 5-(cubeRootOf5 ^ 3:) '' >>>> 8.88178e_16 >>>> >>>> That said, in some cases, J can clean up floating point discrepancies >>>> >>>> 5-x:(cubeRootOf5 ^ 3:) '' >>>> 0 >>>> >>>> but that's from direct manipulation of the values and does not care >>>> about delayed evaluation: >>>> >>>> 5-x:((3 %:5) ^ 3:) '' >>>> 0 >>>> >>>> Anyways, J implements the data structures to support symbolic >>>> manipulation but it does not have a particularly large library of >>>> prebuilt symbolic manipulation routines. >>>> >>>> FYI, >>>> >>>> -- >>>> Raul >>>> ---------------------------------------------------------------------- >>>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
