One thing you could do is get rid of the intermediate names in gr: gr=: monad define 1-~ (+&%:)/ y$1 )
And you might want to make this tacit, for example: 13 :'1-~ (+&%:)/ y$1' 1 -~ [: +&%:/ 1 $~ ] Or, depending on your preferences, you might want to use induction rather than insertion: gri=: 1-~(1+%:@])^:([-1:)&1 I guess it's really a matter of what your idea of "elegance" is... Personally, when I am fiddling with small expressions, I like to set up a line that evaluates and then tweak the expression and watch to make sure the result does not change. For this example, I'd have lines like: gr 10 1.61798 1-~(1+%:)^:9]1 1.61798 13 :'((+&%:)/ y$1) - 1' 10 1.61798 (1-~(1+%:@])^:([-1:)&1) 10 1.61798 (with lots of other lines, including some errors, mixed in) But the precision issue you are seeing is really the print precision global parameter. See http://www.jsoftware.com/help/dictionary/dx009.htm for how to change that. I hope this helps. -- Raul On Thu, Apr 14, 2016 at 3:13 PM, Martin Kreuzer <[email protected]> wrote: > Moving from continued fraction to continued square root, I arrived at this: > > NB. modelling gr=. rt(1+rt(1+rt(1+rt(1+...)))) > > gr=. monad define > ps=. + > rt=. %: > v=. y $ 1 > r=. 1-~ (ps&rt)/ v > ) > gr 10 > 1.61798 > gr 13 > 1.61803 > > Q1: > What would be (more elegant and/or concise) ways to do this, especially the > line with the return value (r)..? > Q2: > What should I do to get higher precision (more digits) in the result (and > still having a floating point number); does that need a "foreign"..? > (I'm sure that I have seen this before, but can't remember where.) > > Thanks > -M > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
