I think it is because you are finding quadratic residues (
https://en.wikipedia.org/wiki/Quadratic_residue ), not simple residues.
In general, you are looking for the solution to
x^2 = q mod n,
i.e. looking for some x such that
n | (*: x)
is equal to q, for a given q. A solution does not necessarily exist for every q
in {0, ..., n-1}.
--------------------------------------------
On Tue, 1/5/16, Devon McCormick <[email protected]> wrote:
Subject: [Jprogramming] Prime-based selection oddity
To: "J-programming forum" <[email protected]>
Date: Tuesday, January 5, 2016, 11:13 AM
Recently I was looking at how I might
generate something that look like an
encryption key and noticed this oddity:
#val=. '0123456789ABCDEF'
16
val{~(#val)|2^~p:i.128
49919919191919199991119119199119199199199911919199111911919199911991991119919911991119119191199191999991919111191911919991999991
frtab val{~(#val)|2^~p:i.128
+--+-+
|1 |4|
+--+-+
|68|9|
+--+-+
|59|1|
+--+-+
Where "frtab" is a frequency table generator:
frtab=: 3 : 0
cts=. #&>y</.y
NB. # unique items...
if. -.isNum y do.
NB. Special case enclosed, text mat, text
vec,
if. (L.=0:) y do. (<"0
cts),.<"0 ~.y else.
if. 2=#$y do.
(<"0 cts),.<"1 ~.y else. (<"0 cts),.<"0 ~.y
end.
end.
else. cts,.~.y end. NB.
and simple numeric vec.
NB.EG (1 2 3 2 1,. 11 22 33 222 99) -: frtab 11 22 22 33 33
33 222 222 99
)
Any obvious reason why the 16| of squares of primes should
return only "1"
and "9" for this sample?
--
Devon McCormick, CFA
Quantitative Consultant
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm