paley(g,n) --- create a Paley graph with n vertices
SYNOPSIS
function paley(g,n)
DESCRIPTION
paley(g,n) --- create a Paley graph with n vertices
In this graph, there is an edge from i to j iff i-j is a square in Z_n.
Hence, if -1 is not a square in Z_n, an error is generated.
0001 function paley(g,n)
0002 % paley(g,n) --- create a Paley graph with n vertices
0003 % In this graph, there is an edge from i to j iff i-j is a square in Z_n.
0004 % Hence, if -1 is not a square in Z_n, an error is generated.
0005
0006 if (n <= 1)
0007 error('n must be at least 2');
0008 end
0009
0010 squares = unique(mod([1:n-1].^2,n));
0011
0012 % check if -1 is a square
0013 if ~ismember(n-1,squares)
0014 error('-1 is not a square in Z_n');
0015 end
0016 resize(g,0);
0017 resize(g,n);
0018 rmxy(g);
0019 for v = 1:n
0020 nlist = mod(v+squares,n);
0021 idx = find(nlist == 0);
0022 if length(idx)>0
0023 nlist(idx) = n;
0024 end
0025 for w = nlist
0026 add(g,v,w)
0027 end
0028 end