Question about inner product
12 posts
• Page 1 of 2 • 1, 2
Question about inner product
I just realized the following:
On v5 of APL+Win if I do:
On v13.2 of Dyalog Apl I don't get the same result (with ⎕ML←3):
Why I don't get the same result ? Wich one is the correct one ?
On v5 of APL+Win if I do:
2^.∊1 2 3
1
On v13.2 of Dyalog Apl I don't get the same result (with ⎕ML←3):
2∧.∊1 2 3
0
Why I don't get the same result ? Wich one is the correct one ?
Last edited by PGilbert on Wed Apr 02, 2014 8:14 am, edited 1 time in total.
-
PGilbert - Posts: 436
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: Question about outer product
Personally I should say that APL2000 is correct but I've never forked out the two or three hundred euros for the standard if it's even clarified in there.
In pre-nested APL only the scalar primitive arithmetic, relational and loicals could be used with outer- and inner-product and reduction. When Dyalog implemented inner-product they made no difference in the calling sequence with "mixed" functions from that already implemented for scalar functions.
One consequence is that the commonly held equivalence:
So we get the following dichotomy:
In pre-nested APL only the scalar primitive arithmetic, relational and loicals could be used with outer- and inner-product and reduction. When Dyalog implemented inner-product they made no difference in the calling sequence with "mixed" functions from that already implemented for scalar functions.
One consequence is that the commonly held equivalence:
f/a g b ←→ a f.g b ⍝ for vector a and bno longer holds.
So we get the following dichotomy:
'aeiou'='vowel'
0 0 0 0 0
∨/'aeiou='vowel'
0
'aeiou'∨.='vowel'
0
'aeiou'∊'vowel'
0 1 0 1 0
∨/'aeiou'∊'vowel'
1
'aeiou'∨.∊'vowel'
1 or 0 ?
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Question about outer product
Dyalog's inner product definition is an-item-at-a-time. You can watch it working by binding the operand functions with the "trace" operator from dfns.dws:
Like it or loath it, it's probably too late to change this now as it would affect people's working code.
John
'aeiou'∨.∊'vowel'
0
)copy dfns trace
u:\ws\dfns saved Tue Apr 01 21:01:57 2014
'aeiou'(∨trace).(∊trace)'vowel'
u ∊ l => 0
o ∊ e => 0
0 ∨ 0 => 0
i ∊ w => 0
0 ∨ 0 => 0
e ∊ o => 0
0 ∨ 0 => 0
a ∊ v => 0
0 ∨ 0 => 0
0
Like it or loath it, it's probably too late to change this now as it would affect people's working code.
John
- JohnS|Dyalog
Re: Question about inner product
Thanks Phil and John for your answer.
Here is another one:
will return 1 in APL2000 and a LENGTH ERROR with Dyalog.
So I will end-up writing:
To make it work in my case.
Thanks guys, I hope there is not too much like that when converting from APL2000.
Here is another one:
1 2 ∧.∊ 1 2 3
will return 1 in APL2000 and a LENGTH ERROR with Dyalog.
So I will end-up writing:
1 2 {∧/⍺∊⍵} 1 2 3
To make it work in my case.
Thanks guys, I hope there is not too much like that when converting from APL2000.
-
PGilbert - Posts: 436
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: Question about inner product
With APLX from MicroAPL I get the following results:
wich is consistent with APL2000. Anybody that has APL2 from IBM that would like to post the results of those 2 lines ?
1 2 ^.∊ 1 2 3
1
1 ^.∊ 1 2 3
1
wich is consistent with APL2000. Anybody that has APL2 from IBM that would like to post the results of those 2 lines ?
-
PGilbert - Posts: 436
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: Question about inner product
In APL2:
In Dyalog there is an implicit disclose so the result is
- Code: Select all
1^.∊1 2 3
1
1 2^.∊1 2 3
1
1 2^.∊(1 2 3) (2 90)
0
In Dyalog there is an implicit disclose so the result is
- Code: Select all
2∧.∊1 2 3
0
1 2∧.∊1 2 3
LENGTH ERROR
1 2∧.∊1 2 3
∧
1 2∧.∊(1 2 3) (2 90)
1
- DanB|Dyalog
Re: Question about inner product
so 2^.∊1 2 3 in APL+Win is equivalent to 2∧.∊⊂ 1 2 3 in Dyalog
I wouldn't really say APL200 is "correct" because the definition of inner product was extended from +.x & really required the first operation to return something of a conformable length. I remember attempting ∧.∊ when first learning APL and being "miffed" that it didn't work
2=1 2 3 (or whatever such scalar extension) will always return a 3 element vector 2∊ 1 2 3 returns a single element, so surely it is just a case of programming implementation?
In the sense that, we need a 3 element answer and have to extend the result of membership: so do we do either
( 2∊ 1 2 3)( 2∊ 1 2 3)( 2∊ 1 2 3)
or
( 2∊ 1)( 2∊ 2)( 2∊ 3)
before we do the ∧/
So I understand why they are different and I can't off hand think of a reason for preferring one over the other, except consistency within the interpreter.
It is just order of execution. John will probably correct me, but as Dan Baronet says "Dyalog is essentially scalar in operation" (correct me if I misquoted you Dan).
I wouldn't really say APL200 is "correct" because the definition of inner product was extended from +.x & really required the first operation to return something of a conformable length. I remember attempting ∧.∊ when first learning APL and being "miffed" that it didn't work
2=1 2 3 (or whatever such scalar extension) will always return a 3 element vector 2∊ 1 2 3 returns a single element, so surely it is just a case of programming implementation?
In the sense that, we need a 3 element answer and have to extend the result of membership: so do we do either
( 2∊ 1 2 3)( 2∊ 1 2 3)( 2∊ 1 2 3)
or
( 2∊ 1)( 2∊ 2)( 2∊ 3)
before we do the ∧/
So I understand why they are different and I can't off hand think of a reason for preferring one over the other, except consistency within the interpreter.
It is just order of execution. John will probably correct me, but as Dan Baronet says "Dyalog is essentially scalar in operation" (correct me if I misquoted you Dan).
- crishog
- Posts: 61
- Joined: Mon Jan 25, 2010 9:52 am
Re: Question about inner product
John wrote "Dyalog's inner product definition is an-item-at-a-time" (scalar application) and I wrote "there is an implicit disclose of the result" (before each scalar application).
The original definition was to apply F/ x G y on the rows of x vs the columns of y for SCALAR fns F and G.
With the advent of enclosed arrays the definition hasn't been reviewed and each vendor has done its own implementation.
The original definition was to apply F/ x G y on the rows of x vs the columns of y for SCALAR fns F and G.
With the advent of enclosed arrays the definition hasn't been reviewed and each vendor has done its own implementation.
- DanB|Dyalog
Re: Question about inner product
Is that according to the ISO/IEC 13751:2001 standard? Is it a good 238.00 Swiss Francs worth?Dan wrote: the definition hasn't been reviewed
I think Paul Chapman might have been first with "Dyalog APL is a scalar language" back in about '91 or '92Chris wrote:"Dyalog is essentially scalar in operation" (correct me if I misquoted you Dan)
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Question about inner product
Interesting issue .
K doesn't an inner product other than a _dot function .
However it has explicit eachLeft , \: and eachRight , /: which I'll take in exchange .
I think John's item-wise application is most in the spirit of the inner product but the f / x g y definition is compelling .
Perhaps a general definition should be that g is taken to act on atoms of x with atoms of y .
What is J's definition ?
K doesn't an inner product other than a _dot function .
However it has explicit eachLeft , \: and eachRight , /: which I'll take in exchange .
I think John's item-wise application is most in the spirit of the inner product but the f / x g y definition is compelling .
Perhaps a general definition should be that g is taken to act on atoms of x with atoms of y .
What is J's definition ?
-
Bob Armstrong - Posts: 26
- Joined: Wed Dec 23, 2009 8:41 pm
- Location: 39.038681° -105.079070° 2500m
12 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group