Hello everyone,

First of all, thank you so much for all the responses. After reading each
one multiple times and spending several hours looking at this program, I
think that I have made progress.

Hauke:
I hadn't noticed that parentheses were, as a rule of thumb, matched.
About dissect: it is not compatible with expressions containing {{ }}, so I
tried removing these, replacing y with 15 and dissecting the resulting
expression. But that also failed because I was writing 1 15 } instead of 1
(15) }. The replies by Brian and Raul made me realize this mistake and
finally be able to dissect the entire expression.
Thanks for mentioning the ;: operator, it allowed me to find the tokens and
look them up before I had dissect working.

Boss:
The result of parens was super useful:
(, ((72#:~8#2){~3#.\0,],0:)@{:)^:y ,: 1 y} (>:+:y) $ 0
    └────────┘
   └──────────────────────┘
└─────────────────────────────┘            └─────┘
And indeed, using 72#:~8#2 instead of 0 1 0 0 1 0 0 0 is nonsensical.

Brian:
Thanks for the explanation about forks. A question that I have is: can V0
V1 V2 V3 V4 can become V0 V1 V2 (V3 V4) instead of V0 V1 (V2 V3 V4)?

Raul:
That made a lot of sense, I needed your detailed clues to understand the
program.


So here is the summary of my current understanding:

1- ( >: +: y ) $ 0 generates an array with 2*y+1 zeros.
2- 1 y } replaces the middle element in that array with the number 1.
3- ,: converts the result into a matrix with a single row.
4- ^: y makes the operator on its left be applied y times to that matrix.
5- That operator has two parts: (A B), where A is , and B is ( ( 72 #: ~ 8
# 2 ) { ~ 3 #. \ 0 , ] , 0: ) @ {:
6- (A B) y expands to y A (B y) -- "J for C programmers", chapter 40.
7- So we have (B y) being appended to the matrix each time.
8- B is the composition (@) of getting the last row in the matrix ({:) and
applying the operator ( ( 72 #: ~ 8 # 2 ) { ~ 3 #. \ 0 , ] , 0: ) to that
last row.
9- We'll use (A B C) y = (A y) B (C y) to process the train -- "J for C
programmers", chapter 40.
10- Step 1: append (,) the row (], identity) and 0. That is, add a 0 to its
right.
11- Step 2: 0 , followed by the result of step 10. That is, append a 0 to
the left of the array.
12- For every 3 elements in the resulting array, get the number in base 2
with digits corresponding to those elements (3 #. \).
13- Use the result as indexes for the ( 72 #: ~ 8 # 2 ) array.

Now why steps 10-13 result in the next row of a sierpinski triangle, I
don't know, I guess it has to do with generating a Pascal triangle.

That was probably one of the hardest things to grasp that I have ever
encountered in programming. 10 years writing C programs did not prepare me
for this.
Without the help that I have received here, I would probably have taken
about 3 weeks to get this far.


Andrew



On Tue, Feb 1, 2022 at 7:31 PM Raul Miller <rauldmil...@gmail.com> wrote:

> It's probably worth noting here that the {: here is used to grab the
> last row of the partial result which is being built.
>
> Initially, this is a list of y zeros, followed by a 1, followed by y zeros.
>
>    ,: 1 (15)} (>:+:15) $ 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>
> Note that there would be other ways of building this value, for example:
>    15=i.1 31
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>
> Anyways, next you have an expression of the form (, (...)@{:)^:15
> which starts with the above as its initial value. So it's adding
> another 15 rows. (Or... y instead of 15, for the general case.)
>
> And, there, it's padding each row with an extra zero, grabbing every
> adjacent set of three bits and using them to index into an eight bit
> constant.
>
> Hopefully this is close to the right number of clues?
>
> Thanks,
>
> --
> Raul
>
> On Tue, Feb 1, 2022 at 12:54 PM Brian Schott <schott.br...@gmail.com>
> wrote:
> >
> > Andrew, your observations are correct.
> > Now consider this part which is an amend to create
> > and amend a long list of zeroes.
> >
> >    1 (15)} (>:+:15) $ 0    NB. beware, of long result
> > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> >    $,:1 (15)} (>:+:15) $ 0   NB. ,: forces a new dimension
> > 1 31
> >
> > Now consider the left-most part which is just a train of
> > verbs and some nouns which are forced to behave like verbs in
> > this context, (except for the first part: @{:). Such trains
> > are called forks in J when they have 3 tines.
> > Forks of 3 verbs can be symbolized V0 V1 V2 or if the
> > V0 is a noun, symbolized N, then N is treated as if it is
> > a verb and it is V0.
> > Longer fork trains like V0 V1 V2 V3 V4 are processed from
> > right to left and the result of the leftmost fork becomes
> > the rightmost verb of the next fork to the left after the
> > first fork is processed; so V0 V1 V2 V3 V4 is processed
> > like V0 V1 (V2 V3 V4). In this case, the 3 is a leftmost noun
> > in one of the forks, and the 0 to its right is another
> > leftmost noun in a fork. Also the term (72#:~8#2) is a
> > leftmost noun in a fork.
> >
> >    (, ((72#:~8#2){~3#.\0,],0:)@{:)
> >
> > The (, (....)) 2 verb train called a hook, which appends
> > the hook's input to the result when the leftmost verb (.....)
> > is applied to its own input.
> >
> >
> > The ^:y term repeats the process y times.
> >
> > Maybe this give some more information, although it is rough.
> > ----------------------------------------------------------------------
> > 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

Reply via email to