Ignore:
Timestamp:
May 30, 2012, 10:05:27 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
210d1bfc080ce1cf56ed7c937c68613a6c8cc989
Parents:
2407cbbcbfa07c81823bde4407a9c0ae473b292c
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-05-30 22:05:27+02:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2014-05-07 04:41:44+02:00
Message:
implemented FindReducer in syzextra

chg: (SS)FindReducer don't need T!
add: SSFindReducer uses FindReducer by default and can check its result!
File:
1 edited

Legend:

Unmodified
Added
Removed
  • dyn_modules/syzextra/mod_main.cc

    r2407cb r33161fd  
    595595  if( __DEBUG__ )
    596596  {
    597     PrintS("  a & b have the same comp & deg! "); PrintLn();
     597    PrintS("cmp_c_ds: a & b have the same comp & deg! "); PrintLn();
    598598  }
    599599#endif
     
    10701070
    10711071
     1072/// return a new term: leading coeff * leading monomial of p
     1073/// with 0 leading component!
     1074static inline poly leadmonom(const poly p, const ring r)
     1075{
     1076  poly m = NULL;
     1077
     1078  if( p != NULL )
     1079  {
     1080    assume( p != NULL );
     1081    assume( p_LmTest(p, r) );
     1082
     1083    m = p_LmInit(p, r);
     1084    p_SetCoeff0(m, n_Copy(p_GetCoeff(p, r), r), r);
     1085
     1086    p_SetComp(m, 0, r);
     1087    p_Setm(m, r);
     1088
     1089    assume( p_GetComp(m, r) == 0 );
     1090    assume( m != NULL );
     1091    assume( pNext(m) == NULL );
     1092    assume( p_LmTest(m, r) );
     1093  }
     1094
     1095  return m;
     1096}
     1097
     1098
     1099/// TODO: save shortcut (syz: |-.->) LM(LM(m) * "t") -> syz?
     1100/// proc SSFindReducer(def product, def syzterm, def L, def T, list #)
     1101static BOOLEAN FindReducer(leftv res, leftv h)
     1102{
     1103  const ring r = currRing;
     1104
     1105  NoReturn(res);
     1106
     1107
     1108#ifndef NDEBUG
     1109  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)TRUE)));
     1110#else
     1111  const BOOLEAN __DEBUG__ = (BOOLEAN)((long)(atGet(currRingHdl,"DEBUG",INT_CMD, (void*)FALSE)));
     1112#endif
     1113
     1114  const BOOLEAN __TAILREDSYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"TAILREDSYZ",INT_CMD, (void*)0)));
     1115  const BOOLEAN __LEAD2SYZ__ = (BOOLEAN)((long)(atGet(currRingHdl,"LEAD2SYZ",INT_CMD, (void*)0)));
     1116  const BOOLEAN __SYZCHECK__ = (BOOLEAN)((long)(atGet(currRingHdl,"SYZCHECK",INT_CMD, (void*)0)));   
     1117
     1118  if ((h==NULL) || (h->Typ()!=VECTOR_CMD && h->Typ() !=POLY_CMD) || (h->Data() == NULL))
     1119  {
     1120    WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected");
     1121    return TRUE;   
     1122  }
     1123   
     1124  const poly product = (poly) h->Data(); h = h->Next();
     1125
     1126  assume (product != NULL);
     1127
     1128   
     1129  if ((h==NULL) || (h->Typ()!=VECTOR_CMD))
     1130  {
     1131    WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected");
     1132    return TRUE;   
     1133  }
     1134
     1135  const poly syzterm = (poly) h->Data(); h = h->Next();
     1136
     1137  int c = 0;
     1138 
     1139  if (syzterm != NULL)
     1140    c = p_GetComp(syzterm, r) - 1;
     1141 
     1142 
     1143  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1144  {
     1145    WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected");
     1146    return TRUE;   
     1147  }
     1148 
     1149  const ideal L = (ideal) h->Data(); h = h->Next();
     1150
     1151  assume( IDELEMS(L) > 0 );
     1152  assume( c >= 0 && c < IDELEMS(L) );
     1153
     1154 
     1155/*
     1156  if ((h==NULL) || (h->Typ()!=IDEAL_CMD && h->Typ() !=MODUL_CMD) || (h->Data() == NULL))
     1157  {
     1158    WerrorS("`FindReducer(<poly/vector>, <vector>, <ideal/module>[,<module>])` expected");
     1159    return TRUE;   
     1160  }
     1161
     1162  const ideal T = (ideal) h->Data(); h = h->Next();
     1163*/
     1164
     1165  ideal LS = NULL;
     1166
     1167  if ((h != NULL) && (h->Typ() ==MODUL_CMD) && (h->Data() != NULL))
     1168  {
     1169    LS = (ideal)h->Data();
     1170    h = h->Next();
     1171  }
     1172
     1173  if( __TAILREDSYZ__ )
     1174    assume (LS != NULL);
     1175
     1176  assume( h == NULL );
     1177
     1178  if( __DEBUG__ )
     1179  {
     1180    PrintS("FindReducer(product, syzterm, L, T, #)::Input: \n");
     1181
     1182    PrintS("product: "); dPrint(product, r, r, 2);
     1183    PrintS("syzterm: "); dPrint(syzterm, r, r, 2);
     1184    PrintS("L: "); dPrint(L, r, r, 2);
     1185//    PrintS("T: "); dPrint(T, r, r, 4);
     1186
     1187    if( LS == NULL )
     1188      PrintS("LS: NULL\n");
     1189    else
     1190    {
     1191      PrintS("LS: "); dPrint(LS, r, r, 2);
     1192    }
     1193  }
     1194
     1195
     1196  if (__SYZCHECK__ && syzterm != NULL)
     1197  {
     1198    const poly m = L->m[c];
     1199
     1200    assume( m != NULL ); assume( pNext(m) == NULL );
     1201
     1202    poly lm = p_Mult_mm(leadmonom(syzterm, r), m, r);
     1203    assume( p_EqualPolys(lm, product, r) );
     1204
     1205    //  def @@c = leadcomp(syzterm); int @@r = int(@@c);
     1206    //  def @@product = leadmonomial(syzterm) * L[@@r];
     1207
     1208    p_Delete(&lm, r);   
     1209  }
     1210
     1211 
     1212  res->rtyp = VECTOR_CMD;
     1213
     1214  // looking for an appropriate diviser q = L[k]...
     1215  for( int k = IDELEMS(L)-1; k>= 0; k-- )
     1216  {
     1217    const poly p = L->m[k];   
     1218
     1219    // ... which divides the product, looking for the _1st_ appropriate one!
     1220    if( !p_LmDivisibleBy(p, product, r) )
     1221      continue;
     1222
     1223
     1224    const poly q = p_New(r);
     1225    pNext(q) = NULL;
     1226    p_ExpVectorDiff(q, product, p, r); // (LM(product) / LM(L[k]))
     1227    p_SetComp(q, k + 1, r);
     1228    p_Setm(q, r);
     1229
     1230    // cannot allow something like: a*gen(i) - a*gen(i)
     1231    if (syzterm != NULL && (k == c))
     1232      if (p_ExpVectorEqual(syzterm, q, r))
     1233      {
     1234        if( __DEBUG__ )
     1235        {
     1236          Print("FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: ");
     1237          dPrint(syzterm, r, r, 1);
     1238        }   
     1239       
     1240        p_LmFree(q, r);
     1241        continue;
     1242      }
     1243
     1244    // while the complement (the fraction) is not reducible by leading syzygies
     1245    if( LS != NULL )
     1246    {
     1247      BOOLEAN ok = TRUE;
     1248     
     1249      for(int kk = IDELEMS(LS)-1; kk>= 0; kk-- )
     1250      {
     1251        const poly pp = LS->m[kk];
     1252
     1253        if( p_LmDivisibleBy(pp, q, r) )
     1254        {
     1255          if( __DEBUG__ )
     1256          {
     1257            Print("FindReducer::Test LS: q is divisible by LS[%d] !:((, diviser is: ", kk+1);
     1258            dPrint(pp, r, r, 1);
     1259          }   
     1260
     1261          ok = FALSE; // q in <LS> :((
     1262          break;                 
     1263        }
     1264      }
     1265     
     1266      if(!ok)
     1267      {
     1268        p_LmFree(q, r);
     1269        continue;
     1270      }
     1271    }
     1272
     1273    p_SetCoeff0(q, n_Neg( n_Div( p_GetCoeff(product, r), p_GetCoeff(p, r), r), r), r);
     1274
     1275    if( __DEBUG__ )
     1276    {
     1277      PrintS("FindReducer::Output: \n");
     1278      dPrint(q, r, r, 1);
     1279    }   
     1280
     1281    res->data = q;
     1282    return FALSE;
     1283  }
     1284
     1285  res->data = NULL;
     1286  return FALSE;   
     1287 
     1288}
     1289
     1290
     1291
    10721292/// Get leading term without a module component
    10731293static BOOLEAN leadmonom(leftv res, leftv h)
     
    10801300    const poly p = (poly)(h->Data());
    10811301
    1082     poly m = NULL;
    1083 
    1084     if( p != NULL )
    1085     {
    1086       assume( p != NULL );
    1087       assume( p_LmTest(p, r) );
    1088 
    1089       m = p_LmInit(p, r);
    1090       p_SetCoeff0(m, n_Copy(p_GetCoeff(p, r), r), r);
    1091 
    1092       //            if( p_GetComp(m, r) != 0 )
    1093       //            {
    1094       p_SetComp(m, 0, r);
    1095       p_Setm(m, r);
    1096       //            }
    1097 
    1098       assume( p_GetComp(m, r) == 0 );
    1099       assume( m != NULL );
    1100       assume( p_LmTest(m, r) );
    1101     }
     1302    const poly m = leadmonom(p, r);
    11021303
    11031304    res->rtyp = POLY_CMD;
     
    17211922 
    17221923  ADD(psModulFunctions, currPack->libname, "Sort_c_ds", FALSE, Sort_c_ds);
     1924  ADD(psModulFunctions, currPack->libname, "FindReducer", FALSE, FindReducer);
     1925 
    17231926 
    17241927  //  ADD(psModulFunctions, currPack->libname, "GetAMData", FALSE, GetAMData);
Note: See TracChangeset for help on using the changeset viewer.