0

I recently wrote a program for quickly finding quadratic residues in Maple;

quadres := proc (n::posint)

global k, L, Sorting;

Sorting := proc (X)

global Y, i, j, z;

Y := X;

for i to nops(Y)-1 do

for j to nops(Y)-i do

if Y[j+1] <= Y[j] then z := Y[j]; Y[j] := Y[j+1]; Y[j+1] := z end

if end do end do;

eval(Y) end proc;

for k from 0 to n-1 do mod(k^2, n) end do;

L := [seq(mod(k^2, n), k = 1 .. (1/2)*n-1/2)];

Sorting(L);

print(n = Sorting(L))

end proc;

My question is this. I want to convert this to a point plot program so that I can plot larger numbers of data to look for patterns. The axes will be moduli (x-axis) vs. residues (y-axis). Thus, for moduli 2,3,4,and 5, the ordered pairs will be $$\{(3,1),(4,1),(5,1),(5,4),(6,1),(6,4), (7,1),(7,2),(7,4)\}$$. Any thoughts on how to write the program would be helpful. I'm a novice with Maple, but catch on quick.

  • Please give an example of how you expect to call this function, and how moduli 2,3,4,5 result in the order pair mentioned. It's unclear how you intend it to work. Then we might suggest fixes (including removal of all those global declarations, etc). Also, you may be able to supply a predicate to the builtin sort command, but very likely don't need your own sorting implementation (efficient or not), and certaily not one which gets its body redefined each time quadres is called. – acer Feb 08 '14 at 00:23
  • Here's the goal. A point plot program and a relation $R={(x,y)|x\in\mathbb{N}, y\text{ is a quadratic residue of }x}$. I figured that i could use the residue program to extract the residues and pair them with the appropriate modulus. Thus, since $1,2,4$ are all quadratic residues of 7, then the program will plot the points ${(7,1),(7,2),(7,4)}.$ I can get the residues quickly, now how do I get the residues and the moduli as ordered pairs and then plot.... – Eleven-Eleven Feb 08 '14 at 03:09
  • This isn't really a coding site.... – Gerry Myerson Feb 08 '14 at 04:31
  • I'll keep that in mind for future posts @Gerry Myerson. Is there a forum strictly for Maple? – Eleven-Eleven Feb 08 '14 at 16:29
  • I don't know. There is a forum for Mathematica, and there is (at least) one for coding, generally. – Gerry Myerson Feb 08 '14 at 22:06
  • Questions which are more about programming in Maple than about mathematics in Maple are better posted to either www.stackoverflow.com (with the maple tag) or www.mapleprimes.com – acer Feb 10 '14 at 00:59
  • Thanks @acer. i'll remember next time. – Eleven-Eleven Feb 10 '14 at 02:42

1 Answers1

1
restart:

quadres:=(n::posint)->{seq([n,k^2 mod n],k=1..(n-1)/2)}:

S:=`union`(seq(quadres(i),i=[3,4,5,6,7]));

        {[3, 1], [4, 1], [5, 1], [5, 4], [6, 1], [6, 4], [7, 1], [7, 2], [7, 4]}

plots:-pointplot(S,view=[1..7,0..6]);

enter image description here

acer
  • 5,293