Re: [Jprogramming] newbie question

2022-05-18 Thread yt
Rational precision proposal (Raul Miller) -- Message: 1 Date: Sun, 15 May 2022 16:12:42 +0200 From: Jan-Pieter Jacobs To: programm...@jsoftware.com Subject: Re: [Jprogramming] newbie question Message-ID: Content-Type: text/plain; charset="UTF-8" actually, J lets you approximate p

Re: [Jprogramming] newbie question

2022-05-15 Thread Raul Miller
81828459045235360287471352662497757147554933 > NB. ^ > > NB. view in fixed width please. > > https://www.jsoftware.com/help/dictionary/dx009.htm > > > > Date: Sun, 15 May 2022 10:28:30 +0200 > > From: yt >

Re: [Jprogramming] newbie question

2022-05-15 Thread David Lambert
iew in fixed width please. https://www.jsoftware.com/help/dictionary/dx009.htm Date: Sun, 15 May 2022 10:28:30 +0200 From: yt To:programm...@jsoftware.com Subject: Re: [Jprogramming] newbie question Message-ID: Content-Type: text/plain; charset=UTF-8; format=flowed Dear All, i come back

Re: [Jprogramming] newbie question

2022-05-15 Thread 'robert therriault' via Programming
I actually made a video for Pi day showing this technique and the various adjustments you need to make to get pi in an extended form from its original float representation. https://youtu.be/vyILnD0e2IE Cheers, bob > On May 15, 2022, at 07:12, Jan-Pieter Jacobs > wrote: > > actually, J lets

Re: [Jprogramming] newbie question

2022-05-15 Thread Jan-Pieter Jacobs
actually, J lets you approximate pi to as many digits as you'd want, but you have to know the trick: pix =. ([: <.@:o. 10^x:) _10 ]\ ": pix 100 3141592653 5897932384 6264338327 9502884197 1693993751 0582097494 4592307816 4062862089 9862803482 5342117067 9 gives the first 101 digits of pi (inclu

Re: [Jprogramming] newbie question

2022-05-15 Thread Elijah Stone
J has a few different ways of representing numbers, including: - Machine integers (limited to 64 or 32 bit); this is what you get if you type a number like 123 - Machine floating-point numbers (limited precision, but can have decimal points in them); this is what you get if you type a number l

Re: [Jprogramming] newbie question

2022-05-15 Thread yt
Dear All, i come back to start in J in jijx>tour>overview    3p5   NB. Pi (3 * Pi ^ 5) 918.059 may be it is not the better way to find Pi :    1p1   NB. Pi (1 * Pi ^ 1)    1p1 3.14159    1p1x |ill-formed number |  1p1x |  ^ but this is ok for :    ^/ 2 3 4

Re: [Jprogramming] Newbie question

2021-10-16 Thread Raul Miller
Good luck. And, not also that (z);t 4 should not behave any different from z;t 4 Take care, -- Raul On Sat, Oct 16, 2021 at 10:48 AM Richard Donovan wrote: > > Thanks for a quick reply Raul. I have printed off the parsing rules for later > study and I use your workaround! > > Richard > > >

Re: [Jprogramming] Newbie question

2021-10-16 Thread Richard Donovan
Thanks for a quick reply Raul. I have printed off the parsing rules for later study and I use your workaround! Richard > On 16 Oct 2021, at 15:30, Raul Miller wrote: > > What you are seeing here is that J needs to understand what names mean > before it can act on those names. > > A concise

Re: [Jprogramming] Newbie question

2021-10-16 Thread Raul Miller
What you are seeing here is that J needs to understand what names mean before it can act on those names. A concise summary of the issues is visible here: https://www.jsoftware.com/help/dictionary/dicte.htm In 'z; t 4' the evaluation of t 4 corresponds to the second line of the parsing table which

[Jprogramming] Newbie question

2021-10-16 Thread Richard Donovan
Hi. I write a function t, execute it, then execute it again. On the second execution, I want to display the intermediate result then the final result I have coded it as below The intermediate result is displayed as the intermediate result of the FIRST execution I was surprised as I though

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-20 Thread 'Mike Day' via Programming
At long last - I've only just managed to find some further solutions! I generate triples of P5s, such that P5(a) + P5(b) = P5(c) for triple (a,b,c) and check for which of them P5(d) = P5(a) + P5(c) for an integer d: |:Ptriples 30 4 7 12 19 7 23 22 22 8 24 25 29 Here are some timings on my la

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-13 Thread Raul Miller
Larger pentagonal numbers are further apart. Here, after 1827553 pentagonal numbers, they're too far apart for adjacent numbers to be closer together. (Note that this also limits the search space--though being slightly liberal with bounds and testing blocks at a time might work to keep interprete

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-13 Thread Skip Cave
Yes, Pascal found the same two pentagonal numbers I found: *pn=.3 :'y*(1-~3*y)%2'* * p=:pn>:i.5000x* Paschal's solution: P(2166)-P(1019) *2166 1019{p* *7042750 1560090* My solution: *]n=.m#p2* *1560090 7042750* The question is, do these two pentagonal numbers have the smallest D? Skip

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-13 Thread Louis de Forcrand
Quick correction: the answer given by Pascal is not 1019 but P(2166)-P(1019), and my email should use that instead of 1019 wherever it is mentioned. Sorry for the noise, Louis > On 14 Jul 2019, at 01:58, Louis de Forcrand wrote: > > I’m with Skip here: how do y’all guarantee that your brute-fo

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-13 Thread Louis de Forcrand
I’m with Skip here: how do y’all guarantee that your brute-force answers (which search through a list of the first few pentagonal numbers) actually return the pair with the smallest _difference_? How do you know there isn’t a pair outside your search range, where each number in the pair is much

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread Skip Cave
Another approach to Euler 44: NB. make a pentagonal number generator verb: *pn=.3 :'y*(1-~3*y)%2'* NB. Generate the first 5000 pentagonal numbers and store them in p. Then find all possible pair combinations of the first 5000 pentagonal numbers and store the pairs in p2. Then store the two inte

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread Daniel Eklund
Ahhh, the anti-base is clever. Now I get it. 3 4 #: 0 6 7 0 0 1 2 1 3 While the spare-array trick is great, I think this answer resonates as more in keeping with an array-oriented 'style' that I'm trying to internalize. It also succinctly does what I was trying to do with modulus/division hack

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread Daniel Eklund
Sorry, that tacit form got butchered in copy/pasting through different mediums and is actually (|@-)/@(0&{)@(a {~ (b {~ I.@(a e.~ (|@:-)/"1@:(a {~ b=:4&$.@$.@(a e.~ ( wrote: > Mike, thanks for thinking like I had a analytic insight, but I made a > mistake. > > In my defense, I did know to divide

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread Daniel Eklund
Mike, thanks for thinking like I had a analytic insight, but I made a mistake. In my defense, I did know to divide by 2, but at the time I was exploring what forms of verbs could automatically be inverted (obverted?) to create a possible "is_pentagonal" predicate and accidentally copied my truncat

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread 'Mike Day' via Programming
Trying out Pascal Jasmin’s brute-force approach (beware his spoiler!) runs out of memory on this iPad. Some of the solvers’ forum messages, from 2005 and later, boast of times as low as 0.2sec (Delphi) I’ve just worked up something akin to Oleg Kolobchenko’s approach; it takes about 12 sec on

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread 'Mike Day' via Programming
It looks as if Daniel was solving the problem for pentagonal numbers * 2. Clearly, if there’s a solution in true Pn for a pair of indices, m > n, ie, (-/ Pn m,n) = +/ Pn m,n, it will also be a solution for 2 * Pn . I suppose there might be some half-integral solutions for 2 * Pn which don’t

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread 'Pascal Jasmin' via Programming
your definition of pentagonal doesn't do the divide by 2 step  pentagonal =: [ -:@* ( 1 -~ 3 * ]) this combines (,:) the +/ and -/ tables into 2, then finds intersection (*./).  4$.$. returns index(es)  4 $. $. *./@:(e.~ -/~ ,: +/~) pentagonal >: i.20115 2166 1019 On Thursday, July 11, 201

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread 'Mike Day' via Programming
Sorry - I see Louis has just posted a very similar comment,  but I'll persist!... I usually use something more basic and more boring! The idea is that you use the shape of your input as the basis for a representation of the indices of the ravelled version of the array. Here goes:    ] toy =: 3 4

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-12 Thread Louis de Forcrand
Hi Daniel, If the ravel indices into the array M are stored in I, the multi-dimensional indices are then ($M) #: I So for your toy example a possible verb is v=: $ #: , I.@:= _1: Cheers, Louis > On 12 Jul 2019, at 02:11, Daniel Eklund wrote: > > Double thanks. > > One for that sparse arra

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-11 Thread Daniel Eklund
Double thanks. One for that sparse array trick. That will go into my toolbox. And secondly, for the work you've been putting into the youtube videos -- I think they've been an invaluable teaching aid, and a welcome addition to the relative paucity of J learning outside of the main website. On

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-11 Thread 'robert therriault' via Programming
Also, I am not sure that I would call it an anti-pattern but you can simplify your general example by using Compose (&) ( pentagonal 20+i.6) +/ pentagonal >: i. 5 1182 1190 1204 1224 1250 1304 1312 1326 1346 1372 1432 1440 1454 1474 1500 1566 1574 1588 1608 1634 1706 1714 1728 1748 1774 1852

Re: [Jprogramming] newbie question about indexing/tabling

2019-07-11 Thread 'robert therriault' via Programming
Wow Daniel, I am sincerely impressed at how you wrestled that one to the ground. A trick I learned a while ago on these forums was the use of Sparse ($.) toy e. _1 1 0 0 0 0 0 1 1 0 0 0 0 $. toy e. _1 NB. converts dense array to sparse form 0 0 │ 1 1 2 │ 1 1 3 │ 1 4 $. $. toy e. _1 NB.

[Jprogramming] newbie question about indexing/tabling

2019-07-11 Thread Daniel Eklund
Hi everyone, I’m looking for some newbie help. I feel I’ve come so far but I’ve run into something that is making me think I’m not really getting something fundamental. Rather than try to come up with a contrived example, I’ll just say outright that I’m trying to solve one of the project Euler q