Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Small, cool examples of APL's power
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Aaron W. Hsu  
View profile  
 More options Jan 27, 5:04 pm
Newsgroups: comp.lang.apl
From: "Aaron W. Hsu" <arcf...@sacrideo.us>
Date: Fri, 27 Jan 2012 17:04:44 -0500
Local: Fri, Jan 27 2012 5:04 pm
Subject: Small, cool examples of APL's power
Does anyone have any cool, concise, but very impressive examples of APL's  
capabilities?

--
Aaron W. Hsu | arcf...@sacrideo.us | http://www.sacrideo.us
לֵ֤ב חֲכָמִים֙ בְּבֵ֣ית אֵ֔בֶל וְלֵ֥ב כְּסִילִ֖ים בְּבֵ֥ית שִׂמְחָֽה


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
markg  
View profile  
 More options Jan 27, 5:44 pm
Newsgroups: comp.lang.apl
From: markg <m...@maxrnd.com>
Date: Fri, 27 Jan 2012 14:44:09 -0800 (PST)
Local: Fri, Jan 27 2012 5:44 pm
Subject: Re: Small, cool examples of APL's power
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Richmond  
View profile  
 More options Jan 27, 7:48 pm
Newsgroups: comp.lang.apl
From: "Charles Richmond" <netn...@aquaporin4.com>
Date: Fri, 27 Jan 2012 18:48:13 -0600
Local: Fri, Jan 27 2012 7:48 pm
Subject: Re: Small, cool examples of APL's power
"Aaron W. Hsu" <arcf...@sacrideo.us> wrote in message
news:op.v8rjl6bm0p3ku8@localhost...

> 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     |
+<><><><><><><><><><><><><><><><><><><>+


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Don Kelly  
View profile  
 More options Jan 27, 9:36 pm
Newsgroups: comp.lang.apl
From: Don Kelly <d...@shawcross.ca>
Date: Fri, 27 Jan 2012 18:36:55 -0800
Local: Fri, Jan 27 2012 9:36 pm
Subject: Re: Small, cool examples of APL's power
On 27/01/2012 2:04 PM, Aaron W. Hsu wrote:
> 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

--
Don Kelly
cross out to reply


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Last  
View profile  
 More options Jan 28, 7:01 am
Newsgroups: comp.lang.apl
From: Phil Last <phil.l...@ntlworld.com>
Date: Sat, 28 Jan 2012 04:01:00 -0800 (PST)
Subject: Re: Small, cool examples of APL's power
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.

Anyway, you can find the APL2-related stuff at:

http://aplwiki.com/PhraseBook/ToDo/Apl2Idioms

and the FinnAPL stuff:

http://aplwiki.com/FinnAplIdiomLibrary

Recently a project started on the APL wiki; goal is to put up a
collection of one-liners which are up-to-date and well-documented:

http://aplwiki.com/CategoryPhrasesAll

These are vendor independent. However,the large number of volunteers
makes this a slow process... ;)

But APL is not about one-liners. In fact we should provide one-liners
only if they come naturally.

The arguably best source  for amazing stuff you can do with APL is
probably:

http://dfns.dyalog.com/

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:

http://www.youtube.com/watch?v=a9xAKttWgP4

You can even calculate the Life, the Universe and Everything in APL:

      MeaningOfLife←{+.×/⍎⊖⍕⊃¨⊂|⌊-*+○⌈∨.∧/>\</×÷!⌽⍉⌹~⍴⍋⍒,⍟?⍳''≡1↑0⍴∊⍵}

For details see

http://aplwiki.com/MeaningOfLife


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roger Hui  
View profile  
 More options Jan 30, 7:00 pm
Newsgroups: comp.lang.apl
From: Roger Hui <rogerhui.can...@gmail.com>
Date: Mon, 30 Jan 2012 16:00:29 -0800 (PST)
Local: Mon, Jan 30 2012 7:00 pm
Subject: Re: Small, cool examples of APL's power

> Does anyone have any cool, concise, but very impressive examples of APL's
> capabilities?

I have a recent example from the "88 Hats" problem.
http://www.jsoftware.com/papers/88hats.htm .  The line is
   (⍳m) g gi (∘.≠⍨⍳m)g.×⍵
This takes some explanation.

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roger Hui  
View profile  
 More options Jan 30, 7:42 pm
Newsgroups: comp.lang.apl
From: Roger Hui <rogerhui.can...@gmail.com>
Date: Mon, 30 Jan 2012 16:42:36 -0800 (PST)
Local: Mon, Jan 30 2012 7:42 pm
Subject: Re: Small, cool examples of APL's power

> 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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron W. Hsu  
View profile  
 More options Jan 30, 7:56 pm
Newsgroups: comp.lang.apl
From: "Aaron W. Hsu" <arcf...@sacrideo.us>
Date: Mon, 30 Jan 2012 19:56:27 -0500
Local: Mon, Jan 30 2012 7:56 pm
Subject: Re: Small, cool examples of APL's power
Hey Roger:

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:

--
Aaron W. Hsu | arcf...@sacrideo.us | http://www.sacrideo.us
לֵ֤ב חֲכָמִים֙ בְּבֵ֣ית אֵ֔בֶל וְלֵ֥ב כְּסִילִ֖ים בְּבֵ֥ית שִׂמְחָֽה

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roger Hui  
View profile  
 More options Jan 30, 8:44 pm
Newsgroups: comp.lang.apl
From: Roger Hui <rogerhui.can...@gmail.com>
Date: Mon, 30 Jan 2012 17:44:27 -0800 (PST)
Local: Mon, Jan 30 2012 8:44 pm
Subject: Re: Small, cool examples of APL's power
A couple of the phrases in your msg are crucial:

Zero, "X and Y must be lists".  The APL expressions work for arrays of
any rank.

One, "require less mental overhead".  You can buy a more powerful
computer, but you can't buy a more powerful head!

Another couple of further examples which are instances of the "old
hat" ideas but uses other functions.

0. Simulate the number of heads in n coin flips:
      ?10⍴2
1 0 1 1 0 1 1 0 1 0
      n←1e6
      +/?n⍴2
500953
      +/?n⍴2
500682
      +/?n⍴2
499842

1. Simulate n trials of the Monty Hall problem.
http://www.jsoftware.com/jwiki/Essays/The_Monty_Hall_Problem

The object of the game is to win a car.

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 ⍵.

      0 MontyHall 10
2 0
2 1
1 0
0 2
2 2
1 0
0 0
0 2
1 2
0 0
      +/=/0 MontyHall 1e6
333361
      +/=/0 MontyHall 1e6
332578

      1 MontyHall 10
1 1
1 0
1 1
1 1
2 2
1 0
1 2
2 2
0 0
2 0
      +/=/1 MontyHall 1e6
667164
      +/=/1 MontyHall 1e6
666692

I am also interested in how you'd do the g.× inner product in other
languages.

On Jan 30, 4:56 pm, "Aaron W. Hsu" <arcf...@sacrideo.us> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bakul Shah  
View profile  
 More options Jan 31, 2:34 am
Newsgroups: comp.lang.apl
From: Bakul Shah <use...@bitblocks.com>
Date: Mon, 30 Jan 2012 23:34:34 -0800
Local: Tues, Jan 31 2012 2:34 am
Subject: Re: Small, cool examples of APL's power
On 1/30/12 4:00 PM, Roger Hui wrote:

> 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.)

They agree to write the same number?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roger Hui  
View profile  
 More options Jan 31, 8:04 am
Newsgroups: comp.lang.apl
From: Roger Hui <rogerhui.can...@gmail.com>
Date: Tue, 31 Jan 2012 05:04:49 -0800 (PST)
Local: Tues, Jan 31 2012 8:04 am
Subject: Re: Small, cool examples of APL's power

> They agree to write the same number?

Let's say they all agree to write 0.  But the hats all had 1.

On Jan 30, 11:34 pm, Bakul Shah <use...@bitblocks.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »