Vocabulary/mdot

From J Wiki
Jump to navigation Jump to search

>> <<   Back to: Vocabulary

[x] u m. n y Modular arithmetic: [x] u y(mod n) Conjunction

Operand-dependent rank -- the rank of the resulting verb depends on u

Warning.png This primitive is new in J9.05


   2 (+ m. 5) 4
1

[x] u m. n y performs the operation given in standard mathematical notation as [x] u y(mod n).

  • u must be one of + - % * ^ %. (-/ . *)
  • The rank of the derived verb is 0 0 0 except for %. which has rank 2 _ 2
  • The monad is supported only for % %. for which it returns the modular inverse
  • x, y, and n must be tolerantly integral or extended
  • Fast computation using integers is performed when n is small enough; otherwise extended integers are used
  • The result is integer when the computation was done using integers and n is not extended or rational; otherwise extended integer
  • 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

Performance Note

Executing x (u m. n) y requires two execution steps:

  • u m. n is executed to produce a derived verb
  • the derived verb is executed on the x and y arguments

If n is a small integer (on 64-bit systems, small is any value whose absolute value is less than 3037000499), producing the derived verb takes much more time than executing it on atomic arguments. If you are going to execute (u m. n) repeatedly, you would be well advised to assign it to a name, preferably a private name:

   plusmod =. + m. n

The derived verb will be assigned to the name plusmod and will not have to be recreated for each use.