File: mhcount.cc

package info (click to toggle)
eclib 20180815-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,216 kB
  • sloc: cpp: 47,046; makefile: 248; sh: 108
file content (68 lines) | stat: -rw-r--r-- 2,116 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// FILE MHCOUNT.CC: Program to list/count Manin-Heilbronn matrices
//////////////////////////////////////////////////////////////////////////
//
// Copyright 1990-2012 John Cremona
// 
// This file is part of the eclib package.
// 
// eclib is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// eclib is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License
// along with eclib; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
// 
//////////////////////////////////////////////////////////////////////////
//
#include <eclib/arith.h>

void outmat(int n, long a, long b, long c, long d)
{
  cout<<"mats["<<n<<"]=mat22("<<a<<","<<b<<","<<c<<","<<d<<");\n";
}

int main(void)
{
  int seemats=0; int np=10;
  cout << "See the matrices? "; cin>>seemats;
  cout << "How many primes? "; cin >> np;
  for(primevar pr(np); pr.ok(); pr++)
    {
      long p = (long)pr; if(p==2) continue;
      long p2 = (p-1)/2;
      int nmats=0;
      cout << "p = " << p << ";\t"; 
      if(seemats) cout << "\n";
      if(seemats) outmat(nmats,1,0,0,p);
      nmats++;
      if(seemats) outmat(nmats,p,0,0,1);
      nmats++;
      for(int s=1; s>-2; s-=2)
      for(long r=1; r<=p2; r++)
	{
//	  cout<<"r = " << s*r << ":" << endl;
	  long x1=p, x2=-s*r, y1=0, y2=1, a=-p, b=s*r, c, q, x3, y3;
	  if(seemats) outmat(nmats,x1,x2,y1,y2);
	  nmats++;
	  while(b!=0)
	    {
	      c=mod(a,b); q=(a-c)/b;
	      x3=q*x2-x1; y3=q*y2-y1;
	      a=-b; b=c; x1=x2; x2=x3; y1=y2; y2=y3;
	      if(seemats) outmat(nmats,x1,x2,y1,y2);
	      nmats++;
	    }
	}
      if(seemats)cout<<"\n";
      cout << "nmats = " << nmats << ";" << endl;
    }
}