This file is indexed.

/usr/share/singular/LIB/aksaka.lib is in singular-data 1:4.1.0-p3+ds-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
////////////////////////////////////////////////////////////////////////////////
version="version aksaka.lib 4.0.0.1 Jun_2014 "; // $Id: bc74504c42ff955c330251e3f092f84d4c6c8a0d $
category="Teaching";
info="
LIBRARY: aksaka.lib     Procedures for primality testing after Agrawal, Saxena, Kayal
AUTHORS: Christoph Mang

OVERVIEW:
 Algorithms for primality testing in polynomial time
 based on the ideas of Agrawal, Saxena and  Kayal.

PROCEDURES:

fastExpt(a,m,n)         a^m for numbers a,m; if a^k>n n+1 is returned
log2(n)                    logarithm to basis 2 of n
PerfectPowerTest(n)        checks if there are a,b>1, so that a^b=n
wurzel(r)                  square root of number r
euler(r)                   phi-function of Euler
coeffmod(f,n)              polynomial f modulo number n (coefficients mod n)
powerpolyX(q,n,a,r)        (polynomial a)^q modulo (poly r,number n)
ask(n)                     ASK-Algorithm; deterministic Primality test
";

LIB "crypto.lib";
LIB "ntsolve.lib";

///////////////////////////////////////////////////////////////
//                                                           //
//   FAST (MODULAR) EXPONENTIATION                           //
//                                                           //
///////////////////////////////////////////////////////////////
proc fastExpt(bigint a,bigint m,bigint n)
"USAGE: fastExpt(a,m,n); a, m, n = number;
RETURN: the m-th power of a; if a^m>n the procedure returns n+1
NOTE:   uses fast exponentiation
EXAMPLE:example fastExpt; shows an example
"
{
  bigint b,c,d;
  c=m;
  b=a;
  d=1;
  while(c>=1)
  {
    if(b>n)
    {
      return(n+1);
    }
    if((c mod 2)==1)
    {
      d=d*b;
      if(d>n)
      {
        return(n+1);
      }
    }
    b=b^2;
    c=c div 2;
  }
  return(d)
}
example
{ "EXAMPLE:"; echo = 2;
   fastExpt(2,10,1022);
}
////////////////////////////////////////////////////////////////////////////
proc coeffmod(poly f,bigint n)
"USAGE: coeffmod(f,n);
ASSUME: poly f depends on at most var(1) of the basering
RETURN: poly f modulo number n
NOTE:   at first the coefficients of the monomials of the polynomial f are
        determined, then their remainder modulo n is calculated,
        after that the polynomial 'is put together' again
EXAMPLE:example coeffmod; shows an example
"
{
  matrix M=coeffs(f,var(1));         //Bestimmung der Polynomkoeffizienten
  int i=1;
  poly g;
  int o=nrows(M);

  while(i<=o)
  {
    g=g+(bigint(leadcoef(M[i,1])) mod n)*var(1)^(i-1) ;
                   // umwandeln der Koeffizienten in bigint,
                   // Berechnung der Reste dieser bigint modulo n,
                   // Polynom mit neuen Koeffizienten wieder zusammensetzen
    i++;
  }
  return(g);
}
example
{ "EXAMPLE:"; echo = 2;
   ring R = 0,x,dp;
   poly f=2457*x4+52345*x3-98*x2+5;
   bigint n=3;
   coeffmod(f,n);
}
//////////////////////////////////////////////////////////////////////////
proc powerpolyX(bigint q,bigint n,poly a,poly r)
"USAGE: powerpolyX(q,n,a,r);
RETURN: the q-th power of poly a modulo poly r and number n
EXAMPLE:example powerpolyX; shows an example
"
{
  ideal I=r;

  if(q==1){return(coeffmod(reduce(a,I),n));}
  if((q mod 5)==0){return(coeffmod(reduce(powerpolyX(q div 5,n,a,r)^5,I),n));}
  if((q mod 4)==0){return(coeffmod(reduce(powerpolyX(q div 4,n,a,r)^4,I),n));}
  if((q mod 3)==0){return(coeffmod(reduce(powerpolyX(q div 3,n,a,r)^3,I),n));}
  if((q mod 2)==0){return(coeffmod(reduce(powerpolyX(q div 2,n,a,r)^2,I),n));}

  return(coeffmod(reduce(a*powerpolyX(q-1,n,a,r),I),n));
}
example
{ "EXAMPLE:"; echo = 2;
   ring R=0,x,dp;
   poly a=3*x3-x2+5;
   poly r=x7-1;
   bigint q=123;
   bigint n=5;
   powerpolyX(q,n,a,r);
}
///////////////////////////////////////////////////////////////
//                                                           //
//   GENERAL PROCEDURES                                      //
//                                                           //
///////////////////////////////////////////////////////////////
proc log2(bigint xx)
"USAGE:  log2(x);
RETURN:  logarithm to basis 2 of x
NOTE:    calculates the natural logarithm of x with a power-series
         of the ln, then the basis is changed to 2
EXAMPLE: example log2; shows an example
"
{
  ring r=0,@x,dp;
  number b,c,d,t,l,x;
  x=number(xx);
  int k;
                                         // log2=logarithmus zur basis 2,
                                         // log=natuerlicher logarithmus
  b=100000000000000000000000000000000000000000000000000;
  c=141421356237309504880168872420969807856967187537695;    // c/b=sqrt(2)
  d=69314718055994530941723212145817656807550013436026;     // d/b=log(2)

  //bringen x zunaechst zwischen 1/sqrt(2) und sqrt(2), so dass Reihe schnell
  //konvergiert, berechnen dann Reihe bis 30. Summanden und letztendlich
  //log2(x)=log(x)/log(2)=(log(x/2^j)+j*log(2))/log(2)  fuer grosse x
  //log2(x)=log(x)/log(2)=(log(x*2^j)-j*log(2))/log(2)  fuer kleine x

  number j=0;
  if(x<(b/c))
  {
    while(x<(b/c))
    {
      x=x*2;
      j=j+1;
    }
    t=(x-1)/(x+1);
    k=0;
    l=0;
    while(k<30)       //fuer  x*2^j wird Reihe bis k-tem Summanden berechnet
    {
      l=l+2*(t^(2*k+1))/(2*k+1);      //l=log(x*2^j) nach k Summanden
      k=k+1;
    }
    return (intPart((l*b/d)-j));         //log2(x)=log(x*2^j)/log(2)-j wird ausgegeben
  }
  while(x>(c/b))
  {
    x=x/2;
    j=j+1;
  }
  t=(x-1)/(x+1);
  k=0;
  l=0;
  while(k<30)         //fuer  x/2^j wird Reihe bis k-tem Summanden berechnet
  {
    l=l+2*(t^(2*k+1))/(2*k+1);       //l=log(x/2^j) nach k Summanden
    k=k+1;
  }
  return(intPart(((l*b/d)+j)));     //hier wird log2(x)=log(x/2^j)/log(2)+j  ausgegeben
}
example
{ "EXAMPLE:"; echo = 2;
   log2(1024);
}
//////////////////////////////////////////////////////////////////////////
proc wurzel(number r)
"USAGE: wurzel(r);
ASSUME: characteristic of basering is 0, r>=0
RETURN: number, square root of r
EXAMPLE:example wurzel; shows an example
"
{
  poly f=var(1)^2-r;             //Wurzel wird als Nullstelle eines Polys
                                 //mit proc nt_solve genaehert
  def B=basering;
  ring R=(real,40),var(1),dp;
  poly g=imap(B,f);
  list l=nt_solve(g,1.1);
  number m=leadcoef(l[1][1]);
  setring B;
  return(imap(R,m));
}
example
{ "EXAMPLE:"; echo = 2;
   ring R = 0,x,dp;
   wurzel(7629412809180100);
}
//////////////////////////////////////////////////////////////////////////
proc euler(bigint r)
"USAGE: euler(r);
RETURN: bigint phi(r), where phi is Eulers phi-function
NOTE:   first r is factorized with proc PollardRho, then phi(r) is
        calculated with the help of phi(p) of every factor p;
EXAMPLE:example euler; shows an example
"
{
  list l=PollardRho(r,5000,1);           //bestimmen der Primfaktoren von r
  int k;
  bigint phi=r;
  for(k=1;k<=size(l);k++)
  {
    phi=phi-phi div l[k];       //berechnen phi(r) mit Hilfe der
  }                         //Primfaktoren und Eigenschaften der phi-Fktn
  return(phi);
}
example
{ "EXAMPLE:"; echo = 2;
   euler(99991);
}
///////////////////////////////////////////////////////////////
//                                                           //
//   PERFECT POWER TEST                                      //
//                                                           //
///////////////////////////////////////////////////////////////
proc PerfectPowerTest(bigint n)
"USAGE: PerfectPowerTest(n);
RETURN: 0 if there are numbers a,b>1 with a^b=n;
        1 if there are no numbers a,b>1 with a^b=n;
        if printlevel>=1 and there are a,b>1 with a^b=n,
        then a,b are printed
EXAMPLE:example PerfectPowerTest; shows an example
"
{
  bigint a,b,c,e,f,m,l,p;
  b=2;
  l=log2(n);
  e=0;
  f=1;

  while(b<=l)
  {
    a=1;
    c=n;

    while(c-a>=2)
    {
      m=(a+c) div 2;
      p=fastExpt(m,b,n);

      if(p==n)
      {
        if(printlevel>=1){"es existieren Zahlen a,b>1 mit a^b=n";
                      "a=";m;"b=";b;pause();}
        return(e);
      }

      if(p<n)
      {
        a=m;
      }
      else
      {
        c=m;
      }
    }
    b=b+1;
  }
  if(printlevel>=1){"es existieren keine Zahlen a,b>1  mit a^b=n";pause();}
  return(f);
}
example
{ "EXAMPLE:"; echo = 2;
   PerfectPowerTest(887503681);
}
///////////////////////////////////////////////////////////////
//                                                           //
//   ASK PRIMALITY TEST                                      //
//                                                           //
///////////////////////////////////////////////////////////////
proc ask(bigint n)
"USAGE: ask(n);
ASSUME: n>1
RETURN: 0 if n is composite;
        1 if n is prime;
        if printlevel>=1, you are informed what the procedure will do
        or has calculated
NOTE:   ASK-algorithm; uses proc powerpolyX for step 5
EXAMPLE:example ask; shows an example
"
{
  bigint c,p;
  c=0;
  p=1;

  if(n==2) { return(p); }
  if(printlevel>=1){"Beginn: Test ob a^b=n fuer a,b>1";pause();}
  if(0==PerfectPowerTest(n))             // Schritt1 des ASK-Alg.
  { return(c); }
  if(printlevel>=1)
  {
    "Beginn: Berechnung von r, so dass ord(n) in Z/rZ groesser log2(n)^2 ";
    pause();
  }
  bigint k,M,M2,b;
  int r;                          // Zeile 526-542: Schritt 2
  M=log2(n);                      // darin sind die Schritte
  M2=M^2;                         // 3 und 4 integriert
  r=2;

  if(gcd(n,r)!=1)   //falls ggt ungleich eins, Teiler von n gefunden,
                    // Schritt 3 des ASK-Alg.
  {
    if(printlevel>=1){"Zahl r gefunden mit r|n";"r=";r;pause();}
    return(c);
  }
  if(r==n-1)              // falls diese Bedingung erfuellt ist, ist
                         // ggT(a,n)=1 fuer 0<a<=r, schritt 4 des ASK-Alg.
  {
    if(printlevel>=1){"ggt(r,n)=1 fuer alle 1<r<n";pause();}
    return(p);
  }
  k=1;
  b=1;

  while(k<=M2)         //Beginn des Ordnungstests fuer aktuelles r
  {
    b=((b*n) mod r);
    if(b==1)   //tritt Bedingung ein so gilt fuer aktuelles r,k:
               //n^k=1 mod r
               //tritt Bedingung ein, wird wegen k<=M2=intPart(log2(n)^2)
               //r erhoeht,k=0 gesetzt und Ordnung erneut untersucht
               //tritt diese Bedingung beim groessten k=intPart(log2(n)^2)
               //nicht ein, so ist ord_r_(n)>log2(n)^2 und Schleife
               //wird nicht mehr ausgefuehrt
    {
      if(r==2147483647)
      {
        string e="error: r ueberschreitet integer Bereich und darf
                  nicht als Grad eines Polynoms verwendet werden";
        return(e);
      }
      r=r+1;
      if(gcd(n,r)!=1)   //falls ggt ungleich eins, Teiler von n gefunden,
                         //wird aufgrund von Schritt 3 des ASK-Alg. fuer
                         //jeden Kandidaten r getestet
      {
        if(printlevel>=1){"Zahl r gefunden mit r|n";"r=";r;pause();}
        return(c);
      }
      if(r==n-1)         //falls diese Bedingung erfuellt ist,
                         //ist n wegen Zeile 571 prim
                         //wird aufgrund von Schritt 4 des ASK-Alg. fuer
                         //jeden Kandidaten r getestet
      {
        if(printlevel>=1){"ggt(r,n)=1 fuer alle 1<r<n";pause();}
        return(p);
      }

      k=0;               //fuer neuen Kandidaten r, muss k fuer den
                         //Ordnungstest zurueckgesetzt werden
    }
    k=k+1;
  }
  if(printlevel>=1)
  {
    "Zahl r gefunden, so dass ord(n) in Z/rZ groesser log2(n)^2 ";
    "r=";r;pause();
  }
  ring @R=0,@x,dp;
  bigint l=1;                         // Zeile 603-628: Schritt 5
  poly f,g;                           // Zeile 618 ueberprueft Gleichungen fuer
                                      // das jeweilige a
  g=var(1)^r-1;
  bigint grenze=intPart(wurzel(euler(r))*M);

  if(printlevel>=1)
  {"Beginn: Ueberpruefung ob (x+a)^n kongruent x^n+a mod (x^r-1,n)
        fuer 0<a<=intPart(wurzel(phi(r))*log2(n))=";grenze;pause();
  }
  while(l<=grenze)          //
  {
    if(printlevel>=1){"a=";l;}
    f=var(1)+l;
    if(powerpolyX(bigint(n),bigint(n),f,g)!=(var(1)^(int((n mod r)))+l))
    {
      if(printlevel>=1)
      {"Fuer a=";l;"ist (x+a)^n nicht kongruent x^n+a mod (x^r-1,n)";
        pause();
      }
      return(c);
    }
    l=l+1;
  }
  if(printlevel>=1)
  {"(x+a)^n kongruent x^n+a mod (x^r-1,n) fuer 0<a<wurzel(phi(r))*log2(n)";
    pause();
  }
  return(p);       // Schritt 6
}
example
{ "EXAMPLE:"; echo = 2;
   //ask(100003);
   ask(32003);
}