NB. math utilities
NB.
NB. clean         clean small numbers near to 0
NB. det           determinant of matrix
NB. mp            M mp N  = matrix product of M and N
NB. powermod      x (n powermod) y computes n|x^y
NB. randomint     random integer in range 0, <: 10^y.
NB. randomintd    random integer with y. digits
NB. timesmod      x (n timesmod) y computes n|x*y

det=: -/ .*
mp=: +/ .*
powermod=: 1 : 'x.&|@^'
randomint=: 3 : '10 #. ? y. $ 10x'
randomintd=: 3 : '10 #. (y.{.1) + ? 10x - y.{.1'
timesmod=: 1 : 'x.&|@*'

NB. =========================================================
NB. clean
NB. tolerance (default 1e_10) clean numbers
NB. sets values less than tolerance to 0
clean=: 3 : 0
1e_10 clean y.
:
if. 16 ~: 3!:0 y. do.
  y. * x. <: |y.
else.
  j./"1 y * x. <: | y=. +.y.
end.
)
