Ran into another case where the power of J is amazing. I was on the site
https://en.wikipedia.org/wiki/Residue_number_system and got to the part for
"Associated mixed radix system". Two math definitions. Not too bad but I
had noticed how many names were in the definitions. The second one first,
for M. Eight terms in the definition. Took a few minutes to read.
[image: M_0=1,M_i=\prod_{j=1}^i m_j] for [image: i>0] and [image: 0\leq
x_i<m_i.]
After looking at it a while I saw that it dropped the last prime, took a
running product of the primes, then stuck a one in front. In J it looks
like for 6 primes:
]m =: p:i.6
2 3 5 7 11 13
]x =: m|12345 NB. Some number to work with
1 0 0 4 3 8
]M =: 1,*/\}:m NB. An equivalent statement in J
1 2 6 30 210 2310
Looks pretty simple now. So much easier to read. Next it wanted to convert
r to the mixed radix.
[image:
X=\sum_{i=1}^Nx_iM_{i-1}=x_1+m_1(x_2+m_2(\cdots+m_{N-1}x_{N})\cdots),]
Not so bad. Only 5 names here if you ignore that after the second equals.
Again in J:
]X =: +/x*M
19231
Again, so much simpler. All this to convert the list of residues to a
scalar so it could compare for equal. By the way, is doesn't work for
determining less than or greater than. In J:
m#.&|.x NB. Reversed to get same answer, but not necessary
19231
That whole section is just J's decode.
y=:x NB. Make another name for comparison
But this is where J again is impressive. Match does it.
x-:y
1
That whole section, enough to really impress the reader, is nothing than
match in J.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm