APL question

This is a discussion on APL question within the APL forums in Programming Languages category; Pete, Try to get your hands on FinnAPL Idiom Library. It's some 700 classified one-liners with comments, valuable stuff! jk. "Peter Keller" <psilord @ merlin.cs.wisc.edu> wrote in message news:48f8aa31$0$9898$80265adb @ spool.cs.wisc.edu... > James J. Weinkam <jjw @ cs.sfu.ca> wrote: >> Why are you writing your own function? Dyadic ! (binomial >> coefficient) >> is a primitive scalar function which does everything you want. >> >> 2!5 >> 10 >> {quad}IO{is}0 >> ({iota}6)!5 >> 1 5 10 10 5 1 > > *sheepish grin* I hadn't realized that function was available.... > > I realize that I will not be writing ...

Go Back   Application Development Forum > Programming Languages > APL

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
Reply

 

LinkBack Thread Tools Display Modes
  #11  
Old 10-17-2008, 11:24 AM
Jan Karman
Guest
 
Default Re: APL question

Pete,
Try to get your hands on FinnAPL Idiom Library.
It's some 700 classified one-liners with comments, valuable stuff!
jk.

"Peter Keller" <psilord@merlin.cs.wisc.edu> wrote in message
news:48f8aa31$0$9898$80265adb@spool.cs.wisc.edu...
> James J. Weinkam <jjw@cs.sfu.ca> wrote:
>> Why are you writing your own function? Dyadic ! (binomial
>> coefficient)
>> is a primitive scalar function which does everything you want.
>>
>> 2!5
>> 10
>> {quad}IO{is}0
>> ({iota}6)!5
>> 1 5 10 10 5 1

>
> *sheepish grin* I hadn't realized that function was available....
>
> I realize that I will not be writing good APL initially and have to
> unlearn
> habits from other languages to really understand APL. So, sometimes I
> may
> make missteps, like not realizing there was already something which
> would
> do exactly what I needed.
>
> Thank you.
>
> -pete



Reply With Quote
  #12  
Old 10-17-2008, 11:30 AM
Gosi
Guest
 
Default Re: APL question

On 17 Okt, 15:24, "Jan Karman" <aq...@planet.nl (remove the q's)>
wrote:
> Pete,
> Try to get your hands on FinnAPL Idiom Library.
> It's some 700 classified one-liners with comments, valuable stuff!
> jk.
>
> "Peter Keller" <psil...@merlin.cs.wisc.edu> wrote in message
>
> news:48f8aa31$0$9898$80265adb@spool.cs.wisc.edu...
>
> > James J. Weinkam <j...@cs.sfu.ca> wrote:
> >> Why are you writing your own function? Dyadic ! (binomial
> >> coefficient)
> >> is a primitive scalar function which does everything you want.

>
> >> * * * 2!5
> >> 10
> >> * * * {quad}IO{is}0
> >> * * * ({iota}6)!5
> >> 1 5 10 10 5 1

>
> > *sheepish grin* I hadn't realized that function was available....

>
> > I realize that I will not be writing good APL initially and have to
> > unlearn
> > habits from other languages to really understand APL. So, sometimes I
> > may
> > make missteps, like not realizing there was already something which
> > would
> > do exactly what I needed.

>
> > Thank you.

>
> > -pete


http://www.pyr.fi/apl/texts/Idiot.htm

http://en.wikipedia.org/wiki/Critici...mming_language



------------
Björn Helgason
http://groups.google.com/group/J-Programming
Reply With Quote
  #13  
Old 10-17-2008, 12:29 PM
Peter Keller
Guest
 
Default Re: APL question

Gosi <gosinn@gmail.com> wrote:
> http://www.pyr.fi/apl/texts/Idiot.htm


Unfortunately, even though I have several unicode APL fonts installed,
I see garbage for all of the idioms on that site.

> http://en.wikipedia.org/wiki/Critici...mming_language


Ah, but the pdf prints out nicely.

Thank you.

-pete
Reply With Quote
  #14  
Old 10-17-2008, 01:42 PM
Paul Houle
Guest
 
Default Re: APL question


Careful... {compose} is a new one on me. Don't think {compose} is
available in any of the APL's I use (APLX, APL2C, STSC APL).

"Stephen Taylor <editor@vector.org.uk>" <StephenTaylorFRSA@googlemail.com>
wrote in message
news:ba9a58ea-2bf0-40b2-981c-49b92d80ac10@l62g2000hse.googlegroups.com...
On Oct 17, 7:57 am, Peter Keller <psil...@merlin.cs.wisc.edu> wrote:
> Paul Houle <asmg...@yahoo.com> wrote:
> > You need to enclose the left argument (scalarizing it) to distribute it
> > properly across all the right arguments.

>
> > ({enclose}1 2) berp {each} 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1

>
> Hrm.... So once inside the berp function, how does berp know that the left
> hand side is a vector of length 2 where index 1 is 1 and index 2 is 2,
> instead
> of thinking that the left hand side is a single vector which contains
> one element which is another vector containing 1 and 2?
>
> I'm definitely confused on the semantic reasoning for why {enclose}
> behaves
> correctly in this case.
>
> I'm unsure what the difference are between these and why the
> implementation of berp knows what the left hand side looks like in the
> 1st and 4th example:
>
> 1 2 berp .5
> ({enclose}1 2) berp .5
> 1 2 berp {each} 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1
> ({enclose}1 2) berp {each} 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1
>
> Thank you.
>
> -pete


An alternative to enclosing the left argument is to use the compose
operator to curry it to a monadic function:

1 2{compose}berp {each} 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1

Sounds like that fits your thought more closely.

Stephen
editor@vector.org.uk


Reply With Quote
  #15  
Old 10-17-2008, 03:32 PM
Ibeam2000
Guest
 
Default Re: APL question


> I need to construct a binomial coefficient and have written a function like
> this:
>
> n binc i
> (x/{iota}n) {divide} (x/{iota}i) x x/{iota}n-i
>
> This works for things like 5 binc 2, which is 10.
>
> My question is: if i is a vector, so I might call the function like this:
>
> 5 binc 0 1 2 3 4 5
>
> How can I get the response of a vector like
> 1 5 10 10 5 1
> from binc?


Simply replace the x / iota with ! (exclamation point). Then this
function consists solely of scalar functions, and is a scalar function
itself. It will now work on arrays of any shape, plus work with
scalar extension.

The function should now look like:

R := (!N) % (!I) times !N-I

Like the original, it will also produce a DOMAIN ERROR if the sign of
N - I is negative.
Reply With Quote
  #16  
Old 10-17-2008, 06:46 PM
James J. Weinkam
Guest
 
Default Re: APL question

Peter Keller wrote:
> James J. Weinkam <jjw@cs.sfu.ca> wrote:
>> Why are you writing your own function? Dyadic ! (binomial coefficient)
>> is a primitive scalar function which does everything you want.
>>
>> 2!5
>> 10
>> {quad}IO{is}0
>> ({iota}6)!5
>> 1 5 10 10 5 1

>
> *sheepish grin* I hadn't realized that function was available....
>
> I realize that I will not be writing good APL initially and have to unlearn
> habits from other languages to really understand APL. So, sometimes I may
> make missteps, like not realizing there was already something which would
> do exactly what I needed.
>
> Thank you.
>
> -pete


You're welcome. You will find it worth your while to review the lists of
primitive functions and operators given in the reference manual
periodically so that you don't lose sight of the rich variety of
functions available.

Also I should point out that ! is more general than simple binomial
coefficient of integers. In fact it is defined (in terms of the Gamma
function) for all numeric arguments, including complex numbers (at lesst
in APL2). Monadic ! (factorial) is actually Gamma 1+r and is defined for
all complex values except the negative integers.

Similar remarks apply for most of the mathematical functions.
Reply With Quote
  #17  
Old 10-18-2008, 01:48 PM
Don Wiss
Guest
 
Default Re: APL question

On Fri, 17 Oct 2008 10:42:43 -0700, Paul Houle <asmguru@yahoo.com> wrote:

>Careful... {compose} is a new one on me. Don't think {compose} is
>available in any of the APL's I use (APLX, APL2C, STSC APL).


What does the {compose} character look like?

Don <www.donwiss.com> (e-mail link at home page bottom).
Reply With Quote
  #18  
Old 10-19-2008, 05:01 AM
Stephen Taylor
Guest
 
Default Re: APL question

On Oct 18, 7:48*pm, Don Wiss <donwiss@no_spam.com> wrote:
> On Fri, 17 Oct 2008 10:42:43 -0700, Paul Houle <asmg...@yahoo.com> wrote:
> >Careful... *{compose} is a new one on me. *Don't think {compose} is
> >available in any of the APL's I use (APLX, APL2C, STSC APL).

>
> What does the {compose} character look like?
>
> Don <www.donwiss.com> (e-mail link at home page bottom).


The compose operator is represented by the jot character. I'll
represent it here (inaccurately) by the ° symbol.

In its simplest usage the operator binds a left or right argument to a
dyadic function, producing a monadic function:

treble <- 3°×
halve <- ÷°2

Not to be confused with the jot character's role in representing the
outer-product operator. In its dyadic form it binds two functions.
Here the result of the first is the argument of the second

im <- {w°.=w}°{iota}
im 3
1 0 0
0 1 0
0 0 1

If you're into operators the above D-function (in Dyalog) can be
improved with the commute operator. This supplies the missing left
argument of a dyadic function by replicating its right argument, and
is represented by the diaresis/tilde overstrike sometimes called
{frog}. So:

+{frog}2
4
im <- °.={frog}°{iota}

I understand the dataflow analysis required for parallelisation is
simplified by functional style and that one day these compositions may
be blessed with free speedups. In the meantime, I watch, pray and hope
the exercise delays the onset of Alzheimer's.

A worked example of using compose appears in the "In Session" column
in Vector 23:1

http://www.vector.org.uk/archive/v231/insession.htm

SJT
Reply With Quote
  #19  
Old 10-19-2008, 10:59 AM
RHui000@shaw.ca
Guest
 
Default Re: APL question

> I understand the dataflow analysis required for parallelisation is
> simplified by functional style and that one day these compositions may
> be blessed with free speedups.


A more general statement is true today in J: optimizations
are facilitated by tacit definitions (a.k.a. functional style).
A list of about 100 such optimizations can be found in
http://www.jsoftware.com/help/dictionary/special.htm

An example of such optimizations is the fork f i. 1:
where f is a comparison, for example x (< i. 1 y
finds the smallest index where x is less than y .
Quoting from "Remembering Ken Iverson", November 2004,
http://keiapl.org/rhui/remember.htm#special , also
http://www.vector.org.uk/archive/v223/hui222.htm

If the target is found near the beginning of the search,
the result is computed instantaneously (and in time independent
of the lengths of the arguments for atomic verbs f).
Even if the target is found only at the end of the search,
the improvement in time is by a factor of two or more.
In either case the space used is constant for atomic verbs f .



On Oct 19, 2:01*am, "Stephen Taylor <edi...@vector.org.uk>"
<StephenTaylorF...@googlemail.com> wrote:
> On Oct 18, 7:48*pm, Don Wiss <donwiss@no_spam.com> wrote:
>
> > On Fri, 17 Oct 2008 10:42:43 -0700, Paul Houle <asmg...@yahoo.com> wrote:
> > >Careful... *{compose} is a new one on me. *Don't think {compose} is
> > >available in any of the APL's I use (APLX, APL2C, STSC APL).

>
> > What does the {compose} character look like?

>
> > Don <www.donwiss.com> (e-mail link at home page bottom).

>
> The compose operator is represented by the jot character. I'll
> represent it here (inaccurately) by the ° symbol.
>
> In its simplest usage the operator binds a left or right argument to a
> dyadic function, producing a monadic function:
>
> * * * treble <- 3°×
> * * * halve *<- ÷°2
>
> Not to be confused with the jot character's role in representing the
> outer-product operator. In its dyadic form it binds two functions.
> Here the result of the first is the argument of the second
>
> * * * im <- {w°.=w}°{iota}
> * * * im 3
> 1 0 0
> 0 1 0
> 0 0 1
>
> If you're into operators the above D-function (in Dyalog) can be
> improved with the commute operator. This supplies the missing left
> argument of a dyadic function by replicating its right argument, and
> is represented by the diaresis/tilde overstrike sometimes called
> {frog}. So:
>
> * * * +{frog}2
> 4
> * * * im <- °.={frog}°{iota}
>
> I understand the dataflow analysis required for parallelisation is
> simplified by functional style and that one day these compositions may
> be blessed with free speedups. In the meantime, I watch, pray and hope
> the exercise delays the onset of Alzheimer's.
>
> A worked example of using compose appears in the "In Session" column
> in Vector 23:1
>
> http://www.vector.org.uk/archive/v231/insession.htm
>
> SJT


Reply With Quote
  #20  
Old 10-21-2008, 04:57 AM
phil chastney
Guest
 
Default Re: APL question

Peter Keller wrote:
> Gosi <gosinn@gmail.com> wrote:
>> http://www.pyr.fi/apl/texts/Idiot.htm

>
> Unfortunately, even though I have several unicode APL fonts installed,
> I see garbage for all of the idioms on that site.


the page in question doesn't appear to specify any encoding, so the
browser will use its default setting

the HTML also specifies Dyalog Std TT as one of the fonts, which can be
downloaded from the Dyalog site, but it is something of a strange beast,
having Unicode values for some, but not all, of the non-ASCII characters

try switching your browser display to another encoding, one of which
will almost certainly work, because FinnAPL wouldn't publish rubbish
>
>> http://en.wikipedia.org/wiki/Critici...mming_language

>
> Ah, but the pdf prints out nicely.


PDF? the above URL points to an HTML page

it won't let you see the source, so I don't know if the code actually
specifies UTF-8, or just assumes all right-thinking people use UTF-8 as
default anyway

you can't examine the source, but you can edit the content -- doing so,
reveals that the character set is displayed by embedding HTML special
character codes -- and correct display therefore depends on the client
having a sufficiently well-populated font installed, but it does go to
show what's possible with APL code within HTML

the Finnish keyboard, OTOH, is a GIF file, not character display

HTH . . . /phil
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:40 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.