J Challenge 
Author Message
 J Challenge

Quote:
Bjorn writes:
> For those of you who have not yet discovered the J challenge.
> Please look at the challenges there and try out a few things
> and compare then with the solutions.

> Here is one describing a challenge.

> It is a beauty on its own:

>     ]a=. <;.2 'keep remove '
>    b=. <;.2 'leading trailing outer '
>    c=. <;.2 'blanks numerics characters '
>    all=. { a;b;<c   NB. all combinations
>    (0&{&> , ' - '"_ , ;)&> all

> Try it out on your J at home !!!
> --

> http://www.*-*-*.com/ ~gosi
> http://www.*-*-*.com/

APL challenge

Try in APL
?.,/?a b c
in which the bold stiles read <take> and <pick> resp.
and in which a b and c are strings given as:
a =. 'keep ' 'remove ' rather than 'keep remove' etc. which in my view
is more clear in APL than it is in J (in which the blank is apparently
an implicite separator and not a 'character'; why? it doesn't quite
fit in my perception anyway).
The only advantage of J is that you can send it by Internet, which in
most cases is not our purpose.
Jan Karman



Tue, 15 Sep 1998 03:00:00 GMT  
 J Challenge

Quote:

>  Bjorn writes:
> > For those of you who have not yet discovered the J challenge.
> > Please look at the challenges there and try out a few things
> > and compare then with the solutions.

> > Here is one describing a challenge.

> > It is a beauty on its own:

> >     ]a=. <;.2 'keep remove '
> >    b=. <;.2 'leading trailing outer '
> >    c=. <;.2 'blanks numerics characters '
> >    all=. { a;b;<c   NB. all combinations
> >    (0&{&> , ' - '"_ , ;)&> all

> > Try it out on your J at home !!!
> APL challenge
> Try in APL
> ?.,/?a b c

Unfortunately I can not seem to be able to read this last line

Quote:
> in which the bold stiles read <take> and <pick> resp.

In my newsreader there are no bold stiles

Quote:
> and in which a b and c are strings given as:
> a =. 'keep ' 'remove ' rather than 'keep remove' etc.

I take it that the above be defined in your APL as:
   a=. 'keep ' 'remove '
   b=. 'leading ' 'trailing ' 'outer '
   c=. 'blanks ' 'numerics ' 'characters '

Quote:
> which in my view
> is more clear in APL than it is in J (in which the blank is apparently
> an implicite separator and not a 'character'; why? it doesn't quite
> fit in my perception anyway).

In your APL apparantly the blank is some sort of operation while
in J the operation is done by specific well defined and clear operation

 ;.     defines the Cut operation

<       is a left argument to cut and tells it to be boxed

2       is a right argument to cut telling cut to use the last
        character in the string as a separator. 2 means that the
        separator should be kept in the box.

A right argument to cut of _3,_2,_1,0,1,2 and 3 all give you
different boxes.

_2   gives you same kind of box as 2 but removes the separator.
     In this case the last character the blank.

1    would use the first character and keep it.

_1   would also use the first character but remove it from the box.

0    reverses the chars in the box

3    splits it into ever smaller boxes

Quote:
> The only advantage of J is that you can send it by Internet,

I can think of a few more advantages.

It is a bit strange to think that 1982 I remember sitting in the
auditorium in Heidelberg watching Ken Iverson and Jim Brown debating
on the stage about exactly this phenomenon that had just been introduced
in APL2.

Giving a meaning to blank like:
   a=. 'keep ' 'remove '

In APL2 this was supposed to have a meaning while Ken did not like
that. In J this gives a syntax error.

However linking with a specific well defined operation works:
 a=. 'keep ';'remove '

;    link

Link links the two items together.

APL2 is sometimes called the missing link because of this.

At the time I did not understand the significance of the debate.
I had just been introduced to APL2 and thought it was great and I
did not underestand why Ken did not just love it like I did.

It took me several years of using APL2 and then converting to
SAX and eventually J before I began to understand the difference.

Needless to say that I now understand that Ken was right way back then
in Heidelberg.

It is a bit strange to see this debate still being on.
I can understand why people do not understand.

It is often difficult to understand Ken.

I have come to the conclusion that if Ken says something I just
accept it hoping I will be fortunate enough to understand it in a few
years time.

--

http://www2.simi.is/~gosi
http://www.jsoftware.com



Wed, 16 Sep 1998 03:00:00 GMT  
 J Challenge
Bjorn,
The two characters I'm talking of appear in my editor as bold stiles.
The first character 'cross' should be read <mix> rather than <take>
The second 'oe' is meant to be <first> rather than <pick> (I don't
have the tools (nor the time to explore them)to display APL characters
properly on Internet).
I'm not taking in doubt anything Mr Iverson is saying. I just don't
see in your example an explicit "J Challenge", or more than e.g. an
APL Challenge.
Jan


Wed, 16 Sep 1998 03:00:00 GMT  
 J Challenge

Quote:
>a =. 'keep ' 'remove ' rather than 'keep remove' etc. which in my view
>is more clear in APL than it is in J (in which the blank is apparently
>an implicite separator and not a 'character'; why? it doesn't quite
>fit in my perception anyway).

 As Bjorn pointed out, there is nothing special about the blank
which appeared in the constants except for the fact that the
cut conjunction (;.) used the last item in the list (a blank)
as the delimiter.

 The rest is as you guessed:  J's     <;.2 'this and that '
is APL2's   'this ' 'and ' 'that '

 The final line:  (0&{&> , ' - '"_ , ;)&> all
generates a table of function name and definition, eg:
rlb - remove leading blanks

 I'd be interested in seeing the APL2 expression which generates
a similar result to this expression.  Also, I'd like to see the
APL2 solution to the challenge posed here -- I would think its
defined operators would allow for a solution along the lines of
the J solution given at the web site.

           -------------------------------------

 For those interested, here's more information about the "cut"
conjunction which came under discussion here:

 The cut conjunction (;.) splits the argument along the leading
axis ("items" in J-speak), and applies the verb left argument
to each partition.  The number on the right determines how
the partitions are defined:  1 and _1 uses the leading item
as the delimeter; 2 and _2 uses the trailing item.  The negative
cases differ in that the delimiters are not included in the
partitions.  Some examples using box (<) should help:
   <;.1 '/the/delimiters/are/slashes'
+----+-----------+----+--------+
|/the|/delimiters|/are|/slashes|
+----+-----------+----+--------+
   <;._1 '/like/above/but no/delims included'
+----+-----+------+---------------+
|like|above|but no|delims included|
+----+-----+------+---------------+

 Of course, it works on any rank, and with any function:

   +/;._1  ]  0 2 4 3 0 4 5 6 3 2 0 4 5 3 2  NB. sum the partitions
9 20 14

   ]t=. (i.3 4),_1,(12+i.3 4),_1
 0  1  2  3
 4  5  6  7
 8  9 10 11
_1 _1 _1 _1
12 13 14 15
16 17 18 19
20 21 22 23
_1 _1 _1 _1

   */"1 ;. _2 t    NB.  (*/"1) times reduce the rows on each part
    0   840   7920
32760 93024 212520

 Dyadic cuts can be used when you want to explicitly specify the
partitions with a boolean mask.  Also, there are 0- and 3- cuts
which do all sorts of wonderful things..  but I won't get into
them here.

           -------------------------------------

 A more practical example takes as an argument a character list
of newline-terminated lines, and applies a function to each line.
Examples:

   list=. 0 : 0
This is a series of
lines which are
read by 0 : 0.

It returns a newline-delimited
list of these contents.
)


+-------------------+---------------+--------------++----- ...
|fo seires a si sihT|era hcihw senil|.0 : 0 yb daer||detim ...
+-------------------+---------------+--------------++----- ...

   firstword=. {.~ i.&' '    NB.  return first word in a string
   firstword;._2 list     NB.  result is table of first words.
This
lines
read

It  
list
   NB.  Could have just been:    firstwords=. ({.~ i.&' ');._2

Also, given the example list, we can also:

   lines=. <;._2 list    NB.  Return list of boxes for each line.

A paragraph is indicated by an empty line, now an empty box:
   para_delim=. <''   NB. paragraph delimiter
   ]text=. <;._2 lines,para_delim
+----------------------------------------------------+----...
|+-------------------+---------------+--------------+|+---...
||This is a series of|lines which are|read by 0 : 0.|||It ...
|+-------------------+---------------+--------------+|+---...
+----------------------------------------------------+----...

Result of the above is a list of boxes each representing a paragraph.
Inside each box is a list of boxes containing the lines in that
paragraph.  Once text is defined, you can do the following:
   #text      NB.  Number of paragraphs
2
   #&>text    NB.  Number of lines in each paragraph
3 2



   ]x=.find_of&> &.> text  NB.  return a boolean mask per paragraph
+-----+---+                NB.  showing lines with the word 'of' in it.
|1 0 0|0 1|
+-----+---+

   x#&.>text    NB. Pick out those lines
+---------------------+-------------------------+
|+-------------------+|+-----------------------+|
||This is a series of|||list of these contents.||
|+-------------------+|+-----------------------+|
+---------------------+-------------------------+

--



Thu, 17 Sep 1998 03:00:00 GMT  
 J Challenge

that I posted Sunday at 14:22 GMT was terribly garbled.  I believe the
garbling was caused by a combination of the following two factors:

. The article contains a quotation from Jan Karman containing
APL characters in the upper ASCII range (>127).  The presence
of these characters in my article caused some software/network
along the way, but definitely after leaving my machine and my
e-mail service provider, to replace them and certain _other_
characters by "=xx", where xx is the ASCII index in hex.  
In particular, the = sign itself was replaced by "=3D"
(thus "=." became "=3D."), and (mysteriously) some blanks
were replaced by "=20".  

Without intending to, I managed to demonstrate once again the
havoc that APL characters can cause.  It is ironic that in his
original post Jan Karman said, "The only advantage of J is that you
can send it by Internet, which in most cases is not our purpose".

. The display of the boxed array "all" was more than 80 characters wide.
My e-mail software wrapped these lines in a non-fortuitous manner.

Herewith, the article as I intended, hopefully not to be garbled again:

-------------------------

Quote:
Bjorn Helgason writes:
>    ]a=. <;.2 'keep remove '
> +-----+-------+
> |keep |remove |
> +-----+-------+
>    b=. <;.2 'leading trailing outer '
>    c=. <;.2 'blanks numerics characters '
>    all=. { a;b;<c   NB. all combinations

>    (0&{&> , ' - '"_ , ;)&> all
> klb - keep leading blanks      
> kln - keep leading numerics    
> klc - keep leading characters  

> ktb - keep trailing blanks      
> ktn - keep trailing numerics    
> ktc - keep trailing characters   ...
Jan Karman writes:
> APL challenge

> Try in APL
> {hex 86}{hex b0}.,/{hex 9c}{hex a8}{hex a8}a b c
> in which the bold stiles read <take> and <pick> resp.
> and in which a b and c are strings given as:
> a =. 'keep ' 'remove ' rather than 'keep remove' etc. which in my view ...

As far as I can tell, the APL expression is

{first}{jot}.,/{disclose}{each}{each}a b c

which only generates the result "all", but is silent on how the final
array of acronyms and full texts is to be computed.

There is another solution in J that uses the monad ;: (word formation)
to advantage.  ;: applies the J rhematic rules to produce a list of the
words in the string argument, individually boxed.  ;: is quite efficient,
and is often applicable to ordinary text, as here:

   each=. &.>
   [ t=. 'remove keep'; 'leading trailing outer'; 'blanks numerics characters'
+-----------+----------------------+--------------------------+
|remove keep|leading trailing outer|blanks numerics characters|
+-----------+----------------------+--------------------------+
   [ all=. { ;: each t
+------------------------+--------------------------+---------------------- ...
|+------+-------+------+ |+------+-------+--------+ |+------+-------+------
||remove|leading|blanks| ||remove|leading|numerics| ||remove|leading|charac
|+------+-------+------+ |+------+-------+--------+ |+------+-------+------
+------------------------+--------------------------+----------------------
|+------+--------+------+|+------+--------+--------+|+------+--------+-----
||remove|trailing|blanks|||remove|trailing|numerics|||remove|trailing|chara
|+------+--------+------+|+------+--------+--------+|+------+--------+-----
+------------------------+--------------------------+----------------------
|+------+-----+------+   |+------+-----+--------+   |+------+-----+--------
||remove|outer|blanks|   ||remove|outer|numerics|   ||remove|outer|characte
|+------+-----+------+   |+------+-----+--------+   |+------+-----+--------
+------------------------+--------------------------+----------------------
...


rlb - remove leading blanks    
rln - remove leading numerics  
rlc - remove leading characters

rtb - remove trailing blanks  
rtn - remove trailing numerics
rtc - remove trailing characters  ...

The leftmost tine in the last fork replaces 0&{ with the equivalent {. .
The rightmost tine is essentially ;:^:_1 (the inverse of word formation),
so that:

   ;:^:_1 ({.&> ; '-'"_ ; ])&> { ;: each t
rlb - remove leading blanks    
rln - remove leading numerics  
rlc - remove leading characters

rtb - remove trailing blanks    
rtn - remove trailing numerics  
rtc - remove trailing characters  ...

   ({.&> ; '-'"_ ; ])&> { ;: each t
+---+-+------+--------+----------+
|rlb|-|remove|leading |blanks    |
+---+-+------+--------+----------+
|rln|-|remove|leading |numerics  |
+---+-+------+--------+----------+
|rlc|-|remove|leading |characters|
+---+-+------+--------+----------+  ...

Quote:
Jan Karman further writes:
> The only advantage of J is that you can send it by Internet, which in
> most cases is not our purpose.

I am curious, how would you solve in your favorite language or APL dialect
the problems posed recently in this forum?

. Binomial coefficents (Ken Iverson)
. String containment (Bernhard Strohmeier)
. Primes and factoring (Jim Weigang)
. Binomial series coefficients (Ken Iverson)
. Fahrenheit/Celsius conversion (Bjorn Helgason, Steve Apter)
. QR decomposition (Sam Sirlin, Lewis Robinson)
. R inverse (Roger Hui)
. All acronyms (Kirk Iverson, Bjorn Helgason)



Fri, 18 Sep 1998 03:00:00 GMT  
 J Challenge
<snip>

Quote:
> It is a bit strange to think that 1982 I remember sitting in the
> auditorium in Heidelberg watching Ken Iverson and Jim Brown debating
> on the stage about exactly this phenomenon that had just been introduced
> in APL2.

> Giving a meaning to blank like:
>    a=. 'keep ' 'remove '

> In APL2 this was supposed to have a meaning while Ken did not like
> that. In J this gives a syntax error.

> However linking with a specific well defined operation works:
>  a=. 'keep ';'remove '

> ;    link

> Link links the two items together.

> APL2 is sometimes called the missing link because of this.

> At the time I did not understand the significance of the debate.
> I had just been introduced to APL2 and thought it was great and I
> did not underestand why Ken did not just love it like I did.

> It took me several years of using APL2 and then converting to
> SAX and eventually J before I began to understand the difference.

> Needless to say that I now understand that Ken was right way back then
> in Heidelberg.

> It is a bit strange to see this debate still being on.
> I can understand why people do not understand.

> It is often difficult to understand Ken.

> I have come to the conclusion that if Ken says something I just
> accept it hoping I will be fortunate enough to understand it in a few
> years time.

> --

> http://www2.simi.is/~gosi
> http://www.jsoftware.com

Bjorn,

The "function" of the blank is crap.
In APL2, A(B) is a two-item vector if A and B are data.
In J, F(G) is a Fork if A and B are functions.

It's NOT the blank, it's what are the semantics of justaposed words?
 Consider two words (tokens) without an explicit "operation" between
them as in A B

APL\360
1. function application when A is a monadic function and B is data
2. two-item vector when A and B are numeric constants

APL2
1. function application
2. two-item vector when A and B are data (notice simpler than APL\360)

Dyalog APL
1. & 2. (same as APL2)
3. Derived function when A is a function or data and B is an operator

J
1. & 2. (same as APL\360)
3. (same as Dyalog APL)
4. Fork when A and B are functions

It looks like J has the most definitions for the juxtaposition of a
pair of words. The rule that a vector of numeric constants is one word
is stange.

The juxtaposition rules for Zero are the same as for Dyalog APL,
e.g. F G is a SYNTAX ERROR.

I have nothing against Fork, I would define an explicit symbol for
Fork. (J is the missing fork ... there must be a joke in there
somewhere.)

I have nothing against an explicit Link function ( link:{_y _x}. ).
It is so easy to make. I wonder why it should be primitive.

It feels like 1982 again. ;-)

Alan Graham



Fri, 18 Sep 1998 03:00:00 GMT  
 J Challenge
Roger,

Quote:
>As far as I can tell, the APL expression is
>{first}{jot}.,/{disclose}{each}{each}a b c

Thank you, Roger, for un-garbling the code; it seems to me
that calling the APL primitives by name is confusing.
In the dialect I'm using it should read

 {mix}{jot}.,/{first}{each}{each}a b c

As far as my admiration for J concerns, I'm already impressed by

        i. 2 3 4
Jan



Sat, 19 Sep 1998 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. JS-EAI with *JS*-callback

2. js.exception 3279.js

3. NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

4. lapackTest.js

5. profile.js

6. J script file profile.js

7. JS valueOf() in RB ?

8. JS for functional programming?

9. JS for functional programming?

10. prefs.js question

11. JS / VRML / HTML / camera binding

12. help: js generated vrml

 

 
Powered by phpBB® Forum Software