Changeset fe35f2 in git


Ignore:
Timestamp:
Jun 13, 2012, 8:10:48 PM (11 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
9cf2201c9530f84fbd6899531bf184f72c797fc4
Parents:
f6c4596916eaf5784447ac80bd6f9a76c5315bed
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-06-13 20:10:48+02:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2014-05-07 04:41:44+02:00
Message:
finall code migration to C/C++ (syzextra)

add: ReduceTerm&TraverseTail / SchreyerSyzygyNF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/schreyer.lib

    rf6c459 rfe35f2  
    12711271  }
    12721272
    1273   vector s = [0];
    1274 
    1275   if( size(t) > 0 )
    1276   {
    1277     def product = m * t;
    1278 
    1279     s = SSFindReducer(product, syzterm, L/*, T*/, #);
    1280 
    1281     if( size(s) != 0 )
    1282     {
    1283       poly b = leadmonomial(s);
    1284 
    1285       def c = leadcomp(s); int k = int(c);
    1286 
    1287       s = s + SSTraverseTail(b, T[k], L, T, #); // !!!   
    1288     }
    1289   }
     1273  if( typeof(#[1]) == "module" )
     1274  {
     1275    vector ss = ReduceTerm(m, t, syzterm, L, T, #[1]);
     1276  } else
     1277  {
     1278    vector ss = ReduceTerm(m, t, syzterm, L, T);
     1279  }
     1280
     1281  if( @KERCHECK )
     1282  {
     1283    vector s = 0;
     1284
     1285    if( size(t) > 0 )
     1286    {
     1287      def product = m * t;
     1288
     1289      s = SSFindReducer(product, syzterm, L, #);
     1290
     1291      if( size(s) != 0 )
     1292      {
     1293        poly @b = leadmonomial(s);
     1294
     1295        def @c = leadcomp(s); int k = int(@c);
     1296
     1297        s = s + SSTraverseTail(@b, T[k], L, T, #); // !!!   
     1298      }
     1299    }
    12901300   
    1291   if( @DEBUG )
    1292   {
    1293     "SSReduceTerm::Output: ", s;
    1294   }
    1295  
    1296   return (s);
     1301    if( s != ss )
     1302    {
     1303      "ERROR in ReduceTerm => old: ", s, " != ker: ", ss;
     1304      "m: ", m;
     1305      "t: ", t;
     1306      "syzterm: ", syzterm;
     1307      L; T; #;
     1308      $;
     1309    } 
     1310  }
     1311
     1312  if( @DEBUG )
     1313  {
     1314    "SSReduceTerm::Output: ", ss;
     1315  }
     1316 
     1317  return (ss);
    12971318}
    12981319
     
    13311352  }
    13321353
    1333   vector s = 0;
    1334 
    1335   def @l;
     1354  if( typeof(#[1]) == "module" )
     1355  {
     1356    vector ss = TraverseTail(m, @tail, L, T, #[1]);
     1357  } else
     1358  {
     1359    vector ss = TraverseTail(m, @tail, L, T);
     1360  }
     1361
     1362  if( @KERCHECK )
     1363  {
     1364    vector s = 0;
     1365
     1366    def @l, @p;
     1367    @p = @tail;
    13361368
    13371369  // iterate tail-terms in ANY order!
    1338   while( size(@tail) > 0 )
    1339   {
    1340     @l = lead(@tail);
    1341     s = s + SSReduceTerm(m, @l, [0], L, T, #); // :(
    1342     @tail = @tail - @l;
    1343   }
    1344 
    1345   if( @DEBUG )
    1346   {
    1347     "SSTraverseTail::Output: ", s;
    1348   }
    1349   return (s);
    1350 }
     1370    while( size(@p) > 0 )
     1371    {
     1372      @l = lead(@p);
     1373      s = s + SSReduceTerm(m, @l, [0], L, T, #); // :(
     1374      @p = @p - @l;
     1375    }
     1376   
     1377    if( s != ss )
     1378    {
     1379      "ERROR in TraverseTail => old: ", s, " != ker: ", ss;
     1380      "m: ", m;
     1381      "@tail: ", @tail;
     1382      L; T; #;
     1383      $;
     1384    } 
     1385  }
     1386
     1387  if( @DEBUG )
     1388  {
     1389    "SSTraverseTail::Output: ", ss;
     1390  }
     1391 
     1392  return (ss);
     1393}
     1394
     1395// -------------------------------------------------------- //
     1396
     1397proc SSSchreyerSyzygyNF(vector syz_lead, vector syz_2, def L, def T, list #)
     1398"
     1399   Hybrid Syzygy computation: 'reduce' spoly by eliminating _any_ terms
     1400   while discurding terms of lower order!
     1401
     1402   Return the tail syzygy (without: syz_lead, starting with: syz_2)
     1403"
     1404{
     1405  if( typeof( attrib(basering, "DEBUG") ) == "int" )
     1406  {
     1407    int @DEBUG = attrib(basering, "DEBUG");
     1408  } else
     1409  {
     1410    int @DEBUG = !system("with", "ndebug");
     1411  }
     1412
     1413  if( @DEBUG )
     1414  {
     1415    "SSSchreyerSyzygyNF::Input: ";
     1416
     1417    "syzygy_lead: ", syz_lead;
     1418    "syzygy 2nd : ", syz_2;
     1419    L; T;
     1420    if( size(#) > 0 )
     1421    {
     1422      "LSyz: "; #[1];
     1423    }
     1424  }
     1425
     1426  if( typeof( attrib(basering, "KERCHECK") ) == "int" )
     1427  {
     1428    int @KERCHECK = attrib(basering, "KERCHECK");
     1429  } else
     1430  {
     1431    int @KERCHECK = @DEBUG;
     1432  }
     1433
     1434  if( typeof(#[1]) == "module" )
     1435  {
     1436    def my = SchreyerSyzygyNF(syz_lead, syz_2, L, T, #[1]);
     1437  } else
     1438  {
     1439    def my = SchreyerSyzygyNF(syz_lead, syz_2, L, T);
     1440  }
     1441
     1442  if( @KERCHECK )
     1443  {
     1444    def spoly = leadmonomial(syz_lead) * T[int(leadcomp(syz_lead))]
     1445              + leadmonomial(syz_2)    * T[int(leadcomp(syz_2))];
     1446
     1447    vector @tail = syz_2;
     1448
     1449    while (size(spoly) > 0)
     1450    {
     1451      syz_2 = SSFindReducer(lead(spoly), 0, L, #); spoly = Tail(spoly);
     1452
     1453      if( size(syz_2) != 0)
     1454      {         
     1455        spoly = spoly + leadmonomial(syz_2) * T[int(leadcomp(syz_2))];
     1456        @tail = @tail + syz_2;
     1457      }
     1458    }
     1459   
     1460    if( my != @tail )
     1461    {
     1462      "ERROR in SchreyerSyzygyNF => old: ", @tail, " != ker: ", my;
     1463     
     1464      "syzygy_lead: ", syz_lead;
     1465      "syzygy 2nd : ", syz_2;
     1466     
     1467      L; T; #;
     1468      $;
     1469    }
     1470  }
     1471
     1472  if( @DEBUG )
     1473  {
     1474    "SSSchreyerSyzygyNF::Output: ", my;
     1475  }
     1476 
     1477  return (my);
     1478}
     1479
     1480
    13511481
    13521482// -------------------------------------------------------- //
     
    14621592      } else
    14631593      {
    1464         spoly = aa * T[r];
    1465 
    14661594        if( @LEAD2SYZ )
    14671595        {
     
    14801608          }
    14811609        }
    1482        
    1483         c = leadcomp(a2); r2 = int(c); aa2 = leadmonomial(a2);
    1484        
    1485         spoly = spoly + aa2 * T[r2];
    1486         @tail = a2;
    1487 
    1488         while (size(spoly) > 0)
    1489         {
    1490           a2 = SSFindReducer( lead(spoly), [0], L/*, T*/, LS);
    1491           spoly = Tail(spoly);
    1492 
    1493           if( size(a2) != 0)
    1494           {         
    1495             c = leadcomp(a2); r2 = int(c); aa2 = leadmonomial(a2);
    1496 
    1497             spoly = spoly + aa2 * T[r2];
    1498             @tail = @tail + a2;
    1499           }
    1500         }
    1501        
     1610
     1611        @tail = SSSchreyerSyzygyNF(a, a2, L, T, LS);
    15021612      }
    15031613     
     
    18721982
    18731983      exportto(Schreyer, Syzextra::FindReducer);
     1984
     1985      exportto(Schreyer, Syzextra::ReduceTerm);
     1986      exportto(Schreyer, Syzextra::TraverseTail);
     1987
     1988      exportto(Schreyer, Syzextra::SchreyerSyzygyNF);
    18741989    }
    18751990/*
     
    19192034      exportto(Schreyer, Syzextra_g::FindReducer);
    19202035     
     2036      exportto(Schreyer, Syzextra_g::ReduceTerm);
     2037      exportto(Schreyer, Syzextra_g::TraverseTail);
     2038
     2039      exportto(Schreyer, Syzextra_g::SchreyerSyzygyNF);
    19212040    }
    19222041*/
  • dyn_modules/syzextra/mod_main.cc

    rf6c459 rfe35f2  
    10971097
    10981098
    1099 /// TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz?
    1100 /// proc SSFindReducer(def product, def syzterm, def L, def T, list #)
    1101 static BOOLEAN FindReducer(leftv res, leftv h)
    1102 {
    1103   const char* usage = "`FindReducer(<poly/vector>, <vector/0>, <ideal/module>[,<module>])` expected";
    1104   const ring r = currRing;
    1105 
    1106   NoReturn(res);
    1107 
    1108 
     1099
     1100static poly FindReducer(poly product, poly syzterm,
     1101                        ideal L, ideal LS,
     1102                        const ring r)
     1103{
     1104  assume( product != NULL );
     1105  assume( L != NULL );
     1106
     1107  int c = 0;
     1108
     1109  if (syzterm != NULL)
     1110    c = p_GetComp(syzterm, r) - 1;
     1111
     1112  assume( c >= 0 && c < IDELEMS(L) );
     1113 
    11091114#ifndef NDEBUG
    11101115  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE)));
     
    11131118#endif
    11141119
    1115   const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0)));
    1116 
    1117   if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD) || (h->Data() == NULL))
    1118   {
    1119     WerrorS(usage);
    1120     return TRUE;   
    1121   }
    1122    
    1123   const poly product = (poly) h->Data(); assume (product != NULL);
    1124 
    1125 
    1126   h = h->Next();
    1127   if ((h==NULL) || !((h->Typ()==VECTOR_CMD) || (h->Data() == NULL)) )
    1128   {
    1129     WerrorS(usage);
    1130     return TRUE;   
    1131   }
    1132 
    1133   const poly syzterm = (poly) h->Data(); h = h->Next();
    1134 
    1135   int c = 0;
    1136  
    1137   if (syzterm != NULL)
    1138     c = p_GetComp(syzterm, r) - 1;
    1139  
    1140  
    1141   if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
    1142   {
    1143     WerrorS(usage);
    1144     return TRUE;   
    1145   }
    1146  
    1147   const ideal L = (ideal) h->Data(); h = h->Next();
    1148 
    1149   assume( IDELEMS(L) > 0 );
    1150   assume( c >= 0 && c < IDELEMS(L) );
    1151 
    1152  
    1153 /*
    1154   if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
    1155   {
    1156     WerrorS(usage);
    1157     return TRUE;   
    1158   }
    1159 
    1160   const ideal T = (ideal) h->Data(); h = h->Next();
    1161 */
    1162 
    1163   ideal LS = NULL;
    1164 
    1165   if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
    1166   {
    1167     LS = (ideal)h->Data();
    1168     h = h->Next();
    1169   }
    1170 
    1171   if( __TAILREDSYZ__ )
    1172     assume (LS != NULL);
    1173 
    1174   assume( h == NULL );
    1175 
    1176   if( __DEBUG__ )
    1177   {
    1178     PrintS("FindReducer(product, syzterm, L, T, #)::Input: \n");
    1179 
    1180     PrintS("product: "); dPrint(product, r, r, 2);
    1181     PrintS("syzterm: "); dPrint(syzterm, r, r, 2);
    1182     PrintS("L: "); dPrint(L, r, r, 2);
    1183 //    PrintS("T: "); dPrint(T, r, r, 4);
    1184 
    1185     if( LS == NULL )
    1186       PrintS("LS: NULL\n");
    1187     else
    1188     {
    1189       PrintS("LS: "); dPrint(LS, r, r, 2);
    1190     }
    1191   }
    1192 
    1193 
     1120  long debug = __DEBUG__;
     1121  const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)debug)));   
     1122 
    11941123  if (__SYZCHECK__ && syzterm != NULL)
    11951124  {
     
    12061135    p_Delete(&lm, r);   
    12071136  }
    1208 
    1209  
    1210   res->rtyp = VECTOR_CMD;
    1211 
     1137 
    12121138  // looking for an appropriate diviser q = L[k]...
    12131139  for( int k = IDELEMS(L)-1; k>= 0; k-- )
     
    12351161          dPrint(syzterm, r, r, 1);
    12361162        }   
    1237        
     1163
    12381164        p_LmFree(q, r);
    12391165        continue;
     
    12441170    {
    12451171      BOOLEAN ok = TRUE;
    1246      
     1172
    12471173      for(int kk = IDELEMS(LS)-1; kk>= 0; kk-- )
    12481174      {
     
    12511177        if( p_LmDivisibleBy(pp, q, r) )
    12521178        {
     1179         
    12531180          if( __DEBUG__ )
    12541181          {
     
    12611188        }
    12621189      }
    1263      
     1190
    12641191      if(!ok)
    12651192      {
     
    12701197
    12711198    p_SetCoeff0(q, n_Neg( n_Div( p_GetCoeff(product, r), p_GetCoeff(p, r), r), r), r);
    1272 
    1273     if( __DEBUG__ )
    1274     {
    1275       PrintS("FindReducer::Output: \n");
    1276       dPrint(q, r, r, 1);
     1199    return q;
     1200
     1201  }
     1202
     1203 
     1204  return NULL;
     1205}
     1206
     1207
     1208/// TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz?
     1209/// proc SSFindReducer(def product, def syzterm, def L, def T, list #)
     1210static BOOLEAN FindReducer(leftv res, leftv h)
     1211{
     1212  const char* usage = "`FindReducer(<poly/vector>, <vector/0>, <ideal/module>[,<module>])` expected";
     1213  const ring r = currRing;
     1214
     1215  NoReturn(res);
     1216
     1217
     1218#ifndef NDEBUG
     1219  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE)));
     1220#else
     1221  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE)));
     1222#endif
     1223
     1224  const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0)));
     1225
     1226  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD) || (h->Data() == NULL))
     1227  {
     1228    WerrorS(usage);
     1229    return TRUE;   
     1230  }
     1231   
     1232  const poly product = (poly) h->Data(); assume (product != NULL);
     1233
     1234
     1235  h = h->Next();
     1236  if ((h==NULL) || !((h->Typ()==VECTOR_CMD) || (h->Data() == NULL)) )
     1237  {
     1238    WerrorS(usage);
     1239    return TRUE;   
     1240  }
     1241
     1242  poly syzterm = NULL;
     1243
     1244  if(h->Typ()==VECTOR_CMD)
     1245    syzterm = (poly) h->Data();
     1246
     1247
     1248
     1249  h = h->Next();
     1250  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1251  {
     1252    WerrorS(usage);
     1253    return TRUE;   
     1254  }
     1255 
     1256  const ideal L = (ideal) h->Data(); h = h->Next();
     1257
     1258  assume( IDELEMS(L) > 0 );
     1259
     1260  ideal LS = NULL;
     1261
     1262  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
     1263  {
     1264    LS = (ideal)h->Data();
     1265    h = h->Next();
     1266  }
     1267
     1268  if( __TAILREDSYZ__ )
     1269    assume (LS != NULL);
     1270
     1271  assume( h == NULL );
     1272
     1273  if( __DEBUG__ )
     1274  {
     1275    PrintS("FindReducer(product, syzterm, L, T, #)::Input: \n");
     1276
     1277    PrintS("product: "); dPrint(product, r, r, 2);
     1278    PrintS("syzterm: "); dPrint(syzterm, r, r, 2);
     1279    PrintS("L: "); dPrint(L, r, r, 0);
     1280//    PrintS("T: "); dPrint(T, r, r, 4);
     1281
     1282    if( LS == NULL )
     1283      PrintS("LS: NULL\n");
     1284    else
     1285    {
     1286      PrintS("LS: "); dPrint(LS, r, r, 0);
     1287    }
     1288  }
     1289
     1290  res->rtyp = VECTOR_CMD;
     1291  res->data = FindReducer(product, syzterm, L, LS, r);
     1292
     1293  if( __DEBUG__ )
     1294  {
     1295    PrintS("FindReducer::Output: \n");
     1296    dPrint((poly)res->data, r, r, 2);
     1297  }   
     1298 
     1299  return FALSE;   
     1300 
     1301}
     1302
     1303static poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck,
     1304                       ideal L, ideal T, ideal LS, const ring r);
     1305
     1306static poly TraverseTail(poly multiplier, poly tail,
     1307                         ideal L, ideal T, ideal LS,
     1308                         const ring r)
     1309{
     1310  assume( multiplier != NULL );
     1311
     1312  assume( L != NULL );
     1313  assume( T != NULL );
     1314
     1315  poly s = NULL;
     1316
     1317  // iterate over the tail
     1318  for(poly p = tail; p != NULL; p = pNext(p))
     1319    s = p_Add_q(s, ReduceTerm(multiplier, p, NULL, L, T, LS, r), r); 
     1320   
     1321  return s;
     1322}
     1323
     1324
     1325static poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck,
     1326                       ideal L, ideal T, ideal LS, const ring r)
     1327{
     1328  assume( multiplier != NULL );
     1329  assume( term4reduction != NULL );
     1330
     1331
     1332  assume( L != NULL );
     1333  assume( T != NULL );
     1334 
     1335  // assume(r == currRing); // ?
     1336
     1337  // simple implementation with FindReducer:
     1338  poly s = NULL;
     1339 
     1340  if(1)
     1341  {
     1342    // NOTE: only LT(term4reduction) should be used in the following:
     1343    poly product = pp_Mult_mm(multiplier, term4reduction, r);
     1344    s = FindReducer(product, syztermCheck, L, LS, r);
     1345    p_Delete(&product, r);
     1346  }
     1347
     1348  if( s == NULL ) // No Reducer?
     1349    return s;
     1350
     1351  poly b = leadmonom(s, r);
     1352
     1353  const int c = p_GetComp(s, r) - 1;
     1354  assume( c >= 0 && c < IDELEMS(T) );
     1355
     1356  const poly tail = T->m[c];
     1357
     1358  if( tail != NULL )
     1359    s = p_Add_q(s, TraverseTail(b, tail, L, T, LS, r), r); 
     1360 
     1361  return s;
     1362}
     1363
     1364
     1365static poly SchreyerSyzygyNF(poly syz_lead, poly syz_2, ideal L, ideal T, ideal LS, const ring r)
     1366{
     1367  assume( syz_lead != NULL );
     1368  assume( syz_2 != NULL );
     1369
     1370  assume( L != NULL );
     1371  assume( T != NULL );
     1372
     1373  assume( IDELEMS(L) == IDELEMS(T) );
     1374
     1375  int  c = p_GetComp(syz_lead, r) - 1;
     1376
     1377  assume( c >= 0 && c < IDELEMS(T) );
     1378
     1379  poly p = leadmonom(syz_lead, r); // :( 
     1380  poly spoly = pp_Mult_qq(p, T->m[c], r);
     1381  p_Delete(&p, r);
     1382
     1383 
     1384  c = p_GetComp(syz_2, r) - 1;
     1385  assume( c >= 0 && c < IDELEMS(T) );
     1386
     1387  p = leadmonom(syz_2, r); // :(
     1388  spoly = p_Add_q(spoly, pp_Mult_qq(p, T->m[c], r), r);
     1389  p_Delete(&p, r);
     1390
     1391  poly tail = p_Copy(syz_2, r); // TODO: use bucket!?
     1392
     1393  while (spoly != NULL)
     1394  {
     1395    poly t = FindReducer(spoly, NULL, L, LS, r);
     1396
     1397    p_LmDelete(&spoly, r);
     1398   
     1399    if( t != NULL )
     1400    {
     1401      p = leadmonom(t, r); // :(
     1402      c = p_GetComp(t, r) - 1;
     1403
     1404      assume( c >= 0 && c < IDELEMS(T) );
     1405     
     1406      spoly = p_Add_q(spoly, pp_Mult_qq(p, T->m[c], r), r);
     1407
     1408      p_Delete(&p, r);
     1409     
     1410      tail = p_Add_q(tail, t, r);
    12771411    }   
    1278 
    1279     res->data = q;
    1280     return FALSE;
    1281   }
    1282 
    1283   res->data = NULL;
    1284   return FALSE;   
    1285  
    1286 }
     1412  }
     1413 
     1414  return tail;
     1415}
     1416
     1417// proc SchreyerSyzygyNF(vector syz_lead, vector syz_2, def L, def T, list #)
     1418static BOOLEAN SchreyerSyzygyNF(leftv res, leftv h)
     1419{
     1420  const char* usage = "`SchreyerSyzygyNF(<vector>, <vector>, <ideal/module>, <ideal/module>[,<module>])` expected";
     1421  const ring r = currRing;
     1422
     1423  NoReturn(res);
     1424
     1425#ifndef NDEBUG
     1426  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE)));
     1427#else
     1428  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE)));
     1429#endif
     1430
     1431  const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0)));
     1432//  const BOOLEAN __LEAD2SYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"LEAD2SYZ",INT_CMD, (void*)0)));
     1433  const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)0)));   
     1434
     1435  if ((h==NULL) || (h->Typ() != VECTOR_CMD) || (h->Data() == NULL))
     1436  {
     1437    WerrorS(usage);
     1438    return TRUE;   
     1439  }
     1440
     1441  const poly syz_lead = (poly) h->Data(); assume (syz_lead != NULL);
     1442
     1443
     1444  h = h->Next();
     1445  if ((h==NULL) || (h->Typ() != VECTOR_CMD) || (h->Data() == NULL))
     1446  {
     1447    WerrorS(usage);
     1448    return TRUE;   
     1449  }
     1450
     1451  const poly syz_2 = (poly) h->Data(); assume (syz_2 != NULL);
     1452
     1453  h = h->Next();
     1454  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1455  {
     1456    WerrorS(usage);
     1457    return TRUE;   
     1458  }
     1459
     1460  const ideal L = (ideal) h->Data(); assume( IDELEMS(L) > 0 );
     1461
     1462
     1463  h = h->Next();
     1464  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1465  {
     1466    WerrorS(usage);
     1467    return TRUE;   
     1468  }
     1469
     1470  const ideal T = (ideal) h->Data();
     1471
     1472  assume( IDELEMS(L) == IDELEMS(T) );
     1473
     1474  ideal LS = NULL;
     1475
     1476  h = h->Next();
     1477  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
     1478  {
     1479    LS = (ideal)h->Data();
     1480    h = h->Next();
     1481  }
     1482
     1483  if( __TAILREDSYZ__ )
     1484    assume (LS != NULL);
     1485
     1486  assume( h == NULL );
     1487
     1488  if( __DEBUG__ )
     1489  {
     1490    PrintS("SchreyerSyzygyNF(syz_lead, syz_2, L, T, #)::Input: \n");
     1491
     1492    PrintS("syz_lead: "); dPrint(syz_lead, r, r, 2);
     1493    PrintS("syz_2: "); dPrint(syz_2, r, r, 2);
     1494
     1495    PrintS("L: "); dPrint(L, r, r, 0);
     1496    PrintS("T: "); dPrint(T, r, r, 0);
     1497
     1498    if( LS == NULL )
     1499      PrintS("LS: NULL\n");
     1500    else
     1501    {
     1502      PrintS("LS: "); dPrint(LS, r, r, 0);
     1503    }
     1504  }
     1505 
     1506  res->rtyp = VECTOR_CMD;
     1507  res->data = SchreyerSyzygyNF(syz_lead, syz_2, L, T, LS, r);
     1508
     1509  if( __DEBUG__ )
     1510  {
     1511    PrintS("SchreyerSyzygyNF::Output: ");
     1512
     1513    dPrint((poly)res->data, r, r, 2);
     1514  }
     1515
     1516
     1517  return FALSE;
     1518}
     1519
     1520
     1521
     1522/// TODO: save shortcut (syz: |-.->) LM(m) * "t" -> ?
     1523/// proc SSReduceTerm(poly m, def t, def syzterm, def L, def T, list #)
     1524static BOOLEAN ReduceTerm(leftv res, leftv h)
     1525{
     1526  const char* usage = "`ReduceTerm(<poly>, <poly/vector>, <vector/0>, <ideal/module>, <ideal/module>[,<module>])` expected";
     1527  const ring r = currRing;
     1528
     1529  NoReturn(res);
     1530
     1531#ifndef NDEBUG
     1532  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE)));
     1533#else
     1534  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE)));
     1535#endif
     1536
     1537  const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0)));
     1538//  const BOOLEAN __LEAD2SYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"LEAD2SYZ",INT_CMD, (void*)0)));
     1539  const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)0)));   
     1540
     1541  if ((h==NULL) || (h->Typ() !=POLY_CMD) || (h->Data() == NULL))
     1542  {
     1543    WerrorS(usage);
     1544    return TRUE;   
     1545  }
     1546
     1547  const poly multiplier = (poly) h->Data(); assume (multiplier != NULL);
     1548
     1549 
     1550  h = h->Next();
     1551  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD) || (h->Data() == NULL))
     1552  {
     1553    WerrorS(usage);
     1554    return TRUE;   
     1555  }
     1556
     1557  const poly term4reduction = (poly) h->Data(); assume( term4reduction != NULL );
     1558
     1559 
     1560  poly syztermCheck = NULL;
     1561 
     1562  h = h->Next();
     1563  if ((h==NULL) || !((h->Typ()==VECTOR_CMD) || (h->Data() == NULL)) )
     1564  {
     1565    WerrorS(usage);
     1566    return TRUE;   
     1567  }
     1568
     1569  if(h->Typ()==VECTOR_CMD)
     1570    syztermCheck = (poly) h->Data();
     1571
     1572 
     1573  h = h->Next();
     1574  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1575  {
     1576    WerrorS(usage);
     1577    return TRUE;   
     1578  }
     1579
     1580  const ideal L = (ideal) h->Data(); assume( IDELEMS(L) > 0 );
     1581
     1582 
     1583  h = h->Next();
     1584  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1585  {
     1586    WerrorS(usage);
     1587    return TRUE;   
     1588  }
     1589
     1590  const ideal T = (ideal) h->Data();
     1591
     1592  assume( IDELEMS(L) == IDELEMS(T) );
     1593
     1594  ideal LS = NULL;
     1595
     1596  h = h->Next();
     1597  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
     1598  {
     1599    LS = (ideal)h->Data();
     1600    h = h->Next();
     1601  }
     1602
     1603  if( __TAILREDSYZ__ )
     1604    assume (LS != NULL);
     1605
     1606  assume( h == NULL );
     1607
     1608  if( __DEBUG__ )
     1609  {
     1610    PrintS("ReduceTerm(m, t, syzterm, L, T, #)::Input: \n");
     1611
     1612    PrintS("m: "); dPrint(multiplier, r, r, 2);
     1613    PrintS("t: "); dPrint(term4reduction, r, r, 2);
     1614    PrintS("syzterm: "); dPrint(syztermCheck, r, r, 2);
     1615   
     1616    PrintS("L: "); dPrint(L, r, r, 0);
     1617    PrintS("T: "); dPrint(T, r, r, 0);
     1618
     1619    if( LS == NULL )
     1620      PrintS("LS: NULL\n");
     1621    else
     1622    {
     1623      PrintS("LS: "); dPrint(LS, r, r, 0);
     1624    }
     1625  }
     1626
     1627
     1628  if (__SYZCHECK__ && syztermCheck != NULL)
     1629  {
     1630    const int c = p_GetComp(syztermCheck, r) - 1;
     1631    assume( c >= 0 && c < IDELEMS(L) );
     1632   
     1633    const poly p = L->m[c];
     1634    assume( p != NULL ); assume( pNext(p) == NULL );   
     1635
     1636    assume( p_EqualPolys(term4reduction, p, r) ); // assume? TODO
     1637
     1638
     1639    poly m = leadmonom(syztermCheck, r);
     1640    assume( m != NULL ); assume( pNext(m) == NULL );
     1641
     1642    assume( p_EqualPolys(multiplier, m, r) ); // assume? TODO
     1643
     1644    p_Delete(&m, r);   
     1645   
     1646// NOTE:   leadmonomial(syzterm) == m &&  L[leadcomp(syzterm)] == t
     1647  }
     1648
     1649  res->rtyp = VECTOR_CMD;
     1650  res->data = ReduceTerm(multiplier, term4reduction, syztermCheck, L, T, LS, r);
     1651
     1652
     1653  if( __DEBUG__ )
     1654  {
     1655    PrintS("ReduceTerm::Output: ");
     1656
     1657    dPrint((poly)res->data, r, r, 2);
     1658  }
     1659 
     1660 
     1661  return FALSE;
     1662}
     1663
     1664
     1665
     1666
     1667// TODO: store m * @tail -.-^-.-^-.--> ?
     1668// proc SSTraverseTail(poly m, def @tail, def L, def T, list #)
     1669static BOOLEAN TraverseTail(leftv res, leftv h)
     1670{
     1671  const char* usage = "`TraverseTail(<poly>, <poly/vector>, <ideal/module>, <ideal/module>[,<module>])` expected";
     1672  const ring r = currRing;
     1673
     1674  NoReturn(res);
     1675
     1676#ifndef NDEBUG
     1677  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE)));
     1678#else
     1679  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE)));
     1680#endif
     1681
     1682  const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)1)));
     1683
     1684  if ((h==NULL) || (h->Typ() !=POLY_CMD) || (h->Data() == NULL))
     1685  {
     1686    WerrorS(usage);
     1687    return TRUE;   
     1688  }
     1689
     1690  const poly multiplier = (poly) h->Data(); assume (multiplier != NULL);
     1691
     1692  h = h->Next();
     1693  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD))
     1694  {
     1695    WerrorS(usage);
     1696    return TRUE;   
     1697  }
     1698
     1699  const poly tail = (poly) h->Data();
     1700
     1701  h = h->Next();
     1702
     1703  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1704  {
     1705    WerrorS(usage);
     1706    return TRUE;   
     1707  }
     1708
     1709  const ideal L = (ideal) h->Data();
     1710
     1711  assume( IDELEMS(L) > 0 );
     1712
     1713  h = h->Next();
     1714  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1715  {
     1716    WerrorS(usage);
     1717    return TRUE;   
     1718  }
     1719
     1720  const ideal T = (ideal) h->Data();
     1721
     1722  assume( IDELEMS(L) == IDELEMS(T) );
     1723
     1724  h = h->Next();
     1725 
     1726  ideal LS = NULL;
     1727
     1728  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
     1729  {
     1730    LS = (ideal)h->Data();
     1731    h = h->Next();
     1732  }
     1733
     1734  if( __TAILREDSYZ__ )
     1735    assume (LS != NULL);
     1736
     1737  assume( h == NULL );
     1738
     1739  if( __DEBUG__ )
     1740  {
     1741    PrintS("TraverseTail(m, t, L, T, #)::Input: \n");
     1742
     1743    PrintS("m: "); dPrint(multiplier, r, r, 2);
     1744    PrintS("t: "); dPrint(tail, r, r, 10);
     1745
     1746    PrintS("L: "); dPrint(L, r, r, 0);
     1747    PrintS("T: "); dPrint(T, r, r, 0);
     1748
     1749    if( LS == NULL )
     1750      PrintS("LS: NULL\n");
     1751    else
     1752    {
     1753      PrintS("LS: "); dPrint(LS, r, r, 0);
     1754    }
     1755  }
     1756
     1757  res->rtyp = VECTOR_CMD;
     1758  res->data = TraverseTail(multiplier, tail, L, T, LS, r);
     1759
     1760
     1761  if( __DEBUG__ )
     1762  {
     1763    PrintS("TraverseTail::Output: ");
     1764    dPrint((poly)res->data, r, r, 2);
     1765  }
     1766
     1767  return FALSE;
     1768}
     1769
     1770
     1771
    12871772
    12881773
     
    19212406  ADD(psModulFunctions, currPack->libname, "Sort_c_ds", FALSE, Sort_c_ds);
    19222407  ADD(psModulFunctions, currPack->libname, "FindReducer", FALSE, FindReducer);
    1923  
     2408
     2409
     2410  ADD(psModulFunctions, currPack->libname, "ReduceTerm", FALSE, ReduceTerm);
     2411  ADD(psModulFunctions, currPack->libname, "TraverseTail", FALSE, TraverseTail);
     2412
     2413   
     2414  ADD(psModulFunctions, currPack->libname, "SchreyerSyzygyNF", FALSE, SchreyerSyzygyNF);
    19242415 
    19252416  //  ADD(psModulFunctions, currPack->libname, "GetAMData", FALSE, GetAMData);
Note: See TracChangeset for help on using the changeset viewer.