Decode/Encode

33 views
Skip to first unread message

Ajay Askoolum

unread,
Sep 27, 2020, 12:53:39 PM9/27/20
to APLWin
Given:

L←63 83 45 68 86 29 89 53 31 7 
R←39 12 23 90 59 18 73 2 76 74

L⊤L⊥R

39 12 24 22 59 18 73 4 23.5 6

Why does the result contain 23.5 & not 24?

Ideas?

Roy Sykes

unread,
Sep 27, 2020, 6:24:24 PM9/27/20
to APLWin
Precision.  That [weird] argument to decode produces
25470244737473360, which needs 54.5 bits to represent,
but 64-bit floating point only has 52.  So the final couple
of decimal digits presented are spurious.

Anyway, the encode proceeds as follows ([]PP=17 and []CT=0):

      L←63 83 45 68 86 29 89 53 31 7 
      R←39 12 23 90 59 18 73 2 76 74
      2 {log} []  ← Z  ← L⊥R
25470244737473360                            Z is result of decode
54.49966234038716

     
2 {log} []  ← Z <- (Z-[]  ← 7|Z)÷7
6                                                                 
last item of result of encode               
3638606391067621.6                         final digits spurious
51.69230741832956                           representable precision now

      2 {log} []  ← Z  ← (Z-[]  ← 31|Z)÷31        
23.5                                                          
penultimate item of result
1173743997118588
46.73811110794268

     
Z  ← (Z-[]  ← 53|Z)÷53
4                                                                  antepenultimate item of result                                
... and so on

Ajay Askoolum

unread,
Sep 28, 2020, 1:22:16 AM9/28/20
to APLWin
Thank you. I tried the same expression with APLX & Dyalog and got different results.

Does it make sense to ask "What is the maximum value of L⊥R at or below which the result of L⊤L⊥R is 'accurate'?"

Roy Sykes

unread,
Sep 28, 2020, 2:59:30 AM9/28/20
to APLWin
If implemented correctly, all implementations should "max out" on
accuracy once the result of  ⊥  exceeds 2*52 (actually, up to 2*53
given some peculiarities of the IEEE standard for 64-bit floating point),
At that point, the modulus (residue) operation is dealing with sloppy
values, and thus returns sloppy results.  Those low-order digits are
not accurate, and those are precisely what  |  returns. 

Ajay Askoolum

unread,
Sep 28, 2020, 5:16:54 AM9/28/20
to APLWin
Another quick question based on this:

           L =   95 13 35 74 99 65 29 60 61
           R =   69 80 35 39 2 19 97 43 73
       2⍟L⊥R =   50.61978262
       L⊤L⊥R =   75 3 0 39 2 22 10 44 12
 your method =   75 3 0 39 2 22 10 44.1953125 0

(Note: the last two values do not match)

I coded 'your method'  thus:
    ∇ Z←L encodex R
[1]   Z←0/0
[2]   :for i :in ⌽⍳⍴L
[3]       R←(R-q←L[i]∣R)÷L[i]
[4]       Z,←q
[5]   :endfor
[6]   Z←⌽Z

Is there some other issue afoot?

Roy Sykes

unread,
Sep 28, 2020, 10:35:03 AM9/28/20
to APLWin
You're using default []CT=1E-13.  You forgot to set  []CT← 0. 
The reason:  | (modulus, residue) is []CT-sensitive.  ⊤  (encode, represent) is not.

P.S.  You need line [6] because of line [4] Z ,←q which is the same as Z ←Z,q.
If you change line [4] to Z←q,Z then you can eliminate line [6].   You might also
want to localize i and q.

Ajay Askoolum

unread,
Sep 28, 2020, 11:58:48 AM9/28/20
to APLWin
The function was a rough & ready trial of your iterative code (not tidied up in any way) built for testing only.
I don't think I've ever needed to localize []ct in any code I've written to date!
Roy, thanks for sharing your insight. Much appreciated.

Reply all
Reply to author
Forward
0 new messages