digitsE=:10&#.^:_1 NB. Elijah's convert to digits digitsR=:"."0": NB. My convert to digits datatype digitsE 357686312646216567629137x extended datatype digitsR 357686312646216567629137x floating truncs=. [:~. [:10x&#.\. digitsR truncs 357686312646216567629137x 3.57686e23 5.76863e22 7.68631e21 6.86313e20 8.63126e19 6.31265e18 3.12646e17 1.26462e16 2.64622e15 6.46217e14 4.62166e13 6.21657e12 2.16568e11 1.65676e10 6.56763e9 5.67629e8 6.76291e7 7.62914e6 629137 29137 9137 137 37 7 digitsR=:<.@"."0": NB. My convert to digits truncs 357686312646216567629137x 357686312646216567629137 57686312646216567629137 7686312646216567629137 686312646216567629137 86312646216567629137 6312646216567629137 312646216567629137 12646216567629137 2646216567629137 646216567629137 46216567629137 6216567629137 216567629137 165676291... datatype digitsR 357686312646216567629137x integer
Note especially the table at https://www.jsoftware.com/help/dictionary/dictg.htm J's numeric type system was designed for efficiency and the sort of accuracy typically needed in physics and education contexts rather than the needs of high precision number theory contexts (which wasn't really a part of Ken Iverson's background). I hope this helps, -- Raul On Sun, Nov 20, 2022 at 4:39 AM Richard Donovan <rsdono...@hotmail.com> wrote: > > Proving that I am still baffled by J! > > Elijah has a different way to convert a number to its > digits than I normally use, so I set out to compare.. > > digitsE=:10&#.^:_1 NB. Elijah's convert to digits > digitsR=:"."0": NB. My convert to digits > > (digitsE-:digitsR) 357686312646216567629137x > 1 NB. Well that's alright! > > digitsE 357686312646216567629137x > 3 5 7 6 8 6 3 1 2 6 4 6 2 1 6 5 6 7 6 2 9 1 3 7 > digitsR 357686312646216567629137x > 3 5 7 6 8 6 3 1 2 6 4 6 2 1 6 5 6 7 6 2 9 1 3 7 > NB. Still looking good! > > > NB. Set up truncs with Elijah's routine.. > truncs=. [:~. [:10&#.\. digitsE > > NB. Works perfectly! :o) > truncs 357686312646216567629137x > 357686312646216567629137 ...etc > > 1 p: truncs 357686312646216567629137x > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > NB. Perfect! > > NB. Set up truncs with my routine.. > truncs=. [:~. [:10&#.\. digitsR > > NB. Should be the same??? > > truncs 357686312646216567629137x > 3.57686e23 5.76863e22... WRONG!!! :o( > > > On 19 Nov 2022, at 22:04, Elijah Stone <elro...@elronnd.net> wrote: > > > > x: ". y where y is simply a string of digits will interpret those digits > > as a (fixed-width) integer and _then_ convert the latter to > > extended-precision. You could append an 'x', or perhaps consider the > > following definition: > > > > truncs=. [:~. [:10&#.\. 10&#.^:_1 NB.equivalent to ltrunc^:a: > > ,.truncs 357686312646216567629137x > > 357686312646216567629137 > > 57686312646216567629137 > > 7686312646216567629137 > > 686312646216567629137 > > 86312646216567629137 > > 6312646216567629137 > > 312646216567629137 > > 12646216567629137 > > 2646216567629137 > > 646216567629137 > > 46216567629137 > > 6216567629137 > > 216567629137 > > 16567629137 > > 6567629137 > > 567629137 > > 67629137 > > 7629137 > > 629137 > > 29137 > > 9137 > > 137 > > 37 > > 7 > > > >> On Sat, 19 Nov 2022, Richard Donovan wrote: > >> > >> Hi > >> > >> I am doing experiments with large primes, in particular looking at primes > >> that remain primes when n digits are truncated from the left. For example > >> 6391373 391373 91373 1373 373 73 3 remains prime at each > >> step. > >> > >> The largest of these in base 10 is 357686312646216567629137. > >> > >> I wrote the following code in preparation for further investigation but I > >> find that the 24 digit number above is not handled as I wish it to be, as > >> you will see below. > >> > >> What have I missed? > >> > >> Thanks > >> > >> > >> > >> > >> digits > >> "."0@": > >> > >> ltrunc > >> 3 : 0"0 0 0 > >> n=: ": 0, }. digits y > >> x: ". n-. ' ' > >> ) > >> > >> > >> > >> NB. Works fine with 7 digit number... > >> ltrunc^:a: 6391373 > >> 6391373 391373 91373 1373 373 73 3 0 > >> > >> > >> NB. But I can’t get it working for a 24 digit number! > >> ltrunc 357686312646216567629137 > >> 0 0 5 7 6 8 6 0 2 3 > >> ltrunc 357686312646216567629137x > >> 57686312646216568012800 > >> ltrunc x:357686312646216567629137x > >> 57686312646216568012800 > >> > >> Is there a way around the limit? > >> > >> ---------------------------------------------------------------------- > >> 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