Changeset 08a6ebb in git


Ignore:
Timestamp:
Sep 26, 2007, 4:31:12 PM (16 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
f4b18020f64669b26ca1cbe58482a4d2d8178a49
Parents:
8b388e1e07f2e848edfe629e622f372c9b16c0ea
Message:
*hannes: farey fixed


git-svn-id: file:///usr/local/Singular/svn/trunk@10312 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
factory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_chinese.cc

    r8b388e r08a6ebb  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_chinese.cc,v 1.11 2007-09-26 09:17:39 Singular Exp $ */
     2/* $Id: cf_chinese.cc,v 1.12 2007-09-26 14:31:12 Singular Exp $ */
    33
    44//{{{ docu
     
    162162{
    163163   //assume(P>0);
    164    if (N<0){N=N+P;}
     164   // assume !isOn(SW_RATIONAL): mod is a no-op otherwise
     165   if (N<0) N +=P;
    165166   CanonicalForm A,B,C,D,E;
    166167   E=P;
    167168   B=1;
    168    while (N!=0)
     169   while (!N.isZero())
    169170   {
    170171        if (2*N*N<P)
    171172        {
    172            return(N/B);
    173         }
    174         D=E % N;
    175         C=A-(E-E % N)/N*B;
     173           On(SW_RATIONAL);
     174           N /=B;
     175           Off(SW_RATIONAL);
     176           return(N);
     177        }
     178        D=mod(E , N);
     179        C=A-(E-mod(E , N))/N*B;
    176180        E=N;
    177181        N=D;
     
    184188CanonicalForm Farey ( const CanonicalForm & f, const CanonicalForm & q )
    185189{
     190    int is_rat=isOn(SW_RATIONAL);
     191    Off(SW_RATIONAL);
    186192    Variable x = f.mvar();
    187193    CanonicalForm result = 0;
     
    198204          result += power( x, i.exp() ) * Farey(c,q);
    199205    }
     206    if (is_rat) On(SW_RATIONAL);
    200207    return result;
    201208}
  • factory/cf_gcd.cc

    r8b388e r08a6ebb  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_gcd.cc,v 1.50 2007-09-26 09:17:39 Singular Exp $ */
     2/* $Id: cf_gcd.cc,v 1.51 2007-09-26 14:31:12 Singular Exp $ */
    33
    44#include <config.h>
     
    983983
    984984#define GCD_CHINES_MIN_TRIES 3
    985 #define GCD_CHINES_MAX_TRIES 7
    986985CanonicalForm chinrem_gcd ( const CanonicalForm & FF, const CanonicalForm & GG )
    987986{
     
    992991  f=cd*FF;
    993992  f /=vcontent(f,Variable(1));
    994   cd = bCommonDen( f ); f *=cd;
    995   f /=vcontent(f,Variable(1));
     993  //cd = bCommonDen( f ); f *=cd;
     994  //f /=vcontent(f,Variable(1));
    996995
    997996  cd = bCommonDen( GG );
    998997  g=cd*GG;
    999998  g /=vcontent(g,Variable(1));
    1000   cd = bCommonDen( g ); g *=cd;
    1001   g /=vcontent(g,Variable(1));
     999  //cd = bCommonDen( g ); g *=cd;
     1000  //g /=vcontent(g,Variable(1));
    10021001
    10031002  q = 0;
     
    10181017    n--;
    10191018    Dp = gcd( mapinto( f ), mapinto( g ) );
     1019    Dp /=Dp.lc();
    10201020    setCharacteristic( 0 );
    10211021    dp_deg=totaldegree(Dp);
     
    10361036        D = newD;
    10371037      }
    1038       else if ( dp_deg < d_deg )
     1038      else if ( dp_deg > d_deg )
    10391039      {
    10401040        n=GCD_CHINES_MIN_TRIES;
     
    10441044        d_deg=dp_deg;
    10451045      }
    1046       //else
    1047       //  printf("bad prime\n");
    1048       // else p is a bad prime
    1049     }
    1050     if (( i >= 0 ) && (n >= GCD_CHINES_MIN_TRIES-GCD_CHINES_MAX_TRIES))
     1046      //else dp_deg < d_deg: bad prime
     1047    }
     1048    if ( i >= 0 )
    10511049    {
    10521050      if (n<=0)
    10531051      {
    1054       // now balance D mod q
    1055       //CanonicalForm Dn = balance_p( D, q );
    1056       //out_cf("test ",Dn,"\n");
    1057       //if ( fdivides( Dn, f ) && fdivides( Dn, g ) )
    1058       //{
    1059       //  //printf("does divide\n");
    1060       //  return Dn;
    1061       //}
    1062       CanonicalForm Dn= Farey(D,q);
    1063       CanonicalForm cd = bCommonDen( Dn );
    1064       Dn *=cd;
    1065       Dn /=vcontent(Dn,Variable(1));
    1066       if ( fdivides( Dn, f ) && fdivides( Dn, g ) )
    1067       {
    1068         //printf("does divide\n");
    1069         return Dn;
     1052        CanonicalForm Dn= Farey(D,q);
     1053        int is_rat=isOn(SW_RATIONAL);
     1054        On(SW_RATIONAL);
     1055        CanonicalForm cd = bCommonDen( Dn ); // we need On(SW_RATIONAL)
     1056        if (!is_rat) Off(SW_RATIONAL);
     1057        Dn *=cd;
     1058        //Dn /=vcontent(Dn,Variable(1));
     1059        if ( fdivides( Dn, f ) && fdivides( Dn, g ) )
     1060        {
     1061          return Dn;
     1062        }
     1063      //else: try more primes
    10701064      }
    1071       //else
    1072       // printf("does not divide\n");
    1073       }
    1074     }
    1075     else
    1076     {
    1077       #if 0
    1078       printf("primes left:%d, tries left:%d, gcd-deg:%d\n",i,n,d_deg);
    1079       out_cf("f= ",f,"\n");
    1080       out_cf("g= ",g,"\n");
    1081       CanonicalForm Dn= Farey(D,q);
    1082       CanonicalForm cd = bCommonDen( Dn );
    1083       Dn *=cd;
    1084       Dn /=vcontent(Dn,Variable(1));
    1085       out_cf("farey: ",Dn,"\n");
    1086       #endif
     1065    }
     1066    else
     1067    {
    10871068      Off(SW_USE_CHINREM_GCD);
    10881069      D=gcd_poly( f, g );
    10891070      On(SW_USE_CHINREM_GCD);
    1090       #if 0
    1091       out_cf("gcd: ",D,"\n");
    1092       #endif
    10931071      return D;
    10941072    }
Note: See TracChangeset for help on using the changeset viewer.