justin2004
justin2004

Reputation: 305

dyalog apl recognized idiom for `and` reduction

In Dyalog APL, could G be recognized as an idiom that evaluates to F since F is more efficient?

In order to do that maybe the interpreter first needs to know if it has a boolean array argument?

      G
 ∧/ ,
      F
~ 0 ∘∊ 
      v←¯1+∘?¨100 ⍴¨ 1e6⍴2
      cmpx 'F¨v' 'G¨v'
  F¨v → 1.7E¯1 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕           
  G¨v → 2.4E¯1 | +39% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕

Upvotes: 0

Views: 82

Answers (1)

Silas
Silas

Reputation: 336

The short answer to your question is yes. Dyalog could chose to extend the idiom list to include an "all ones" expression. An example of what you suggest does indeed occur - NA⊃¨⊂XV is implemented as XV[NA]

Idiom recognition happens in the scanner with usage decided at runtime, due to factors as such as type information and problems with stranding (eg. wanting to reject 1 0=⍴X)

Upvotes: 1

Related Questions