Changeset 53e03a6 in git


Ignore:
Timestamp:
Dec 11, 2006, 7:51:12 PM (17 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
688052c6836073bcb5c3e359253c9c06b18d72c7
Parents:
0c0b9f11e094394b7ba5d064cb18da114c89975d
Message:
*hannes: docu, format


git-svn-id: file:///usr/local/Singular/svn/trunk@9579 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/AtkinsTest.lib

    r0c0b9f1 r53e03a6  
    11///////////////////////////////////////////////////////////////////////////////
    2 version="$Id: AtkinsTest.lib,v 1.2 2006-12-11 18:08:15 Singular Exp $";
     2version="$Id: AtkinsTest.lib,v 1.3 2006-12-11 18:51:12 Singular Exp $";
    33category="Teaching";
    44info="
     
    4040
    4141proc new(list L, number D)
    42 // "USAGE: new(L,D);
    43 // RETURN:  1, if D does not already exist in L,
    44 //         -1, if D does already exist in L
    45 // EXAMPLE:example new; shows an example
    46 // "
    47     {
     42"USAGE: new(L,D);
     43RETURN:  1, if D does not already exist in L,
     44        -1, if D does already exist in L
     45EXAMPLE:example new; shows an example
     46"
     47{
    4848      number a=1;                // a=1 bedeutet: D noch nicht in L vorhanden
    4949      int i;
     
    5858
    5959      return(a);
    60     }
    61 
    62 example
    63  { "EXAMPLE:"; echo = 2;
     60}
     61example
     62{ "EXAMPLE:"; echo = 2;
    6463    ring r = 0,x,dp;
    6564    list L=8976,-223456,556,-778,3,-55603,45,766677;
    6665    number D=-55603;
    6766    new(L,D);
    68  }
     67}
    6968
    7069
    7170
    7271proc bubblesort(list L)
    73 // "USAGE: bubblesort(L);
    74 // RETURN: list L, sort in decreasing order
    75 // EXAMPLE:example bubblesort; shows an example
    76 // "
    77     {
     72"USAGE: bubblesort(L);
     73RETURN: list L, sort in decreasing order
     74EXAMPLE:example bubblesort; shows an example
     75"
     76{
    7877      number b;
    7978      int n,i,j;
     
    9594
    9695      return(L);
    97     }
    98 
    99 example
    100  { "EXAMPLE:"; echo = 2;
     96}
     97example
     98{ "EXAMPLE:"; echo = 2;
    10199    ring r = 0,x,dp;
    102100    list L=-567,-233,446,12,-34,8907;
    103101    bubblesort(L);
    104  }
     102}
    105103
    106104
    107105
    108106proc disc(number N, int k)
    109 // "USAGE: disc(N,k);
    110 // RETURN: list L of negative discriminants D, sort in decreasing order
    111 // ASSUME: D<0, D kongruent 0 or 1 modulo 4 and |D|<4N
    112 // NOTE:   D=b^2-4*a, where 0<=b<=k and intPart((b^2)/4)+1<=a<=k for each b
    113 // EXAMPLE:example disc; shows an example
    114 // "
    115     {
     107"USAGE: disc(N,k);
     108RETURN: list L of negative discriminants D, sort in decreasing order
     109ASSUME: D<0, D kongruent 0 or 1 modulo 4 and |D|<4N
     110NOTE:   D=b^2-4*a, where 0<=b<=k and intPart((b^2)/4)+1<=a<=k for each b
     111EXAMPLE:example disc; shows an example
     112"
     113{
    116114      list L=-3,-4,-7;
    117115      number D;
     
    133131      L=bubblesort(L);
    134132      return(L);
    135     }
    136 
    137 example
    138  { "EXAMPLE:"; echo = 2;
     133}
     134example
     135{ "EXAMPLE:"; echo = 2;
    139136    ring R = 0,x,dp;
    140137    disc(2003,50);
    141  }
     138}
    142139
    143140
    144141
    145142proc Cornacchia(number d, number p)
    146 // "USAGE: Cornacchia(d,p);
    147 // RETURN: x,y such that x^2+d*y^2=p with p prime,
    148 //         -1, if the Diophantine equation has no solution,
    149 //          0, if the parameters are wrong selected
    150 // ASSUME: 0<d<p
    151 // EXAMPLE:example Cornacchia; shows an example
    152 // "
    153     {
     143"USAGE: Cornacchia(d,p);
     144RETURN: x,y such that x^2+d*y^2=p with p prime,
     145        -1, if the Diophantine equation has no solution,
     146         0, if the parameters are wrong selected
     147ASSUME: 0<d<p
     148EXAMPLE:example Cornacchia; shows an example
     149"
     150{
    154151
    155152      if((d<0)||(p<d))                                                   // (0)[Test if assumptions well-defined]
     
    222219              }
    223220         }
    224     }
    225 
    226 example
    227  { "EXAMPLE:"; echo = 2;
     221}
     222example
     223{ "EXAMPLE:"; echo = 2;
    228224    ring R = 0,x,dp;
    229225    Cornacchia(55,9551);
    230  }
     226}
    231227
    232228
    233229
    234230proc CornacchiaModified(number D, number p)
    235 // "USAGE: CornacchiaModified(D,p);
    236 // RETURN: x,y such that x^2+|D|*y^2=p with p prime,
    237 //         -1, if the Diophantine equation has no solution,
    238 //          0, if the parameters are wrong selected
    239 // ASSUME: D<0, D kongruent 0 or 1 modulo 4 and |D|<4p
    240 // EXAMPLE:example CornacchiaModified; shows an example
    241 // "
    242     {
     231"USAGE: CornacchiaModified(D,p);
     232RETURN: x,y such that x^2+|D|*y^2=p with p prime,
     233        -1, if the Diophantine equation has no solution,
     234         0, if the parameters are wrong selected
     235ASSUME: D<0, D kongruent 0 or 1 modulo 4 and |D|<4p
     236EXAMPLE:example CornacchiaModified; shows an example
     237"
     238{
    243239
    244240      if((D>=0)||((D mod 4)==2)||((D mod 4)==3)||(absValue(D)>=4*p))            // (0)[Test if assumptions well-defined]
     
    332328              }
    333329         }
    334     }
    335 
    336 example
    337  { "EXAMPLE:"; echo = 2;
     330}
     331example
     332{ "EXAMPLE:"; echo = 2;
    338333    ring R = 0,x,dp;
    339334    CornacchiaModified(-107,1319);
    340  }
     335}
    341336
    342337
    343338
    344339proc pFactor1(number n,int B, list P)
    345 // "USAGE: pFactor1(n,B,P); n to be factorized, B a bound , P a list of primes
    346 // RETURN: a list of factors of n or the message: no factor found
    347 // NOTE:   Pollard's p-factorization
    348 //         creates the product k of powers of primes (bounded by B)  from
    349 //         the list P with the idea that for a prime divisor p of n p-1|k
    350 //         then p devides gcd(a^k-1,n) for some random a
    351 // EXAMPLE:example pFactor1; shows an example
    352 // "
    353     {
     340"USAGE: pFactor1(n,B,P); n to be factorized, B a bound , P a list of primes
     341RETURN: a list of factors of n or the message: no factor found
     342NOTE:   Pollard's p-factorization
     343        creates the product k of powers of primes (bounded by B)  from
     344        the list P with the idea that for a prime divisor p of n p-1|k
     345        then p devides gcd(a^k-1,n) for some random a
     346EXAMPLE:example pFactor1; shows an example
     347"
     348{
    354349      int i;
    355350      number k=1;
     
    370365      if((d>1)&&(d<n)){return(d);}
    371366      return(n);
    372     }
    373 
     367}
    374368example
    375369{ "EXAMPLE:"; echo = 2;
     
    385379
    386380proc maximum(list L)
    387 // "USAGE: maximum(list L);
    388 // RETURN: the maximal number contained in list L
    389 // EXAMPLE:example maximum; shows an example
    390 // "
    391     {
     381"USAGE: maximum(list L);
     382RETURN: the maximal number contained in list L
     383EXAMPLE:example maximum; shows an example
     384"
     385{
    392386      number max=L[1];
    393387
     
    402396
    403397      return(max);
    404     }
    405 
    406 example
    407  { "EXAMPLE:"; echo = 2;
     398}
     399example
     400{ "EXAMPLE:"; echo = 2;
    408401    ring r = 0,x,dp;
    409402    list L=465,867,1233,4567,776544,233445,2334,556;
    410403    maximum(L);
    411  }
     404}
    412405
    413406
    414407
    415408proc cmod(number x, number y)
    416 // "USAGE: cmod(x,y);
    417 // RETURN: x mod y
    418 // ASSUME: x,y out of Z and x,y<=2147483647
    419 // NOTE:   this algorithm is a helping procedure to be able to calculate
    420            x mod y with x,y out of Z while working in the complex field
    421 // EXAMPLE:example cmod; shows an example
    422 // "
    423     {
     409"USAGE: cmod(x,y);
     410RETURN: x mod y
     411ASSUME: x,y out of Z and x,y<=2147483647
     412NOTE:   this algorithm is a helping procedure to be able to calculate
     413        x mod y with x,y out of Z while working in the complex field
     414EXAMPLE:example cmod; shows an example
     415"
     416{
    424417      int rest=int(x-y*int(x/y));
    425418      if(rest<0)
     
    429422
    430423      return(rest);
    431     }
    432 
    433 example
    434  { "EXAMPLE:"; echo = 2;
     424}
     425example
     426{ "EXAMPLE:"; echo = 2;
    435427    ring r = (complex,30,i),x,dp;
    436428    number x=-1004456;
    437429    number y=1233;
    438430    cmod(x,y);
    439  }
     431}
    440432
    441433
    442434
    443435proc sqr(number w, int k)
    444 // "USAGE: sqr(w,k);
    445 // RETURN: the square root of w
    446 // ASSUME: w>=0
    447 // NOTE:   k describes the number of decimals being calculated in the real numbers,
    448 //         k, intPart(k/5) are inputs for the procedure "nt_solve"
    449 // EXAMPLE:example sqr; shows an example
    450 // "
    451     {
    452       poly f=var(1)^2-w;
    453       def S=basering;
    454       ring R=(real,k),var(1),dp;
    455       poly f=imap(S,f);
    456       ideal I=nt_solve(f,1.1,list(k,int(intPart(k/5))));
    457       number c=leadcoef(I[1]);
    458       setring S;
    459       number c=imap(R,c);
    460       return(c);
    461     }
    462 
    463 example
    464  { "EXAMPLE:"; echo = 2;
     436"USAGE: sqr(w,k);
     437RETURN: the square root of w
     438ASSUME: w>=0
     439NOTE:   k describes the number of decimals being calculated in the real numbers,
     440        k, intPart(k/5) are inputs for the procedure "nt_solve"
     441EXAMPLE:example sqr; shows an example
     442"
     443{
     444  poly f=var(1)^2-w;
     445  def S=basering;
     446  ring R=(real,k),var(1),dp;
     447  poly f=imap(S,f);
     448  ideal I=nt_solve(f,1.1,list(k,int(intPart(k/5))));
     449  number c=leadcoef(I[1]);
     450  setring S;
     451  number c=imap(R,c);
     452  return(c);
     453}
     454example
     455{ "EXAMPLE:"; echo = 2;
    465456    ring R = (real,60),x,dp;
    466457    number ww=288469650108669535726081;
    467458    sqr(ww,60);
    468  }
     459}
    469460
    470461
    471462
    472463proc e(number z, int k)
    473 // "USAGE: e(z,k);
    474 // RETURN: e^z to the order k
    475 // NOTE:   k describes the number of summands being calculated in the exponential power series
    476 // EXAMPLE:example e; shows an example
    477 // "
    478     {
    479       number q=1;
    480       number e=1;
    481 
    482       int n;
    483       for(n=1;n<=k;n++)
    484          {
    485            q=q*z/n;
    486            e=e+q;
    487          }
    488 
    489       return(e);
    490     }
    491 
    492 example
    493  { "EXAMPLE:"; echo = 2;
     464"USAGE: e(z,k);
     465RETURN: e^z to the order k
     466NOTE:   k describes the number of summands being calculated in the exponential power series
     467EXAMPLE:example e; shows an example
     468"
     469{
     470  number q=1;
     471  number e=1;
     472
     473  int n;
     474  for(n=1;n<=k;n++)
     475  {
     476    q=q*z/n;
     477    e=e+q;
     478  }
     479  return(e);
     480}
     481
     482example
     483{ "EXAMPLE:"; echo = 2;
    494484    ring r = (real,30),x,dp;
    495485    number z=40.35;
    496486    e(z,1000);
    497  }
     487}
    498488
    499489
    500490
    501491proc jot(number t, int k)
    502 // "USAGE: jot(t,k);
    503 // RETURN: the j-invariant of t
    504 // ASSUME: t is a complex number with positive imaginary part
    505 // NOTE:   k describes the number of summands being calculated in the power series,
    506 //         10*k is input for the procedure "e"
    507 // EXAMPLE:example jot; shows an example
    508 // "
    509     {
     492"USAGE: jot(t,k);
     493RETURN: the j-invariant of t
     494ASSUME: t is a complex number with positive imaginary part
     495NOTE:   k describes the number of summands being calculated in the power series,
     496        10*k is input for the procedure "e"
     497EXAMPLE:example jot; shows an example
     498"
     499{
    510500      number q1,q2,qr1,qi1,tr,ti,m1,m2,f,j;
    511501
     
    538528      j=(256*f+1)^3/f;
    539529      return(j);
    540     }
    541 
    542 example
    543  { "EXAMPLE:"; echo = 2;
     530}
     531
     532example
     533{ "EXAMPLE:"; echo = 2;
    544534    ring r = (complex,30,i),x,dp;
    545535    number t=(-7+i*sqr(7,250))/2;
    546536    jot(t,50);
    547  }
     537}
    548538
    549539
    550540
    551541proc round(number r)
    552 // "USAGE: round(r);
    553 // RETURN: the nearest number to r out of Z
    554 // ASSUME: r should be a rational or a real number
    555 // EXAMPLE:example round; shows an example
    556 // "
     542"USAGE: round(r);
     543RETURN: the nearest number to r out of Z
     544ASSUME: r should be a rational or a real number
     545EXAMPLE:example round; shows an example
     546"
     547{
     548  number a=absValue(r);
     549  number v=r/a;
     550
     551  number d=10;
     552  int e;
     553  while(1)
     554  {
     555    e=e+1;
     556    if(a-d^e<0)
    557557    {
    558       number a=absValue(r);
    559       number v=r/a;
    560 
    561       number d=10;
    562       int e;
    563       while(1)
    564          {
    565            e=e+1;
    566            if(a-d^e<0)
    567               {
    568                 e=e-1;
    569                 break;
    570               }
    571          }
    572 
    573       number b=a;
    574       int k;
    575       for(k=0;k<=e;k++)
    576          {
    577            while(1)
    578               {
    579                 b=b-d^(e-k);
    580                 if(b<0)
    581                    {
    582                      b=b+d^(e-k);
    583                      break;
    584                    }
    585               }
    586          }
    587 
    588       if(b<1/2)
    589          {
    590            return(v*(a-b));
    591          }
    592 
    593       else
    594          {
    595            return(v*(a+1-b));
    596          }
     558      e=e-1;
     559      break;
    597560    }
    598 
    599 example
    600  { "EXAMPLE:"; echo = 2;
     561  }
     562
     563  number b=a;
     564  int k;
     565  for(k=0;k<=e;k++)
     566  {
     567    while(1)
     568    {
     569      b=b-d^(e-k);
     570      if(b<0)
     571      {
     572        b=b+d^(e-k);
     573        break;
     574      }
     575    }
     576  }
     577
     578  if(b<1/2)
     579  {
     580    return(v*(a-b));
     581  }
     582  else
     583  {
     584    return(v*(a+1-b));
     585  }
     586}
     587example
     588{ "EXAMPLE:"; echo = 2;
    601589    ring R = (real,50),x,dp;
    602590    number r=7357683445788723456321.6788643224;
    603591    round(r);
    604  }
     592}
    605593
    606594
    607595
    608596proc HilbertClassPolynomial(number D, int k)
    609 // "USAGE: HilbertClassPolynomial(D,k);
    610 // RETURN: the monic polynomial of degree h(D) in Z[X] of which jot((D+sqr(D))/2) is a root
    611 // ASSUME: D is a negative discriminant
    612 // NOTE:   k is input for the procedure "jot",
    613 //         5*k is input for the procedure "sqr",
    614 //         10*k describes the number of decimals being calculated in the complex numbers
    615 // EXAMPLE:example HilbertClassPolynomial; shows an example
    616 // "
    617     {
     597"USAGE: HilbertClassPolynomial(D,k);
     598RETURN: the monic polynomial of degree h(D) in Z[X] of which jot((D+sqr(D))/2) is a root
     599ASSUME: D is a negative discriminant
     600NOTE:   k is input for the procedure "jot",
     601        5*k is input for the procedure "sqr",
     602        10*k describes the number of decimals being calculated in the complex numbers
     603EXAMPLE:example HilbertClassPolynomial; shows an example
     604"
     605{
    618606      if(D>=0)                                                         // (0)[Test if assumptions well-defined]
    619607         {
     
    748736           return(Q);
    749737         }
    750     }
    751 
    752 example
    753  { "EXAMPLE:"; echo = 2;
     738}
     739example
     740{ "EXAMPLE:"; echo = 2;
    754741    ring r = 0,x,dp;
    755742    number D=-23;
    756743    HilbertClassPolynomial(D,50);
    757  }
     744}
    758745
    759746
    760747
    761748proc RootsModp(int p, poly P)
    762 // "USAGE: RootsModp(p,P);
    763 // RETURN: list of roots of the polynomial P modulo p with p prime
    764 // ASSUME: p>=3
    765 // NOTE:   this algorithm will be called recursively, and it is understood
    766 //         that all the operations are done in Z/pZ (excepting sqareRoot(d,p))
    767 // EXAMPLE:example RootsModp; shows an example
    768 // "
    769     {
     749"USAGE: RootsModp(p,P);
     750RETURN: list of roots of the polynomial P modulo p with p prime
     751ASSUME: p>=3
     752NOTE:   this algorithm will be called recursively, and it is understood
     753        that all the operations are done in Z/pZ (excepting sqareRoot(d,p))
     754EXAMPLE:example RootsModp; shows an example
     755"
     756{
    770757      if(p<3)                                                              // (0)[Test if assumptions well-defined]
    771758         {
     
    837824           return(l);
    838825         }
    839     }
    840 
    841 example
    842  { "EXAMPLE:"; echo = 2;
     826}
     827example
     828{ "EXAMPLE:"; echo = 2;
    843829    ring r = 0,x,dp;
    844830    poly f=x4+2x3-5x2+x;
     
    846832    poly g=x5+112x4+655x3+551x2+1129x+831;
    847833    RootsModp(1223,g);
    848  }
     834}
    849835
    850836
    851837
    852838proc w(number D)
    853 // "USAGE: w(D);
    854 // RETURN: the number of roots of unity in the quadratic order of discriminant D
    855 // ASSUME: D<0 a discriminant kongruent to 0 or 1 modulo 4
    856 // EXAMPLE:example w; shows an example
    857 // "
    858     {
    859       if((D>=0)||((D mod 4)==2)||((D mod 4)==3))
    860          {
    861            ERROR("Parameter wrong selected!");
    862          }
    863 
    864       else
    865          {
    866            if(D<-4) {return(2);}
    867            if(D==-4){return(4);}
    868            if(D==-3){return(6);}
    869          }
    870     }
    871 
    872 example
    873  { "EXAMPLE:"; echo = 2;
     839"USAGE: w(D);
     840RETURN: the number of roots of unity in the quadratic order of discriminant D
     841ASSUME: D<0 a discriminant kongruent to 0 or 1 modulo 4
     842EXAMPLE:example w; shows an example
     843"
     844{
     845  if((D>=0)||((D mod 4)==2)||((D mod 4)==3))
     846  {
     847    ERROR("Parameter wrong selected!");
     848  }
     849  else
     850  {
     851    if(D<-4) {return(2);}
     852    if(D==-4){return(4);}
     853    if(D==-3){return(6);}
     854  }
     855}
     856example
     857{ "EXAMPLE:"; echo = 2;
    874858    ring r = 0,x,dp;
    875859    number D=-3;
    876860    w(D);
    877  }
     861}
    878862
    879863
    880864
    881865proc Atkin(number N, int K, int B)
    882 // "USAGE: Atkin(N,K,B);
    883 // RETURN:  1, if N is prime,
    884 //         -1, if N is not prime,
    885 //          0, if the algorithm is not applicable, since there are too little discriminants
    886 // ASSUME: N is coprime to 6 and different from 1
    887 // NOTE:   - K/2 is input for the procedure "disc",
    888 //           K is input for the procedure "HilbertClassPolynomial",
    889 //           B describes the number of recursions being calculated
    890 //         - The basis of the the algorithm is the following theorem:
    891 //           Let N be an integer coprime to 6 and different from 1 and E be an ellipic curve modulo N.
    892 //           Assume that we know an integer m and a point P of E(Z/NZ) satisfying the following conditions.
    893 //            (1) There exists a prime divisor q of m such that q>(4-th root(N)+1)^2.
    894 //            (2) m*P=O(E)=(0:1:0).
    895 //            (3) (m/q)*P=(x:y:t) with t element of (Z/NZ)*.
    896 //           Then N is prime.
    897 // EXAMPLE:example Atkin; shows an example
    898 // "
    899     {
     866"USAGE: Atkin(N,K,B);
     867RETURN:  1, if N is prime,
     868        -1, if N is not prime,
     869         0, if the algorithm is not applicable, since there are too little discriminants
     870ASSUME: N is coprime to 6 and different from 1
     871NOTE:   - K/2 is input for the procedure "disc",
     872          K is input for the procedure "HilbertClassPolynomial",
     873          B describes the number of recursions being calculated
     874        - The basis of the the algorithm is the following theorem:
     875          Let N be an integer coprime to 6 and different from 1 and E be an ellipic curve modulo N.
     876          Assume that we know an integer m and a point P of E(Z/NZ) satisfying the following conditions.
     877           (1) There exists a prime divisor q of m such that q>(4-th root(N)+1)^2.
     878           (2) m*P=O(E)=(0:1:0).
     879           (3) (m/q)*P=(x:y:t) with t element of (Z/NZ)*.
     880          Then N is prime.
     881EXAMPLE:example Atkin; shows an example
     882"
     883{
    900884      if(N==1)           {return(-1);}
    901885      if((N==2)||(N==3)) {return(1);}
     
    13141298              }
    13151299         }
    1316     }
    1317 
    1318 example
    1319  { "EXAMPLE:"; echo = 2;
     1300}
     1301example
     1302{ "EXAMPLE:"; echo = 2;
    13201303    ring R = 0,x,dp;
    13211304    printlevel=1;
     
    13241307    Atkin(100019,100,5);
    13251308    Atkin(10000079,100,2);
    1326  }
     1309}
Note: See TracChangeset for help on using the changeset viewer.