## addition on 1-byte integers

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

### addition on 1-byte integers

In previous posts, Membership, Index-Of, Interval Index, and Replicate, the game was to write functions g such that

`      (x symbol y) ≡ x g y`

for x and y of interest where g does not use the primitive symbol in question. Here, the game is to write a function h which does not use + or -, so that for 1-byte integer vectors x and y:

`      all1 ← {¯128,(⍎∊(⊂' ¯'),¨⍕¨⌽1↓a),a←⍳128}  ⍝ all 1-byte ints      A ← all1 ⍬      x ← A[?5678 ⍴ ≢A]      y ← A[?5678 ⍴ ≢A]      (x+y) ≡ x h y1`

⎕io←0 is assumed. ⎕io delenda est!

Base Value

`      p1b ← {1⊥⍺,[¯0.5]⍵}      (x+y) ≡ x p1b y1`

From the definition of ⍺⊥⍵ it can be shown that 1⊥⍺,⍵ ←→ ⍺+⍵ and more generally 1⊥⍺,[¯0.5]⍵ ←→ ⍺+⍵.

Table Look-Up

`      plus1T ← {256 256 ↑ 256 514 ⍴ (⍎∊(⊂' ¯'),¨⍕¨⌽1↓v),v←⍳257}                        ⍝ addition table for 1-byte ints       A ← all1 ⍬      T ← plus1T ⍬      p1t ← {T[(A⍳⍺),¨(A⍳⍵)]}       (x+y) ≡ x p1t y1`

p1t is substantially slower than p1b.
Roger|Dyalog

Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Return to APL Chat

### Who is online

Users browsing this forum: No registered users and 1 guest