There are a lot of convergent sequences given here https://mathworld.wolfram.com/eContinuedFraction.html, e.g. for *e*:
2 1,;(<1 1),~&.>2*1+i.x:5 NB. A sequence of integers 2 1 2 1 1 4 1 1 6 1 1 8 1 1 10 1 1 0j18":(+%)/2 1,;(<1 1),~&.>2*1+i.x:5 2.718281828458563411 On Tue, Oct 3, 2023 at 1:20 PM Devon McCormick <devon...@gmail.com> wrote: > You can see how Raul's 2nd example, where he does not add 2, has fewer > correct digits than the one where he does not add it because adding 2 gives > you two more useful terms, as he mentions. > > On Tue, Oct 3, 2023 at 7:35 AM Raul Miller <rauldmil...@gmail.com> wrote: > >> A couple notes here: >> >> One is that 0j18":Y will give you 18 places after the decimal point >> regardless of the magnitude of Y >> >> Another is that we can inspect intermediate results in the expression >> %-/%!2+x:i.x >> >> Let's try that here with smaller values for x (and leaving out the x: >> so that we're using floating point approximations for more comfortable >> display): >> >> i.4 >> 0 1 2 3 >> !i.4 >> 1 1 2 6 >> !2+i.4 >> 2 6 24 120 >> %!2+i.4 >> 0.5 0.166667 0.0416667 0.00833333 >> %~/%!2+i.4 >> 2.4 >> >> Inspecting these results (and perhaps playing with a few other >> examples), I am reminded that !0 and !1 both have the value 1. And, of >> course, the reciprocal of 1 is 1. And, %~ will finish up by dividing >> the accumulated result by these values. So, this skips a couple >> unnecessary "divide by 1" steps. >> >> But, also, adding 2 means that we've added another two significant >> terms to the initial (right hand side) part of the series, giving us a >> more accurate result. >> >> These correspond to relatively small values in the result, but they do >> increase its precision. >> >> And, I do see a change there, on the right hand side, in the case of >> the example you suggested: >> >> 0j18":%-/%!2+i.x:10 >> 2.718281842777827338 >> 0j18":%-/%!i.x:10 >> 2.718283693893449991 >> >> I hope this helps, >> >> -- >> Raul >> >> On Tue, Oct 3, 2023 at 3:26 AM Richard Donovan <rsdono...@hotmail.com> >> wrote: >> > >> > After watching a math video on YouTube I started to investigate the >> implementation of alternating sequences in J. >> > >> > Using the site search function, (alternating sequences site: >> jsoftware.com) I discovered an entry in the NYCJUG of 2022-11-08 which >> contains an excellent example: >> > >> > >> > calce=: 13 : '%-/%!2+i.x: y' >> > calce 10 >> > 3991680r1468457 >> > 20j18":calce 10 NB. Format rational to 20-digit decimal with 18 >> places past the decimal >> > 2.718281842777827338 >> > >> > Using this as a startpoint, I followed the logic thru but couldn't >> understand why 2 is added to i. x: y >> > >> > Removing the 2+ doesn't seem to affect the result in any of the cases I >> tried. >> > >> > >> > Thanks in advance, >> > >> > Richard >> > ---------------------------------------------------------------------- >> > For information about J forums see http://www.jsoftware.com/forums.htm >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > > > -- > > Devon McCormick, CFA > > Quantitative Consultant > > -- Devon McCormick, CFA Quantitative Consultant ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm