Changeset a355723 in git for libpolys


Ignore:
Timestamp:
Oct 22, 2012, 2:45:46 PM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '6e5adcba05493683b94648c659a729c189812c77')
Children:
314f0a2563593c2ed06d4bf520c64eabc6b2c701becbea965e6c5de8e8ab195c7f480cabc295ac0c
Parents:
b79ed5b79606bbec4a3bc2f9ad41e76c5d40137e
Message:
fix: ntInvers/resultant
Location:
libpolys/polys
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/clapsing.cc

    rb79ed5 ra355723  
    177177      CanonicalForm F( convSingTrPFactoryP( f,r ) ), G( convSingTrPFactoryP( g,r ) );
    178178      res= convFactoryPSingTrP( resultant( F, G, X ),r );
    179       if ((nf!=NULL)&&(!n_IsOne(nf,r->cf))&&(!n_IsZero(nf,r->cf)))
     179      if ((nf!=NULL)&&(!n_IsOne(nf,r->cf)))
    180180      {
    181181        number n=n_Invers(nf,r->cf);
     
    188188      }
    189189      n_Delete(&nf,r->cf);
    190       if ((ng!=NULL)&&(!n_IsOne(ng,r->cf))&&(!n_IsZero(ng,r->cf)))
     190      if ((ng!=NULL)&&(!n_IsOne(ng,r->cf)))
    191191      {
    192192        number n=n_Invers(ng,r->cf);
  • libpolys/polys/ext_fields/transext.cc

    rb79ed5 ra355723  
    161161
    162162  const poly den = DEN(t);
    163  
     163
    164164  if (den != NULL) // !DENIS1(f)
    165165  {
    166166    assume( p_Test(den, ntRing) );
    167      
     167
    168168    if(p_IsConstant(den, ntRing) && (n_IsOne(pGetCoeff(den), ntRing->cf)))
    169169    {
     
    171171      return FALSE;
    172172    }
    173        
     173
    174174    if( !n_GreaterZero(pGetCoeff(den), ntRing->cf) )
    175175    {
     
    177177      return FALSE;
    178178    }
    179    
     179
    180180    // test that den is over integers!?
    181      
     181
    182182  } else
    183183  {  // num != NULL // den == NULL
    184    
     184
    185185//    if( COM(t) != 0 )
    186186//    {
    187 //      Print("?//NULL with non-zero complexity: %d in %s:%d\n", COM(t), f, l);   
     187//      Print("?//NULL with non-zero complexity: %d in %s:%d\n", COM(t), f, l);
    188188//      return FALSE;
    189189//    }
     
    293293  ntTest(a);
    294294  definiteGcdCancellation(a, cf, FALSE);
    295  
     295
    296296  if (IS0(a)) return NULL;
    297297
     
    307307  {
    308308    assume( DEN (f) == NULL );
    309    
     309
    310310    number g;
    311311    // TODO/NOTE: the following should not be necessary (due to
    312     // Hannes!) as NUM (f) should be over Z!!!   
     312    // Hannes!) as NUM (f) should be over Z!!!
    313313    CPolyCoeffsEnumerator itr(NUM(f));
    314314
     
    324324
    325325    // g should be a positive integer now!
    326     assume( n_GreaterZero(g, ntRing->cf) ); 
    327    
     326    assume( n_GreaterZero(g, ntRing->cf) );
     327
    328328    if( !n_IsOne(g, ntRing->cf) )
    329329    {
    330330      DEN (f) = p_NSet(g, ntRing); // update COM(f)???
    331331      COM (f) ++;
    332       assume( DEN (f) != NULL );           
     332      assume( DEN (f) != NULL );
    333333    }
    334334    else
     
    339339
    340340  // Call ntNormalize instead of above?!?
    341  
     341
    342342  NUM (result) = p_Copy (NUM (f), ntRing); // ???
    343343  DEN (result) = NULL;
    344344  COM (result) = 0;
    345  
     345
    346346  ntTest((number)result);
    347347  return (number)result;
     
    361361
    362362  const BOOLEAN denis1 = DENIS1 (f);
    363  
     363
    364364  if( IS0(f) || (denis1 && getCoeffType (ntCoeffs) != n_Q) ) // */1 or 0
    365365  {
     
    388388//    NUM (result) = p_One(ntRing); // NOTE: just in order to be sure...
    389389  }
    390  
     390
    391391  // */1 / Q
    392392  assume( getCoeffType (ntCoeffs) == n_Q );
    393   assume( DEN (f) == NULL );     
    394    
    395   number g;   
     393  assume( DEN (f) == NULL );
     394
     395  number g;
    396396//    poly num= p_Copy (NUM (f), ntRing); // ???
    397397
     
    400400  // Hannes!) as NUM (f) should be over Z!!!
    401401  CPolyCoeffsEnumerator itr(NUM(f));
    402    
    403   n_ClearDenominators(itr, g, ntRing->cf); // may return -1 :((( 
     402
     403  n_ClearDenominators(itr, g, ntRing->cf); // may return -1 :(((
    404404//    nlClearDenominators(itr, g, ntRing->cf);
    405405
    406    
     406
    407407  if( !n_GreaterZero(g, ntRing->cf) )
    408408  {
     
    414414
    415415  // g should be a positive integer now!
    416   assume( n_GreaterZero(g, ntRing->cf) ); 
     416  assume( n_GreaterZero(g, ntRing->cf) );
    417417
    418418  if( !n_IsOne(g, ntRing->cf) )
     
    420420    assume( n_GreaterZero(g, ntRing->cf) );
    421421    assume( !n_IsOne(g, ntRing->cf) );
    422    
     422
    423423    DEN (f) = p_NSet(g, ntRing); // update COM(f)???
    424424    assume( DEN (f) != NULL );
    425425    COM (f) ++;
    426      
     426
    427427    NUM (result)= p_Copy (DEN (f), ntRing);
    428428  }
     
    431431    NUM (result)= p_NSet(g, ntRing); // p_Copy (DEN (f), ntRing);
    432432//  n_Delete(&g, ntRing->cf);
    433   }     
    434  
     433  }
     434
    435435//    if (!p_IsConstant (num, ntRing) && pNext(num) != NULL)
    436436//    else
     
    444444BOOLEAN ntIsOne(number a, const coeffs cf)
    445445{
    446   ntTest(a); // !!! 
     446  ntTest(a); // !!!
    447447  definiteGcdCancellation(a, cf, FALSE);
    448448  fraction f = (fraction)a;
     
    498498    n_Delete(&n, C);
    499499    return NULL;
    500   }   
     500  }
    501501
    502502  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    503    
     503
    504504  number den = n_GetDenom(n, C);
    505    
     505
    506506  assume( n_GreaterZero(den, C) );
    507    
     507
    508508  if( n_IsOne(den, C) )
    509509  {
    510510     NUM(result) = p_NSet(n, A);
    511      DEN(result) = NULL;       
    512      n_Delete(&den, C); 
     511     DEN(result) = NULL;
     512     n_Delete(&den, C);
    513513  } else
    514514  {
    515      DEN(result) = p_NSet(den, A);     
    516      NUM(result) = p_NSet(n_GetNumerator(n, C), A); 
    517      n_Delete(&n, C);     
     515     DEN(result) = p_NSet(den, A);
     516     NUM(result) = p_NSet(n_GetNumerator(n, C), A);
     517     n_Delete(&n, C);
    518518  }
    519519
     
    525525}
    526526
    527    
     527
    528528number ntInit(long i, const coeffs cf)
    529529{
     
    545545{
    546546  if (p == 0) return NULL;
    547    
     547
    548548    number g;
    549549    // TODO/NOTE: the following should not be necessary (due to
    550     // Hannes!) as NUM (f) should be over Z!!!   
     550    // Hannes!) as NUM (f) should be over Z!!!
    551551    CPolyCoeffsEnumerator itr(p);
    552552
     
    561561
    562562    // g should be a positive integer now!
    563     assume( n_GreaterZero(g, ntRing->cf) ); 
     563    assume( n_GreaterZero(g, ntRing->cf) );
    564564
    565565    fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    566      
     566
    567567    if( !n_IsOne(g, ntRing->cf) )
    568568    {
    569       DEN (f) = p_NSet(g, ntRing); 
     569      DEN (f) = p_NSet(g, ntRing);
    570570//      COM (f) ++; // update COM(f)???
    571       assume( DEN (f) != NULL );           
     571      assume( DEN (f) != NULL );
    572572    }
    573573    else
    574574    {
    575       DEN(f) = NULL;     
     575      DEN(f) = NULL;
    576576      n_Delete(&g, ntRing->cf);
    577     }   
    578    
     577    }
     578
    579579    NUM(f) = p;
    580580    COM(f) = 0;
     
    591591  fraction f = (fraction)a;
    592592  if (!DENIS1(f)) return 0;
    593  
     593
    594594  const poly aAsPoly = NUM(f);
    595595
    596596  if(aAsPoly == NULL)
    597597    return 0;
    598  
     598
    599599  if (!p_IsConstant(aAsPoly, ntRing))
    600600    return 0;
    601601
    602602  assume( aAsPoly != NULL );
    603  
     603
    604604  return n_Int(p_GetCoeff(aAsPoly, ntRing), ntCoeffs);
    605605}
     
    720720
    721721//  ntTest((number)result);
    722    
     722
    723723  return (number)result;
    724724}
     
    763763  ntTest(a); // !!!?
    764764  ntTest(b); // !!!?
    765  
     765
    766766  if (IS0(a) || IS0(b)) return NULL;
    767767
     
    780780  const poly db = DEN(fb);
    781781
    782  
     782
    783783  if (db == NULL)
    784784  {
    785785    // b = ? // NULL
    786    
     786
    787787    if(da == NULL)
    788788    { // both fa && fb are ?? // NULL!
     
    791791      COM(result) = 0;
    792792    }
    793     else 
     793    else
    794794    {
    795795      assume (da != NULL && db == NULL);
     
    817817
    818818//  ntTest((number)result);
    819  
     819
    820820  return (number)result;
    821821}
     
    10461046    p_Delete(&DEN(f), ntRing); DEN(f) = NULL;
    10471047  }
    1048    
     1048
    10491049  if( DEN(f) != NULL )
    10501050    if( !n_GreaterZero(pGetCoeff(DEN(f)), ntCoeffs) )
     
    10521052      NUM(f) = p_Neg(NUM(f), ntRing);
    10531053      DEN(f) = p_Neg(DEN(f), ntRing);
    1054     } 
    1055    
     1054    }
     1055
    10561056  ntTest((number)f); // TODO!
    10571057}
     
    10761076  } else
    10771077  {
    1078     if (COM(f) > BOUND_COMPLEXITY) 
     1078    if (COM(f) > BOUND_COMPLEXITY)
    10791079      definiteGcdCancellation(a, cf, TRUE);
    10801080
     
    10851085      NUM(f) = p_Neg(NUM(f), ntRing);
    10861086      DEN(f) = p_Neg(DEN(f), ntRing);
    1087     } 
    1088   }
    1089  
    1090  
     1087    }
     1088  }
     1089
     1090
    10911091  ntTest(a); // !!!!????
    10921092}
     
    11641164      NUM(f) = p_Neg(NUM(f), ntRing);
    11651165      DEN(f) = p_Neg(DEN(f), ntRing);
    1166     }   
     1166    }
    11671167#endif /* HAVE_FACTORY */
    1168    
     1168
    11691169  ntTest(a); // !!!!
    11701170}
     
    11921192      p_String0Long(DEN(f), ntRing, ntRing);
    11931193      if (!omitBrackets) StringAppendS(")");
    1194     }   
     1194    }
    11951195  }
    11961196  ntTest(a); // !!!!
     
    12591259  }
    12601260
    1261   return FALSE; 
     1261  return FALSE;
    12621262}
    12631263
     
    12871287
    12881288    ntTest((number)result); // !!!!
    1289      
     1289
    12901290    return (number)result;
    12911291  }
    1292    
     1292
    12931293
    12941294  /* return pa*pb/gcd */
     
    12991299    ntTest((number)result); // !!!!
    13001300    return (number)result;
    1301  
     1301
    13021302#else
    13031303  Print("// factory needed: transext.cc:ntLcm\n");
     
    13781378  ntTest(a);
    13791379  if (IS0(a))
    1380   {   
     1380  {
    13811381    WerrorS(nDivBy0);
    13821382    return NULL;
    1383   } 
     1383  }
    13841384  fraction f = (fraction)a;
    13851385  assume( f != NULL );
     
    13891389  assume( NUM(f) != NULL );
    13901390  const poly den = DEN(f);
    1391  
     1391
    13921392  if (den == NULL)
    13931393    NUM(result) = p_One(ntRing);
     
    13971397  if( !NUMIS1(f) )
    13981398  {
    1399     DEN(result) = p_Copy(NUM(f), ntRing);
     1399    poly num_f=NUM(f);
     1400    BOOLEAN neg= !n_GreaterZero(pGetCoeff(num_f),ntRing->cf);
     1401    if (neg)
     1402    {
     1403      num_f=p_Neg(p_Copy(num_f, ntRing), ntRing);
     1404      NUM(result)=p_Neg(NUM(result), ntRing);
     1405    }
     1406    else
     1407    {
     1408      num_f=p_Copy(num_f, ntRing);
     1409    }
     1410    DEN(result) = num_f;
    14001411    COM(result) = COM(f);
     1412    if (neg)
     1413    {
     1414      if (p_IsOne(num_f, ntRing))
     1415      {
     1416        DEN(result)=NULL;
     1417        COM(result) = 0;
     1418        p_Delete(&num_f,ntRing);
     1419      }
     1420    }
    14011421  }
    14021422  else
     
    14391459{
    14401460//  if (n_IsZero(a, cf)) return NULL;
    1441    
     1461
    14421462  ntTest(a);
    14431463
    14441464  if (IS0(a)) return NULL;
    1445    
     1465
    14461466  const ring rSrc = cf->extRing;
    14471467  const ring rDst = dst->extRing;
    1448  
     1468
    14491469  if( rSrc == rDst )
    14501470    return ntCopy(a, dst); // USUALLY WRONG!
    1451  
     1471
    14521472  fraction f = (fraction)a;
    14531473  poly g = prCopyR(NUM(f), rSrc, rDst);
    1454    
     1474
    14551475  poly h = NULL;
    1456  
     1476
    14571477  if (!DENIS1(f))
    14581478     h = prCopyR(DEN(f), rSrc, rDst);
    1459    
     1479
    14601480  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    1461    
     1481
    14621482  NUM(result) = g;
    14631483  DEN(result) = h;
    14641484  COM(result) = COM(f);
    14651485  assume(n_Test((number)result, dst));
    1466   return (number)result; 
     1486  return (number)result;
    14671487}
    14681488
     
    14711491  assume( n_Test(a, cf) );
    14721492  if (n_IsZero(a, cf)) return NULL;
    1473    
    1474   fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 
     1493
     1494  fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    14751495  // DEN(f) = NULL; COM(f) = 0;
    14761496  NUM(f) = prCopyR((poly)a, cf->extRing, dst->extRing);
     
    14921512    return NULL;
    14931513  }
    1494  
     1514
    14951515  poly g = p_NSet(q, dst->extRing);
    14961516
     
    15761596  if (nCoeff_is_Q(bSrc) && nCoeff_is_Q(bDst))
    15771597  {
    1578     if (rVar(src->extRing) > rVar(dst->extRing)) 
     1598    if (rVar(src->extRing) > rVar(dst->extRing))
    15791599       return NULL;
    1580      
     1600
    15811601    for (int i = 0; i < rVar(src->extRing); i++)
    1582       if (strcmp(rRingVar(i, src->extRing), rRingVar(i, dst->extRing)) != 0) 
    1583         return NULL;
    1584      
     1602      if (strcmp(rRingVar(i, src->extRing), rRingVar(i, dst->extRing)) != 0)
     1603        return NULL;
     1604
    15851605    if (src->type==n_transExt)
    15861606       return ntCopyMap;          /// Q(T')   --> Q(T)
     
    15911611  if (nCoeff_is_Zp(bSrc) && nCoeff_is_Zp(bDst))
    15921612  {
    1593     if (rVar(src->extRing) > rVar(dst->extRing)) 
     1613    if (rVar(src->extRing) > rVar(dst->extRing))
    15941614       return NULL;
    1595      
     1615
    15961616    for (int i = 0; i < rVar(src->extRing); i++)
    1597       if (strcmp(rRingVar(i, src->extRing), rRingVar(i, dst->extRing)) != 0) 
    1598         return NULL;
    1599      
     1617      if (strcmp(rRingVar(i, src->extRing), rRingVar(i, dst->extRing)) != 0)
     1618        return NULL;
     1619
    16001620    if (src->type==n_transExt)
    16011621       return ntCopyMap;         /// Z/p(T') --> Z/p(T)
     
    17161736  const ring   R = cf->extRing;
    17171737  assume(R != NULL);
    1718   const coeffs Q = R->cf; 
    1719   assume(Q != NULL); 
    1720   assume(nCoeff_is_Q(Q)); 
    1721 
    1722  
     1738  const coeffs Q = R->cf;
     1739  assume(Q != NULL);
     1740  assume(nCoeff_is_Q(Q));
     1741
     1742
    17231743  numberCollectionEnumerator.Reset();
    17241744
     
    17601780  while( numberCollectionEnumerator.MoveNext() ) ;
    17611781
    1762    
     1782
    17631783  // part2: all coeffs = all coeffs * cand
    17641784  if( cand != NULL )
     
    17661786  if( !p_IsConstant(cand, R) )
    17671787  {
    1768     c = ntInit(cand, cf);   
     1788    c = ntInit(cand, cf);
    17691789    numberCollectionEnumerator.Reset();
    17701790    while (numberCollectionEnumerator.MoveNext() )
     
    17781798  else { p_Delete(&cand, R); cand = NULL; }
    17791799  }
    1780    
     1800
    17811801  // Quick and dirty fix for constant content clearing: consider numerators???
    17821802  CRecursivePolyCoeffsEnumerator<NTNumConverter> itr(numberCollectionEnumerator); // recursively treat the NUM(numbers) as polys!
    17831803  number cc;
    1784    
     1804
    17851805//  nlClearContentNoPositiveLead(itr, cc, Q); // TODO: get rid of (-LC) normalization!?
    17861806  nlClearContent(itr, cc, Q);
    17871807  number g = ntInit(p_NSet(cc, R), cf);
    1788    
     1808
    17891809  if( cand != NULL )
    17901810  {
    17911811    number gg = ntMult(g, c, cf);
    1792     ntDelete(&g, cf); 
     1812    ntDelete(&g, cf);
    17931813    ntDelete(&c, cf); c = gg;
    1794   } else 
     1814  } else
    17951815    c = g;
    17961816  ntTest(c);
     
    18171837
    18181838  const ring R = cf->extRing;
    1819   assume(R != NULL); 
    1820 
    1821   const coeffs Q = R->cf; 
    1822   assume(Q != NULL); 
    1823 //  assume(nCoeff_is_Q(Q)); 
     1839  assume(R != NULL);
     1840
     1841  const coeffs Q = R->cf;
     1842  assume(Q != NULL);
     1843//  assume(nCoeff_is_Q(Q));
    18241844
    18251845  do
    18261846  {
    18271847    number &n = numberCollectionEnumerator.Current();
    1828    
     1848
    18291849    ntNormalize(n, cf);
    18301850
     
    18471867      poly gcd = singclap_gcd(p_Copy(cand, R), p_Copy(den, R), R); // gcd(cand, den) is monic no mater leading coeffs! :((((
    18481868//      assume( n_IsOne(pGetCoeff(gcd), Q) ); // TODO: this may be wrong...
    1849       cand = p_Mult_q(cand, p_Copy(den, R), R); // cand *= den     
     1869      cand = p_Mult_q(cand, p_Copy(den, R), R); // cand *= den
    18501870      const poly t = singclap_pdivide( cand, gcd, R ); // cand' * den / gcd(cand', den)
    18511871      p_Delete(&cand, R);
     
    18601880    c = ntInit(1, cf);
    18611881    return;
    1862   } 
    1863 
    1864   c = ntInit(cand, cf); 
     1882  }
     1883
     1884  c = ntInit(cand, cf);
    18651885
    18661886  numberCollectionEnumerator.Reset();
    1867    
     1887
    18681888  number d = NULL;
    18691889
     
    18761896    ntNormalize(t, cf); // TODO: needed?
    18771897    n = t;
    1878    
     1898
    18791899    fraction f = (fraction)t;
    18801900    assume( f != NULL );
     
    18861906      assume( p_IsConstant(den, R) );
    18871907      assume( pNext(den) == NULL );
    1888          
     1908
    18891909      if( d == NULL )
    1890         d = n_Copy(pGetCoeff(den), Q);
     1910        d = n_Copy(pGetCoeff(den), Q);
    18911911      else
    18921912      {
    1893         number g = n_Lcm(d, pGetCoeff(den), Q);
     1913        number g = n_Lcm(d, pGetCoeff(den), Q);
    18941914        n_Delete(&d, Q); d = g;
    18951915      }
    18961916    }
    18971917  }
    1898    
     1918
    18991919  if( d != NULL )
    19001920  {
     
    19151935        assume( p_IsConstant(den, R) );
    19161936        assume( pNext(den) == NULL );
    1917          
    1918         number ddd = n_Div(d, pGetCoeff(den), Q); // but be an integer now!!!
     1937
     1938        number ddd = n_Div(d, pGetCoeff(den), Q); // but be an integer now!!!
    19191939        NUM(f) = p_Mult_nn(NUM(f), ddd, R);
    1920         n_Delete(&ddd, Q);
    1921        
    1922         p_Delete(&DEN(f), R);
    1923         DEN(f) = NULL; // TODO: check if this is needed!?
    1924       }     
    1925        
     1940        n_Delete(&ddd, Q);
     1941
     1942        p_Delete(&DEN(f), R);
     1943        DEN(f) = NULL; // TODO: check if this is needed!?
     1944      }
     1945
    19261946      assume( DEN(f) == NULL );
    19271947    }
    1928      
     1948
    19291949    NUM(c) = p_Mult_nn(NUM(c), d, R);
    19301950    n_Delete(&d, Q);
    19311951  }
    1932    
    1933    
     1952
     1953
    19341954  ntTest(c);
    19351955}
     
    19511971  ring R = e->r;
    19521972  assume(R != NULL);
    1953  
     1973
    19541974  R->ref ++; // increase the ref.counter for the ground poly. ring!
    19551975
     
    19591979  cf->ch = R->cf->ch;
    19601980  cf->factoryVarOffset = R->cf->factoryVarOffset + rVar(R);
    1961  
     1981
    19621982  cf->cfGreaterZero  = ntGreaterZero;
    19631983  cf->cfGreater      = ntGreater;
  • libpolys/polys/monomials/p_polys.cc

    rb79ed5 ra355723  
    27122712  }
    27132713
    2714   assume( n_GreaterZero(pGetCoeff(ph),C) );
    27152714  if(!n_GreaterZero(pGetCoeff(ph),C))
    27162715  {
Note: See TracChangeset for help on using the changeset viewer.