Changeset 8e89a3 in git


Ignore:
Timestamp:
Nov 29, 2021, 2:48:20 PM (2 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
eccae75d9df69c8235bdc90b5a36a2161eb0654d
Parents:
b9ded9215c1f31f52c684d1560787b9c150d904e
Message:
format (Farey)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_chinese.cc

    rb9ded9 r8e89a3  
    202202CanonicalForm Farey ( const CanonicalForm & f, const CanonicalForm & q )
    203203{
    204     int is_rat=isOn(SW_RATIONAL);
    205     Off(SW_RATIONAL);
    206     Variable x = f.mvar();
    207     CanonicalForm result = 0;
    208     CanonicalForm c;
    209     CFIterator i;
     204  int is_rat=isOn(SW_RATIONAL);
     205  Off(SW_RATIONAL);
     206  Variable x = f.mvar();
     207  CanonicalForm result = 0;
     208  CanonicalForm c;
     209  CFIterator i;
    210210#ifdef HAVE_FLINT
    211    fmpz_t FLINTq;
    212    fmpz_init(FLINTq);
    213    convertCF2initFmpz(FLINTq,q);
    214    fmpz_t FLINTc;
    215    fmpz_init(FLINTc);
    216    fmpq_t FLINTres;
    217    fmpq_init(FLINTres);
     211  fmpz_t FLINTq;
     212  fmpz_init(FLINTq);
     213  convertCF2initFmpz(FLINTq,q);
     214  fmpz_t FLINTc;
     215  fmpz_init(FLINTc);
     216  fmpq_t FLINTres;
     217  fmpq_init(FLINTres);
    218218#elif defined(HAVE_NTL)
    219     ZZ NTLq= convertFacCF2NTLZZ (q);
    220     ZZ bound;
    221     SqrRoot (bound, NTLq/2);
     219  ZZ NTLq= convertFacCF2NTLZZ (q);
     220  ZZ bound;
     221  SqrRoot (bound, NTLq/2);
    222222#else
    223    factoryError("NTL/FLINT missing:Farey");
    224 #endif
    225     for ( i = f; i.hasTerms(); i++ )
     223  factoryError("NTL/FLINT missing:Farey");
     224#endif
     225  for ( i = f; i.hasTerms(); i++ )
     226  {
     227    c = i.coeff();
     228    if ( c.inCoeffDomain())
    226229    {
    227         c = i.coeff();
    228         if ( c.inCoeffDomain())
     230#ifdef HAVE_FLINT
     231      if (c.inZ())
     232      {
     233        convertCF2initFmpz(FLINTc,c);
     234        fmpq_reconstruct_fmpz(FLINTres,FLINTc,FLINTq);
     235        result += power (x, i.exp())*(convertFmpq2CF(FLINTres));
     236      }
     237#elif defined(HAVE_NTL)
     238      if (c.inZ())
     239      {
     240        ZZ NTLc= convertFacCF2NTLZZ (c);
     241        bool lessZero= (sign (NTLc) == -1);
     242        if (lessZero)
     243          NTL::negate (NTLc, NTLc);
     244        ZZ NTLnum, NTLden;
     245        if (ReconstructRational (NTLnum, NTLden, NTLc, NTLq, bound, bound))
    229246        {
     247          if (lessZero)
     248            NTL::negate (NTLnum, NTLnum);
     249          CanonicalForm num= convertNTLZZX2CF (to_ZZX (NTLnum), Variable (1));
     250          CanonicalForm den= convertNTLZZX2CF (to_ZZX (NTLden), Variable (1));
     251          On (SW_RATIONAL);
     252          result += power (x, i.exp())*(num/den);
     253          Off (SW_RATIONAL);
     254        }
     255      }
     256#else
     257      if (c.inZ())
     258        result += power (x, i.exp()) * Farey_n(c,q);
     259#endif
     260      else
     261        result += power( x, i.exp() ) * Farey(c,q);
     262    }
     263    else
     264      result += power( x, i.exp() ) * Farey(c,q);
     265  }
     266  if (is_rat) On(SW_RATIONAL);
    230267#ifdef HAVE_FLINT
    231           if (c.inZ())
    232           {
    233              convertCF2initFmpz(FLINTc,c);
    234              fmpq_reconstruct_fmpz(FLINTres,FLINTc,FLINTq);
    235              result += power (x, i.exp())*(convertFmpq2CF(FLINTres));
    236           }
    237 #elif defined(HAVE_NTL)
    238           if (c.inZ())
    239           {
    240             ZZ NTLc= convertFacCF2NTLZZ (c);
    241             bool lessZero= (sign (NTLc) == -1);
    242             if (lessZero)
    243               NTL::negate (NTLc, NTLc);
    244             ZZ NTLnum, NTLden;
    245             if (ReconstructRational (NTLnum, NTLden, NTLc, NTLq, bound, bound))
    246             {
    247               if (lessZero)
    248                 NTL::negate (NTLnum, NTLnum);
    249               CanonicalForm num= convertNTLZZX2CF (to_ZZX (NTLnum), Variable (1));
    250               CanonicalForm den= convertNTLZZX2CF (to_ZZX (NTLden), Variable (1));
    251               On (SW_RATIONAL);
    252               result += power (x, i.exp())*(num/den);
    253               Off (SW_RATIONAL);
    254             }
    255           }
    256 #else
    257           if (c.inZ())
    258             result += power (x, i.exp()) * Farey_n(c,q);
    259 #endif
    260           else
    261             result += power( x, i.exp() ) * Farey(c,q);
    262         }
    263         else
    264           result += power( x, i.exp() ) * Farey(c,q);
    265     }
    266     if (is_rat) On(SW_RATIONAL);
    267 #ifdef HAVE_FLINT
    268     fmpq_clear(FLINTres);
    269     fmpz_clear(FLINTc);
    270     fmpz_clear(FLINTq);
    271 #endif
    272     return result;
     268  fmpq_clear(FLINTres);
     269  fmpz_clear(FLINTc);
     270  fmpz_clear(FLINTq);
     271#endif
     272  return result;
    273273}
    274274
Note: See TracChangeset for help on using the changeset viewer.