Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!mm-mac18.mse.uiuc.edu!gaylord
From: Richard J. Gaylord <gaylord@ux1.cso.uiuc.edu>
Subject: "What is J? tutorial into Mathematica
References: <WEG.92Sep21143745@mace.cc.purdue.edu>
Message-ID: <Buz6Jq.8KC@news.cso.uiuc.edu>
X-Xxdate: Tue, 22 Sep 92 05:33:01 GMT
Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
X-Useragent: Nuntius v1.1.1d11
Organization: University of Illinois
Date: Tue, 22 Sep 1992 10:31:01 GMT
X-Xxmessage-Id: <A6E4608DE8019B12@mm-mac18.mse.uiuc.edu>
Lines: 87

desperately trying to avoid preparing my lecture, i decided to translate
the very nice  examples from the "What is J?" article by Leroy Dickey
into Mathematica . 

here they  are:

a = Range[0,8]
{0, 1, 2, 3, 4, 5, 6, 7, 8}

a!
{1, 1, 2, 6, 24, 120, 720, 5040, 40320}

N[1/a!]
{1., 1., 0.5, 0.166667, 0.0416667, 0.00833333, 0.00138889, 0.000198413,
0.0000248016}

Apply[Plus, N[1/a!]]
2.71828

average[x_List] := N[Apply[Plus, x]/Length[x]]

average[Range[4]]
2.5

continuedFraction[x_,n_] := NestList[(1 + 1/#)&,x,n-1]

continuedFraction[1.,15]
{1., 2., 1.5, 1.66667, 1.6, 1.625, 1.61538, 1.61905, 1.61765, 1.61818,
1.61798, 1.61806, 1.61803, 1.61804, 1.61803}

a = {100,200};
b = {10,20,30};
c = {1,2,3,4};

data = Outer[Plus,a,b,c]
{{{111, 112, 113, 114}, {121, 122, 123, 124}, {131, 132, 133, 134}}, 
 {{211, 212, 213, 214}, {221, 222, 223, 224}, {231, 232, 233, 234}}}

Dimensions[data]
{2, 3, 4}

Apply[Plus,data]
{{322, 324, 326, 328}, {342, 344, 346, 348}, {362, 364, 366, 368}}

Apply[Plus,data,{2}]
{{450, 490, 530}, {850, 890, 930}}

Apply[Plus,Transpose[data]]
{{363, 366, 369, 372}, {663, 666, 669, 672}}

average[data]
{{161., 162., 163., 164.}, {171., 172., 173., 174.}, {181., 182., 183.,
184.}}

Map[average,data,{2}]
{{112.5, 122.5, 132.5}, {212.5, 222.5, 232.5}}

Map[average,data]
{{121., 122., 123., 124.}, {221., 222., 223., 224.}}

Dimensions[Apply[Plus,data,{2}]]
{2, 3}

Dimensions[Map[average,data,{2}]]
{2, 3}

Dimensions[Apply[Plus,Transpose[data]]]
{2, 4}

Dimensions[Map[average,data]]
{2, 4}

===============

final notes: 

(1) for APL traditionalists who like runic symbols (no offense intended;
i personally find APL notation to be terrific), we can give Mathematica
built-in functions short names.

di = Dimensions;

di[data]
{2, 3, 4}

(2) these examples were created in and pasted from a Mathematica notebook
(which is  really just a very, very, fancy workspace).
