On Jan 27, 2:04 pm, "Aaron W. Hsu" <arcf...@sacrideo.us> wrote:
> Does anyone have any cool, concise, but very impressive examples of APL's
> capabilities?
Impressive: the FinnAPL Idiom List and the IBM APL Idiom List. Very
impressive: Roy Sykes' Whizbang! columns in Quote Quad. I don't have
links at hand; consider these Google fodder.
> Does anyone have any cool, concise, but very impressive examples of APL's > capabilities?
There is a one-line function written by Ken Iverson that computers the determinant of a matrix. It was published in the August 1977 issue of BYTE magazine. I am *not* well enough versed in the APL to ASCII translation... to be able to post the function here.
-- +<><><><><><><><><><><><><><><><><><><>+
| Charles Richmond numer...@aquaporin4.com |
+<><><><><><><><><><><><><><><><><><><>+
> Does anyone have any cool, concise, but very impressive examples of > APL's capabilities?
what about
B is A[gradeup A] for a sorted list?
Compare this to a program to do this in C (+ whatever)
Another is a one liner to calculate sin x from the series to an arbitrary number of terms out to order n
As I recall it goes something like this.
Y is -/ (X*S) divided by ! S is (N rho 1 0)/i,N
A trouble with many such one-liners is that they become too complex when one is learning whereas the simple sorts and things like calculation of a mean which are easily grasped- and there is no big programming overhead in defining variable types and setting up loops. I'm running into this as a J beginner
On Jan 27, 10:44 pm, markg <m...@maxrnd.com> wrote:
> On Jan 27, 2:04 pm, "Aaron W. Hsu" <arcf...@sacrideo.us> wrote:
> > Does anyone have any cool, concise, but very impressive examples of APL's
> > capabilities?
> Impressive: the FinnAPL Idiom List and the IBM APL Idiom List. Very
> impressive: Roy Sykes' Whizbang! columns in Quote Quad. I don't have
> links at hand; consider these Google fodder.
> ..mark
Forwarded from: Kai Jaeger
> Impressive: the FinnAPL Idiom List and the IBM APL Idiom List.
The FinnAPL list is outdated; both are not exactly brilliantly
documented. Many expressions on the APL2 list won't work elsewhere.
This however is not only pure Dyalog APL, all the stuff is written in
D (or "direct function/operators), a functional branch in Dyalog APL.
It has been written by one of APL's grand masters, John Scholes, who
was also behind the most amazing APL-related video I've seen so far:
g is the (scalar) operation of a finite abelian group of order m. The
group elements are renumbered such that 0 is the identity element.
gi is the inverse of g.
(∘.≠⍨⍳m) is the logical negation of the identity matrix of order m.
The line (⍳m) g gi (∘.≠⍨⍳m)g.×⍵ computes, for each element i of ⍳m,
the element i g gi j, where j←g/(⍳m)~i, the g-reduction of all
elements of ⍳m excepting i. The inner product g.× is neat because the
× is ordinary arithmetic multiplication whereas g is the operation of
an arbitrary finite group. The line in APL compares favorably with
its statement in J,
(⍳m) g gi (∘.≠⍨⍳m)g.×⍵
(i.m) g gi 1 g/\.y
which uses the "outfix" g/\.
The expressions arise in a solution to the 88 hats problem (URL
above), previously solved by John Randall, J user and professor of
mathematics and by Ronald Chan, Ph.D. candidate in engineering and
winner of the Dyalog programming contest in 2009.
88 people stand in a circle, each having a hat with a number from 0 to
87 written on it. Everyone can see the numbers on other people’s hats
but can not see his own number. They simultaneously write a number on
a piece of paper and give it to the judge. If at least one of them
wrote a number that is on his own hat then everyone wins, otherwise
everyone loses. What strategy should they use to guarantee victory?
(Numbers on the hats do not have to be all different. People can not
exchange any information during the procedure but can agree on some
strategy beforehand.)
On Jan 27, 2:04 pm, "Aaron W. Hsu" <arcf...@sacrideo.us> wrote:
> Does anyone have any cool, concise, but very impressive examples of APL's
> capabilities?
Long time APL/J users (myself included) sometimes forget that many
simple expressions are impressive even though they are "old hat" and
likely taught on the first day of an introductory APL course. For
example:
x+y - x plus y where x and y can be scalar, vector, matrix, ...
x×y - x times y where x and y can be scalar, vector, matrix, ...
x⌈y - x max y where x and y can be scalar, vector, matrix, ...
+⌿x - the sum of x
×⌿x - the product of x
⌈⌿x - the maximum of x
⍋ages - the indices that would put ages in ascending order
ages[⍋ages] - sort ages
names[⍋ages;] - names sorted by ages
If you don't think these are impressive, try writing them in any other
programming language.
On Jan 27, 2:04 pm, "Aaron W. Hsu" <arcf...@sacrideo.us> wrote:
While I do think that in and of themselves, many of these examples are
rather impressive to some degree, I do find that among PL researchers this
is not nearly as impressive, since many of them work on languages that
have similar things. For example, many would say that such things are not
so bad in other languages like Haskell or Scheme. If you know anything
about these other languages and can compare for me what you think, I would
appreciate it. In particular, I'm quite interesting in hearing what other
APLers think are the really differentiating features of APL compared to
other frontier PL languages. Granted, of course, APL is actually a mature,
very delivered product, while many research languages are quite
unfinished, but I do not think that we can say this about languages like
ArBB, Haskell, Scheme, ML, or Matlab. Here are some examples of those when
encoded into Scheme:
(map + x y) ; X and Y must be lists
(map * x y) ; X and Y must be lists
(map max x y) ; X and Y must be lists
(fold-left + 0 x) ; X must be a list
(fold-left * 1 x) ; X must be a list
(fold-left max -inf.0 x) ; X must be a list
(list-sort < ages) ; AGES must be a list
(map car (list-sort (lambda (x y) (< (cdr x) (cdr y))) (map cons names
ages)))
; NAMES and AGES must be lists
To some extent these are not as flexible as the APL primitives, and I
think that's a key difference, from my perspective. These primitives are a
lot nicer because they are much more generic than some of the equivalent
expressions in other languages, and as such, require less mental overhead
to work with. On the other hand, some might argue that this isn't such a
big deal.
On Mon, 30 Jan 2012 19:42:36 -0500, Roger Hui <rogerhui.can...@gmail.com>
wrote:
> Long time APL/J users (myself included) sometimes forget that many
> simple expressions are impressive even though they are "old hat" and
> likely taught on the first day of an introductory APL course. For
> example:
> x+y - x plus y where x and y can be scalar, vector, matrix, ...
> x×y - x times y where x and y can be scalar, vector, matrix, ...
> x⌈y - x max y where x and y can be scalar, vector, matrix, ...
> +⌿x - the sum of x
> ×⌿x - the product of x
> ⌈⌿x - the maximum of x
> ⍋ages - the indices that would put ages in ascending order
> ages[⍋ages] - sort ages
> names[⍋ages;] - names sorted by ages
> If you don't think these are impressive, try writing them in any other
> programming language.
Two goats and a car are hidden behind 3 doors, one item per door. You
choose a door. The game-master (Monty Hall), who knows what's behind
the doors, opens one of the other doors, revealing a goat, and offers
you the opportunity to change your choice of doors. Your chosen door
is then opened and you get what is revealed.
Should you stick or change?
MontyHall←{
c←?⍵⍴3 ⍝ where the car is hidden
i←?⍵⍴3 ⍝ your original choice of door
~⍺:c,[0.5]i
j←(c×i≠c)+(3|1+i+?⍵⍴2)×i=c ⍝ your changed choice
c,[0.5]j
}
The result of ⍺ MontyHall ⍵ is a (⍵,2) matrix where column 0 is where
the car is hidden and column 1 is your original (if ⍺=0) choice of
door or your final (if ⍺=1) choice of door. The number of times you
win a car is therefore +/=/⍺ MontyHall ⍵.
> While I do think that in and of themselves, many of these examples are
> rather impressive to some degree, I do find that among PL researchers this
> is not nearly as impressive, since many of them work on languages that
> have similar things. For example, many would say that such things are not
> so bad in other languages like Haskell or Scheme. If you know anything
> about these other languages and can compare for me what you think, I would
> appreciate it. In particular, I'm quite interesting in hearing what other
> APLers think are the really differentiating features of APL compared to
> other frontier PL languages. Granted, of course, APL is actually a mature,
> very delivered product, while many research languages are quite
> unfinished, but I do not think that we can say this about languages like
> ArBB, Haskell, Scheme, ML, or Matlab. Here are some examples of those when
> encoded into Scheme:
> (map + x y) ; X and Y must be lists
> (map * x y) ; X and Y must be lists
> (map max x y) ; X and Y must be lists
> (fold-left + 0 x) ; X must be a list
> (fold-left * 1 x) ; X must be a list
> (fold-left max -inf.0 x) ; X must be a list
> (list-sort < ages) ; AGES must be a list
> (map car (list-sort (lambda (x y) (< (cdr x) (cdr y))) (map cons names
> ages)))
> ; NAMES and AGES must be lists
> To some extent these are not as flexible as the APL primitives, and I
> think that's a key difference, from my perspective. These primitives are a
> lot nicer because they are much more generic than some of the equivalent
> expressions in other languages, and as such, require less mental overhead
> to work with. On the other hand, some might argue that this isn't such a
> big deal.
> On Mon, 30 Jan 2012 19:42:36 -0500, Roger Hui <rogerhui.can...@gmail.com>
> wrote:
> > Long time APL/J users (myself included) sometimes forget that many
> > simple expressions are impressive even though they are "old hat" and
> > likely taught on the first day of an introductory APL course. For
> > example:
> > x+y - x plus y where x and y can be scalar, vector, matrix, ...
> > x×y - x times y where x and y can be scalar, vector, matrix, ...
> > x⌈y - x max y where x and y can be scalar, vector, matrix, ...
> > +⌿x - the sum of x
> > ×⌿x - the product of x
> > ⌈⌿x - the maximum of x
> > ⍋ages - the indices that would put ages in ascending order
> > ages[⍋ages] - sort ages
> > names[⍋ages;] - names sorted by ages
> > If you don't think these are impressive, try writing them in any other
> > programming language.
> 88 people stand in a circle, each having a hat with a number from 0 to
> 87 written on it. Everyone can see the numbers on other people’s hats
> but can not see his own number. They simultaneously write a number on
> a piece of paper and give it to the judge. If at least one of them
> wrote a number that is on his own hat then everyone wins, otherwise
> everyone loses. What strategy should they use to guarantee victory?
> (Numbers on the hats do not have to be all different. People can not
> exchange any information during the procedure but can agree on some
> strategy beforehand.)
> > 88 people stand in a circle, each having a hat with a number from 0 to
> > 87 written on it. Everyone can see the numbers on other people’s hats
> > but can not see his own number. They simultaneously write a number on
> > a piece of paper and give it to the judge. If at least one of them
> > wrote a number that is on his own hat then everyone wins, otherwise
> > everyone loses. What strategy should they use to guarantee victory?
> > (Numbers on the hats do not have to be all different. People can not
> > exchange any information during the procedure but can agree on some
> > strategy beforehand.)