Henry has introduced a new primitive for finite arithmetic, m.
NuVoc already has an entry in
https://code.jsoftware.com/wiki/NuVoc
and further details in
https://code.jsoftware.com/wiki/Vocabulary/mdot
In accordance with the current beta, we see on that page:
"
x % m. n y, and x ^ m. n y when y is negative, operate on the
modular multiplicative
inverse and give domain error if that inverse does not exist
"
He and I have corresponded briefly about the best option here. He
suggests opening the
discussion to the J forum(s).
There is a possibility to change behaviour in the presence of "errors";
instead of domain error,
the result could include "wrong" value(s), probably 0 to keep the
result integer, or, much less
likely to be implemented, positive or negative infinity - more
obviously "wrong" but promoting
all values in an array from integer to floating.
Here's the behaviour for a prime modulus, m, with all arguments in
[1,...,m-1] :
minv =: {{ 1 % m. x y }}
mtimes =: {{ x * m. m y }}
5 minv q =. >:i.4
1 3 2 4
q (5 mtimes) 5 minv q
1 1 1 1
but, currently, for a simple composite modulus:
10 minv r =. 1 3 7 9 NB. inverse mod 10 is well -defined for 1 3 7
9 only
1 7 3 9
10 minv q =. >:i.9
|domain error in minv, executing dyad %m.10
| 1 %m.x y
We could do-it-ourselves to ensure results with an inefficient
get-around such as:
minv0 =: {{ try.
1 % m. x y
catch.
0 NB. or _ or __ ???
end.
}} " 0
10 minv0 q =. >:i.9
1 0 7 0 0 0 3 0 9
but it would be more efficient for these "wrong" answers to be done under
the bonnet/hood.
We as users would of course need to be aware that 0s would be
unreliable items in
the array.
Henry points out that J routinely returns
0 % 0
0
ALSO:
Despite a remark about monads on that page, I believe Henry intends to
also allow the monad case for - so that both these would result in 2 :
0 ( - m. 5) 3
2
( - m. 5) 3
|valence error, executing monad -m.5
|verb has no monadic valence
| (-m.5)3
The latter might as well behave as monad - does in its normal usage in
the absence of
a modulus.
I suppose monadic * could work as well, presumably always producing 1 .
There is perhaps a slight advantage of having monad defined for all of +
- * % and (%.) ,
in that users could work up their own modular conjunctions & adverbs
defined for any u .
Any thoughts on reciprocals/negstive powers and perhaps on extending the
support of
monad (u m. n) ?
Thanks,
Mike
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm