Large Integer (dnfn big) Issue

General APL language issues

Large Integer (dnfn big) Issue

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

Notice that with plus the result is text.
`      ⍴⎕←2+big 3456789876544567896545674045678987802514`
And wrong!

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

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

But only for odd numbers!
`      ⍴⎕←2|big '3456789876544567896545678'21`

Phil Last

Posts: 614
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Large Integer (dnfn big) Issue

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

`      4|big 444`

`      15|big 3015`
KamakaniKing

Posts: 14
Joined: Thu Mar 25, 2021 8:06 pm

Re: Large Integer (dnfn big) Issue

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 01 0`

Other basic functions look ok....
`      '0'=¯2+big 21      '0'=2-big 21      '0'=2×big 01      '0'=16÷big 221`

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 909876541      0=45673≥big 909876541      0=45673≠big 456731`
KamakaniKing

Posts: 14
Joined: Thu Mar 25, 2021 8:06 pm

Re: Large Integer (dnfn big) Issue

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.

Phil Last

Posts: 614
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Large Integer (dnfn big) Issue

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.

Morten|Dyalog

Posts: 436
Joined: Tue Sep 09, 2008 3:52 pm

Re: Large Integer (dnfn big) Issue

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 465768798676565343316678771228987842Bad number: 4.657687987E35      2|nats 4.657687986765653E35       ∧⍝ Nats returns '0' and '1' from boolean tests...      '01'∊⍨45673>big 909876540      '01'∊⍨45673>nats 909876541      '01'∊⍨45673>nats 551`
Last edited by petermsiegel on Wed Jan 05, 2022 8:31 pm, edited 2 times in total.
petermsiegel

Posts: 127
Joined: Thu Nov 11, 2010 11:04 pm

Re: Large Integer (dnfn big) Issue

Well done Peter. That's the one.

Phil Last

Posts: 614
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Large Integer (dnfn big) Issue

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

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 FULLbig[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: 127
Joined: Thu Nov 11, 2010 11:04 pm