Marry, pray, Whichcraft in J!
Author Message
Marry, pray, Whichcraft in J!

Here is some practice material for beginning and advanced J programmers alike.
Just in case it happens to be the start of the week and you're looking for some
distraction from Real Work ;-)

Martin Neitzel

While reading Roger Hui's "Rank and Uniformity" from the APL95 proceedings,
I came across the following funky phrase that I did understand immediately:

[ ^: some_comparison

If this isn't already an old hat to you, you're invited to sharpen your
J skills a little bit on this small but useful phrase, too.

Predict the results of

17 ([^:<) 4    and
17 ([^:<) 21

Substitute ] for [ and/or > for < .

This will give you a good impression of what it does.  If you cheated on the
predictions, figure now out how it works.  Look up the definitions of
Left "[", Less Than "<", and Power "^:".  What kind of train is [^:< , and
where do the arguments go?

In general you'll use more complicated boolean relationships r in [^:r
(Roger needed a <&# in his article.)  The phrase makes it also easy to
to look for extremes in larger data sets.  Just use [^:r/ on (non-empty)
item lists.

You are a seasoned Juggler and are bored so far?  Then quick!, either
without or with consulting the Dictionary, but without experiments:

- What is     2 [^:(2) 17  ?
- What is     2 [^:(_1) 17  ?
- What is     2 [^:(_1 _2 _3) 17  ?
- What is  +/ 2 [^:(-i.100) 17  ?

Fri, 16 Oct 1998 03:00:00 GMT
Marry, pray, Whichcraft in J!

Quote:

>You are a seasoned Juggler and are bored so far?  Then quick!, either
>without or with consulting the Dictionary, but without experiments:

> - What is     2 [^:(_1) 17  ?

Very interesting.  And I tried

(2&[) b. _1

How did the interpreter pick that for an inverse?

Henry Rich

Fri, 16 Oct 1998 03:00:00 GMT
Marry, pray, Whichcraft in J!

Martin Neitzel's article on  [^:proposition  reminds me of a couple
of awe-inspiring ^:-ful expressions.

The first is by Ken Iverson and can be found in the dictionary
entry for \. , for computing the (boxed) minors of a matrix:

minors=: 1&(|:\.)"2^:2
<"2 minors i.3 3

The second is by Kirk Iverson and can be found in the page
http://www.jsoftware.com/chal/soln006.html as the solution to
J Challenge #6.  The problem is to border an array y by scalar x
in every dimension, and Kirk's solution is:

(The expression is explained in detail on that page.)  One might

Fri, 16 Oct 1998 03:00:00 GMT
Marry, pray, Whichcraft in J!

Henry Rich writes on Monday, April 29:

Quote:
>  Very interesting.  And I tried

>   (2&[) b. _1

> How did the interpreter pick that for an inverse?

J uses a linear approximation in the absence of a known inverse, as above.
We have had second thoughts about having this default and have removed
it in favor of a domain error, to take effect in the next release.

Sat, 17 Oct 1998 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages