/* -*- gp-script -*- */ \\% Create a conference matrix, of order N=1+q^n where q is an odd prime. \\% Need the prime p and an irreducible polynomial fp over GF(q). \\% The matrix C is such that is has zeros on the diagonal and \\% +-1 else, and C*C^T==(N-1)*id \\ Author: Joerg Arndt \\ License: GPL version 3 or later \\ online at http://www.jjj.de/pari/ \\ version: 2014-October-16 (18:31) num2pol(n,q)= \\ Return polynomial for number n. { my(p, mq, k); p = Pol(0,'x); k = 0; while ( 0!=n, mq = n % q; p += mq * ('x)^k; n -= mq; n \= q; k++; ); return( p ); } /* ----- */ pol2num(p,q)= \\ Return number for polynomial p. { p = lift(p); \\ remove mods, e.g. p=Mod(2, 3)*x^2 + Mod(1, 3) --> 2*x^2+1 return ( subst(p, 'x, q) ); \\ my(t, n); n=0; \\ \\ for (k=0, poldegree(p), \\ t = polcoeff(p, k); \\ t *= Mod(1,q); \\ t = lift(t); \\ t *= q^k; \\ n += t; \\ ); \\ \\ return( n ); } /* ----- */ quadcharvec(fp, q)= \\ Return a table of quadratic characters in GF(q^n) \\ fp is the field polynomial. { my(n, qn, sv, pl); n=poldegree(fp); qn=q^n-1; sv=vector(qn+1, j, -1); sv[1] = 0; for (k=1, qn, pl = num2pol(k,q); pl = Mod(Mod(1,q)*pl, fp); sq = pl * pl; \\ sq = component(sq, 2); sq = lift(sq); \\ remove mod i = pol2num( sq, q ); sv[i+1] = +1; ); return( sv ); } /* ----- */ getquadchar_n(n1, n2, q, fp, n)= \\ Return the quadratic character of (n2-n1) in GF(q^n) with field polynomial fp. \\ Powering method. { my(p1, p2, d, nd, sc); if ( n1==n2, return(0) ); p1 = num2pol(n1, q); p2 = num2pol(n2, q); d = Mod(1,q)* (p2-p1); d = Mod(d,fp)^((q^n-1)/2); \\ d = component(d, 2); d = lift(d); \\ remove mod if ( Mod(1,q)==d, sc=+1, sc=-1 ); return( sc ); } /* ----- */ getquadchar_v(n1, n2, q, fp, sv)= \\ Return the quadratic character of (n2-n1) in GF(q^n) with field polynomial fp. \\ Table lookup method, { my(p1, p2, d, nd, sc); if ( n1==n2, return(0) ); p1 = num2pol(n1, q); p2 = num2pol(n2, q); d = (p2-p1) % fp; nd = pol2num(d, q); sc = sv[nd+1]; return( sc ); } /* ----- */ printmat01(C)= { my(nr, nc, t); t = matsize(C); nr = t[1]; nc=t[2]; for (r=1, nr, for (c=1, nc, print1(" "); t = C[r,c]; if ( 0==t, print1("0") ); if ( +1==t, print1("+") ); if ( -1==t, print1("-") ); ); print(); ); } /* ----- */ matconference(q, fp, sv)= \\ Return a QxQ conference matrix where Q=q^n+1 and q an odd prime, \\ fp an irreducible polynomial modulo q. \\ sv table of quadratic characters in GF(q^n) \\ where n is the degree of fp. { my(y, Q, C, n); n = poldegree(fp); Q=q^n+1; if ( sv[2]==sv[Q-1], y=+1, y=-1 ); \\ symmetry \\ scp = getquadchar(0,1,q,n,fp); \\ scm = getquadchar(1,0,q,n,fp); \\ if ( scp==scm, y=+1, y=-1 ); \\ symmetry C = matrix(Q,Q); for (k=2, Q, C[1,k]=+1); \\ first row for (k=2, Q, C[k,1]=y); \\ first column \\ for (k=2, Q, C[k,1]=+1); \\ first column for (r=2, Q, for (c=2, Q, sc = getquadchar_n(r-2, c-2, q, fp, n); \\ sc = getquadchar_v(r-2, c-2, q, fp, sv); \\ same result C[r,c] = sc; ); ); return( C ); } /* ----- */ \\ ==== end of file ====