Large Integer (dnfn big) Issue

General APL language issues

Large Integer (dnfn big) Issue

Postby KamakaniKing on Sat Jan 01, 2022 5:37 pm

It appears that using the dnfn big with the modulo function has issues:
2|big 465768798676565343316678771228987842
¯41096949494949494949494949494949489883726150818384151632816178265960457

2|big 987675464324
2

Has anyone else seen this?

https://dfns.dyalog.com/n_big.htm
KamakaniKing
 
Posts: 14
Joined: Thu Mar 25, 2021 8:06 pm

Re: Large Integer (dnfn big) Issue

Postby Phil Last on Sun Jan 02, 2022 12:48 pm

Notice that with plus the result is text.
      ⍴⎕←2+big 345678987654456789654567
40456789878025
14
And wrong!

It works with a quoted right argument.
      ⍴⎕←2+big '345678987654456789654567'
345678987654456789654569
24


With modulus it works
      ⍴⎕←2|big '345678987654456789654567'
1
1

But only for odd numbers!
      ⍴⎕←2|big '3456789876544567896545678'
2
1
User avatar
Phil Last
 
Posts: 606
Joined: Thu Jun 18, 2009 6:29 pm

Re: Large Integer (dnfn big) Issue

Postby KamakaniKing on Sun Jan 02, 2022 3:59 pm

Actually, it seems to return the modulus when the result should be zero, regardless of quoted or not. Examples:
      3|big 33
3

      4|big 44
4

      15|big 30
15
KamakaniKing
 
Posts: 14
Joined: Thu Mar 25, 2021 8:06 pm

Re: Large Integer (dnfn big) Issue

Postby KamakaniKing on Sun Jan 02, 2022 6:15 pm

It also looks like the big modulus function returns the number zero instead of the character vector '0' when the right hand operand is zero, contrary to the documentation. This appears to only affect the modulus function. Examples:
      (0 '0')=16|big '0'
1 0
(0 '0')=16|big 0
1 0

Other basic functions look ok....
      '0'=¯2+big 2
1
'0'=2-big 2
1
'0'=2×big 0
1
'0'=16÷big 22
1

The compare functions all seem to return a number 0 or 1 which may be the programmers intent but the documentation doesn't state this.
      0=45673>big 90987654
1
0=45673≥big 90987654
1
0=45673≠big 45673
1
KamakaniKing
 
Posts: 14
Joined: Thu Mar 25, 2021 8:06 pm

Re: Large Integer (dnfn big) Issue

Postby Phil Last on Wed Jan 05, 2022 12:14 am

It appears that all calls go through one or other, several or many "⍕"s in repeated calls to signum, trim, div &c. to ensure that the argument is at least treated as text.

Precision will be fatally compromised for unquoted arguments with more than ⎕PP (default 10, max 34) digits and no attempt is made to maximise this value or to avoid "E" notation and its equally fatal effects.

For values less than and perhaps equal to ⎕PP digits it will make no difference whether the argument is quoted or not.

I believe Roger Hui had a possibly more rigorous operator to do the same job but I can't presently think where to look.
User avatar
Phil Last
 
Posts: 606
Joined: Thu Jun 18, 2009 6:29 pm

Re: Large Integer (dnfn big) Issue

Postby Morten|Dyalog on Wed Jan 05, 2022 8:10 am

Unfortunately, John Scholes is no longer around to fix these issues with the "big" code. We're scrambling to understand exactly what needs to be done and will update the workspace when we can, and also work to put the source in a GitHub repository so that community contributions will become easier to make.
User avatar
Morten|Dyalog
 
Posts: 432
Joined: Tue Sep 09, 2008 3:52 pm

Re: Large Integer (dnfn big) Issue

Postby petermsiegel on Wed Jan 05, 2022 9:57 am

Did you try nats as an alternative? Its domain is non-negative integer strings (and integers that can be so represented via ⍕). In the past, I used it a lot and (unless something changed-- I didn't recheck) it avoids these modulus problems for quoted integers.

When entering APL numbers directly, see the advice at notes.nats in dfns.

Quick test...
Code: Select all
      2|nats '465768798676565343316678771228987842'
0
    ⍝ Too long to represent in integer form
      2|nats 465768798676565343316678771228987842
Bad number: 4.657687987E35
      2|nats 4.657687986765653E35
       ∧
⍝ Nats returns '0' and '1' from boolean tests...
      '01'∊⍨45673>big 90987654
0
      '01'∊⍨45673>nats 90987654
1
      '01'∊⍨45673>nats 55
1
Last edited by petermsiegel on Wed Jan 05, 2022 8:31 pm, edited 2 times in total.
petermsiegel
 
Posts: 123
Joined: Thu Nov 11, 2010 11:04 pm

Re: Large Integer (dnfn big) Issue

Postby Phil Last on Wed Jan 05, 2022 10:46 am

Well done Peter. That's the one.
User avatar
Phil Last
 
Posts: 606
Joined: Thu Jun 18, 2009 6:29 pm

Re: Large Integer (dnfn big) Issue

Postby KamakaniKing on Thu Jan 06, 2022 5:38 pm

Thx Peter - This works for me... would be even better if it could handle negative numbers. Performance increase over big is really nice.
KamakaniKing
 
Posts: 14
Joined: Thu Mar 25, 2021 8:06 pm

Re: Large Integer (dnfn big) Issue

Postby petermsiegel on Thu Jan 06, 2022 10:36 pm

Agreed. Nats was a much better choice for building my own signed routines, in part because (at least in the past, when I did this) it seems to be more efficient in terms of time and space and in part because it's easier to build on its internal format to create more complicated routines, like integer square root (or N-th root).

Here are some random stats:
Code: Select all
       
       a←300⍴⎕D
       b←⌽a
       cmpx 'a ×nats b'  'a ×big b'
  a ×nats b → 1.7E¯4 |    0% ⎕⎕⎕⎕                                   
  a ×big b  → 1.6E¯3 | +857% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
       a←3000⍴⎕D
       b←⌽a
       cmpx 'a ×nats b'  'a ×big b'
  a ×nats b → 2.0E¯3 |     0% ⎕⎕                                     
  a ×big b  → 3.6E¯2 | +1672% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
       a←10000⍴⎕D
       b←⌽a
       cmpx  'a ×nats b'   
1.2E¯2
       cmpx   'a ×big b'
WS FULL
big[55] t←+⌿(¯1+⍳⍴w)⌽((2⍴⍴w)⍴0),⊖w∘.×a

⍝ Add: same 10000 item a and b
       cmpx 'a +nats b'  'a +big b'
  a +nats b → 9.4E¯5 |      0%                                         
  a +big b  → 6.8E¯2 | +71933% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕

Cheers, all.
petermsiegel
 
Posts: 123
Joined: Thu Nov 11, 2010 11:04 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest