addition on 1-byte integers
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 !
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 !
1 post
• Page 1 of 1
addition on 1-byte integers
In previous posts, Membership, Index-Of, Interval Index, and Replicate, the game was to write functions g such that
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:
⎕io←0 is assumed. ⎕io delenda est!
Base Value
From the definition of ⍺⊥⍵ it can be shown that 1⊥⍺,⍵ ←→ ⍺+⍵ and more generally 1⊥⍺,[¯0.5]⍵ ←→ ⍺+⍵.
Table Look-Up
p1t is substantially slower than p1b.
(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 y
1
⎕io←0 is assumed. ⎕io delenda est!
Base Value
p1b ← {1⊥⍺,[¯0.5]⍵}
(x+y) ≡ x p1b y
1
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 y
1
p1t is substantially slower than p1b.
- Roger|Dyalog
- Posts: 238
- Joined: Thu Jul 28, 2011 10:53 am
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group