Changeset 56c789 in git for Singular/gentable.cc


Ignore:
Timestamp:
Oct 12, 2010, 3:03:05 PM (14 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
f86c483adff92eaa95fe133be87f5d14b7f57b61
Parents:
ec58bdfcf1e8339250d75b8fc0ce7fbbce505ddb
Message:
new table generation, p2

git-svn-id: file:///usr/local/Singular/svn/trunk@13459 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/gentable.cc

    rec58bd r56c789  
    886886}
    887887
     888#ifdef HAVE_MPSR
     889#include <Singular/mpsr.h>
     890#include <Singular/mpsr_Tok.h>
     891#define MAX_COP 256 // there may be at most 256 cops
     892
     893// this is the main data struct for storing the relation
     894// Singular token <-> (Dict, OP)
     895typedef struct mpsr_cmd
     896{
     897
     898  short         tok;    // The Singular token encoding
     899
     900  // The MP Dict tag in which this token is defined,
     901  MP_DictTag_t  dict;
     902
     903  // The MP operator corresponding to this token
     904  MP_Common_t   cop; // operator
     905} mpsr_cmd;
     906
     907#define MAX_SR_DICT     5
     908
     909// this provides a mapping from MP dict tags to more useful (small)
     910// array indicies
     911inline short mpdict2srdict(MP_DictTag_t dict)
     912{
     913  if (dict == MP_SingularDict) return 0;
     914  else if (dict == MP_BasicDict) return 1;
     915  else if (dict == MP_PolyDict) return 2;
     916  else if (dict == MP_MatrixDict) return 3;
     917  else if (dict == MP_NumberDict) return 4;
     918  else return MAX_SR_DICT;
     919}
     920
     921// This is the array which holds all mpsr_cmds
     922// It is initialized in mpsr_tok.inc
     923static mpsr_cmd mpsr_cmds[MAX_TOK];
     924
     925// This is the array which stores the mapping from token to an mpsr_cmd
     926// A value is either an index into mpsr_cmds, or MAX_TOK
     927static short tok2mp[MAX_TOK];
     928
     929// This is the array which stores the mapping from (dict, cop) to a
     930// mpsr_cmd. First index mpdict2srdict(dict), second is cop
     931static short mp2tok[MAX_SR_DICT][MAX_COP];
     932
     933// This the list of all tokens which have an MP representation as a
     934// cop in the Singular dictionary
     935short sr_cmds[] =
     936{
     937  OPTION_CMD,
     938  NAMES_CMD,
     939  ATTRIB_CMD,
     940  CHARSTR_CMD,
     941  CLOSE_CMD,
     942  DEF_CMD,
     943  DEGREE_CMD,
     944  DEFINED_CMD,
     945  E_CMD,
     946  EXECUTE_CMD,
     947  FREEMODULE_CMD,
     948  INT_CMD,
     949  INTERRED_CMD,
     950  INTMAT_CMD,
     951  INTVEC_CMD,
     952  IS_RINGVAR,
     953  KILLATTR_CMD,
     954  MAP_CMD,
     955  MEMORY_CMD,
     956  MONITOR_CMD,
     957  NAMEOF_CMD,
     958  NUMBER_CMD,
     959  NPARS_CMD,
     960  NVARS_CMD,
     961  OPEN_CMD,
     962  ORDSTR_CMD,
     963  PAR_CMD,
     964  PARSTR_CMD,
     965  PARDEG_CMD,
     966  POLY_CMD,
     967  PRINT_CMD,
     968  READ_CMD,
     969  SORTVEC_CMD,
     970  STRING_CMD,
     971  SYSTEM_CMD,
     972  TYPEOF_CMD,
     973  VECTOR_CMD,
     974  VAR_CMD,
     975  VARSTR_CMD,
     976  WEIGHT_CMD,
     977  '(',
     978  COEF_CMD,
     979  DELETE_CMD,
     980  FETCH_CMD,
     981  FIND_CMD,
     982  IMAP_CMD,
     983  INSERT_CMD,
     984  SIMPLIFY_CMD,
     985  SRES_CMD,
     986  DBPRINT_CMD,
     987  TEST_CMD,
     988  PROC_CMD,
     989  MSTD_CMD,
     990  RESERVEDNAME_CMD,
     991  WRITE_CMD,
     992  QRING_CMD,
     993  FGLM_CMD,
     994  FGLMQUOT_CMD,
     995  DUMP_CMD,
     996  GETDUMP_CMD,
     997  STATUS_CMD,
     998  LIB_CMD,
     999  PACKAGE_CMD
     1000};
     1001
     1002// struct used for specifying the cmd <-> cop relations
     1003typedef struct cmd_cop
     1004{
     1005  short cmd;
     1006  MP_Common_t cop;
     1007} cmd_op;
     1008
     1009typedef struct cmd_dictcop
     1010{
     1011  MP_DictTag_t  dict;
     1012  cmd_op        cmd_ops[255];
     1013} cmd_dictcop;
     1014
     1015cmd_dictcop cmd_dictcops[] =
     1016{
     1017  {
     1018    MP_PolyDict,
     1019    // This is the list of all tokens which have an MP representation as a
     1020    // cop in the Poly dictionary
     1021    {
     1022      {BETTI_CMD, MP_CopPolyBetti},
     1023      {CHARACTERISTIC_CMD, MP_CopPolyChar},
     1024      {CHAR_SERIES_CMD, MP_CopPolyCharSeries},
     1025      {CONTENT_CMD, MP_CopPolyClearDenom },
     1026      {DEG_CMD, MP_CopPolyDeg},
     1027      {DIM_CMD, MP_CopPolyDim},
     1028      {FAC_CMD, MP_CopPolyFactorize},
     1029      {FACSTD_CMD, MP_CopPolyFacStd},
     1030      {HILBERT_CMD, MP_CopPolyHilb},
     1031      {HOMOG_CMD, MP_CopPolyHomog},
     1032      {INDEPSET_CMD, MP_CopPolyInDepSet},
     1033      {IDEAL_CMD, MP_CopPolyIdeal},
     1034      {KBASE_CMD, MP_CopPolyKbase},
     1035      {LEAD_CMD, MP_CopPolyLead},
     1036      {LEADCOEF_CMD, MP_CopPolyLeadCoef},
     1037      {LEADEXP_CMD, MP_CopPolyLeadExp},
     1038      {MAXID_CMD, MP_CopPolyMaxIdeal},
     1039      {MINBASE_CMD, MP_CopPolyMinBase},
     1040      {MINRES_CMD, MP_CopPolyMinRes},
     1041      {MODUL_CMD, MP_CopPolyModule},
     1042      {MULTIPLICITY_CMD, MP_CopPolyMultiplicity},
     1043      {ORD_CMD, MP_CopPolyOrder},
     1044      {PRUNE_CMD, MP_CopPolyPrune},
     1045      {QHWEIGHT_CMD, MP_CopPolyQHWeight},
     1046      {REGULARITY_CMD, MP_CopPolyRegularity},
     1047      {RESULTANT_CMD, MP_CopPolyResultant},
     1048      {STD_CMD, MP_CopPolyStd},
     1049      {SYZYGY_CMD, MP_CopPolySyz},
     1050      {VDIM_CMD, MP_CopPolyVdim},
     1051      {COEFFS_CMD,  MP_CopPolyCoeffs},
     1052      {CONTRACT_CMD, MP_CopPolyContract},
     1053      {ELIMINATION_CMD, MP_CopPolyEliminate},
     1054      {JET_CMD, MP_CopPolyJet},
     1055      {LIFT_CMD, MP_CopPolyLift},
     1056      {LIFTSTD_CMD, MP_CopPolyLiftstd},
     1057      {MODULO_CMD, MP_CopPolyModulo},
     1058      {MRES_CMD, MP_CopPolyMres},
     1059      {QUOTIENT_CMD, MP_CopPolyQuotient},
     1060      {REDUCE_CMD, MP_CopPolyReduce},
     1061      {PREIMAGE_CMD, MP_CopPolyPreimage},
     1062      {RES_CMD, MP_CopPolyRes},
     1063      {RING_CMD, MP_CopPolyRing},
     1064      {MAX_TOK, 0}
     1065    }
     1066  },
     1067  {
     1068    MP_NumberDict,
     1069    // This is the list of all tokens which have an MP representation as a
     1070    // cop in the Number dictionary
     1071    {
     1072      {PRIME_CMD, MP_CopNumberPrime},
     1073      {EXTGCD_CMD, MP_CopNumberExtGcd},
     1074      {GCD_CMD, MP_CopNumberGcd},
     1075      {RANDOM_CMD, MP_CopNumberRandom},
     1076      {MAX_TOK, 0}
     1077    }
     1078  },
     1079  {
     1080    MP_MatrixDict,
     1081    // This is the list of all tokens which have an MP representation as a
     1082    // cop in the Matrix dictionary
     1083    {
     1084      {BAREISS_CMD, MP_CopMatrixBareiss},
     1085      {COLS_CMD, MP_CopMatrixCols},
     1086      {DET_CMD, MP_CopMatrixDet},
     1087      {JACOB_CMD, MP_CopMatrixJacobi},
     1088      {MATRIX_CMD, MP_CopMatrixDenseMatrix},
     1089      {ROWS_CMD, MP_CopMatrixRows},
     1090      {TRACE_CMD, MP_CopMatrixTrace},
     1091      {TRANSPOSE_CMD, MP_CopMatrixTranspose},
     1092      {KOSZUL_CMD, MP_CopMatrixKoszul},
     1093      {MINOR_CMD, MP_CopMatrixMinor},
     1094      {WEDGE_CMD, MP_CopMatrixWedge},
     1095      {MAX_TOK, 0}
     1096    }
     1097  },
     1098  {
     1099    MP_BasicDict,
     1100    // This is the list of all tokens which have an MP representation as a
     1101    // cop in the MP Basic dictionary
     1102    {
     1103      {PLUSPLUS, MP_CopBasicInc},
     1104      {MINUSMINUS,  MP_CopBasicDec},
     1105      {COUNT_CMD, MP_CopBasicSize},
     1106      {LIST_CMD, MP_CopBasicList},
     1107      {'+', MP_CopBasicAdd},
     1108      {'-', MP_CopBasicMinus},
     1109      {'*', MP_CopBasicMult},
     1110      {'/', MP_CopBasicDiv},
     1111      {'%', MP_CopBasicMod},
     1112      {'^', MP_CopBasicPow},
     1113      {GE, MP_CopBasicGreaterEqual},
     1114      {'<', MP_CopBasicGreater},
     1115      {LE, MP_CopBasicLessEqual},
     1116      {'>', MP_CopBasicLess},
     1117      {'&', MP_CopBasicAnd},
     1118      {'|', MP_CopBasicOr},
     1119      {'=', MP_CopBasicAssign},
     1120      {EQUAL_EQUAL, MP_CopBasicEqual},
     1121      {NOTEQUAL, MP_CopBasicNotEqual},
     1122      {DOTDOT, MP_CopBasicRange},
     1123      {'[', MP_CopBasicIndex},
     1124      {DIFF_CMD, MP_CopBasicDiff},
     1125      {INTERSECT_CMD, MP_CopBasicInterSect},
     1126      {SUBST_CMD, MP_CopBasicSubst},
     1127      {NOT, MP_CopBasicNot},
     1128      {COLONCOLON, MP_CopBasicPackage},
     1129      {MAX_TOK, 0}
     1130    }
     1131  }
     1132};
     1133
     1134
     1135// Given a Singular token, find matching (dict,op): Return 1 if one is
     1136// found, 0, otherwise
     1137static short GetMPDictTok(short tok, MP_DictTag_t *dict, MP_Common_t *cop)
     1138{
     1139  short i, l, j;
     1140  cmd_op *cmd_ops;
     1141
     1142  // first, look through Singular specific commands
     1143  l = sizeof(sr_cmds)/sizeof(short);
     1144  if (l > MAX_COP)
     1145  {
     1146    fprintf(stderr,
     1147            "Error: There are more than 256 entries in MP_SingularDict\n");
     1148    exit(1);
     1149  }
     1150  for (i=0; i<l; i++)
     1151    if (sr_cmds[i] == tok)
     1152    {
     1153      *dict = MP_SingularDict;
     1154      *cop = i;
     1155      return 1;
     1156    }
     1157
     1158  // look through all the other dicts
     1159  for (j=0; j<MAX_SR_DICT-1; j++)
     1160  {
     1161    cmd_ops = cmd_dictcops[j].cmd_ops;
     1162    for (i=0; (cmd_ops[i]).cmd != MAX_TOK; i++)
     1163    {
     1164      if (i > MAX_COP)
     1165      {
     1166        fprintf(stderr,
     1167                "Error: There are more than 256 entries in dict %d's\n",j);
     1168        exit(1);
     1169      }
     1170      if (cmd_ops[i].cmd == tok)
     1171      {
     1172        *dict = cmd_dictcops[j].dict;
     1173        *cop = cmd_ops[i].cop;
     1174        return 1;
     1175      }
     1176    }
     1177  }
     1178  return 0;
     1179}
     1180
     1181
     1182// This actually generates the tables of mpsr_tok.inc
     1183char *mpsr_Tok_inc;
     1184void mpsr_ttGen()
     1185{
     1186  mpsr_cmd mpsrcmds[MAX_TOK];
     1187  short tok2mp[MAX_TOK];
     1188  short mp2tok[MAX_SR_DICT][MAX_COP];
     1189  short max_cmd = 0, i, j;
     1190  MP_Common_t cop;
     1191  FILE *outfile;
     1192  MP_DictTag_t dict;
     1193
     1194
     1195  // init all arrays
     1196  for (i=0; i<MAX_TOK; i++)
     1197  {
     1198    mpsrcmds[i].tok = MAX_TOK;
     1199    tok2mp[i] = MAX_TOK;
     1200  }
     1201  for (i=0; i<MAX_SR_DICT; i++)
     1202    for (j=0; j<MAX_COP; j++)
     1203      mp2tok[i][j] = MAX_TOK;
     1204
     1205  // Now go through all the token and test them
     1206  for (i=0; i<MAX_TOK; i++)
     1207  {
     1208    if (IsCmdToken(i))
     1209    {
     1210      if (GetMPDictTok(i, &dict, &cop))
     1211      {
     1212        mpsrcmds[max_cmd].tok = i;
     1213        mpsrcmds[max_cmd].dict = dict;
     1214        mpsrcmds[max_cmd].cop = cop;
     1215        tok2mp[i] = max_cmd;
     1216        mp2tok[mpdict2srdict(dict)][cop] = i;
     1217        max_cmd++;
     1218      }
     1219     //else
     1220     //{
     1221     //  fprintf(stderr, "Warning: mpsr_ttGen: Unknown Cmd Token: %d(%s)\n",
     1222     //                  i, iiTwoOps(i));
     1223     // }
     1224    }
     1225  }
     1226
     1227  // Generate the template file
     1228  mpsr_Tok_inc=strdup("mpsr_Tok.xxxxxxxx");
     1229  int pid=getpid();
     1230  mpsr_Tok_inc[8]=(pid %10)+'0'; pid/=10;
     1231  mpsr_Tok_inc[9]=(pid %10)+'0'; pid/=10;
     1232  mpsr_Tok_inc[10]=(pid %10)+'0'; pid/=10;
     1233  mpsr_Tok_inc[11]=(pid %10)+'0'; pid/=10;
     1234  mpsr_Tok_inc[12]=(pid %10)+'0'; pid/=10;
     1235  mpsr_Tok_inc[13]=(pid %10)+'0';
     1236
     1237  outfile = myfopen(mpsr_Tok_inc, "w");
     1238  if (outfile == NULL)
     1239  {
     1240    fprintf(stderr, "Error: mpsr_ttGen: Cannot open file mpsr_Tok.inc\n");
     1241    exit(1);
     1242  }
     1243
     1244  // header
     1245  fprintf(outfile,
     1246   "/***************************************************************\n"
     1247   "*\n"
     1248   "* File:       mpsr_tok.inc\n"
     1249   "* Purpose:    tables for mapping Singular cmds to/from MP (dict, op)\n"
     1250   "*\n"
     1251   "* THIS FILE WAS AUTOMATICALLY GENERATED BY mpsr_ttGen(). DO NOT EDIT!\n"
     1252   "*\n"
     1253   "***************************************************************/\n"
     1254   "#ifndef MPSR_STRING_TABLES\n"
     1255   "mpsr_cmd mpsr_cmds[] =\n"
     1256   "{\n"
     1257   "  { %d,\t %d,\t %d }", mpsrcmds[0].tok, mpsrcmds[0].dict, mpsrcmds[0].cop);
     1258
     1259  // mpsrcmds
     1260  for (i=1; i<max_cmd; i++)
     1261  {
     1262    fprintf(outfile, ",\n  { %d,\t %d,\t %d }",
     1263            mpsrcmds[i].tok, mpsrcmds[i].dict, mpsrcmds[i].cop);
     1264  }
     1265  fprintf(outfile,"\n};\n\n");
     1266
     1267  // tok2mp
     1268  fprintf(outfile, "short tok2mp[] = { %d", tok2mp[0]);
     1269  for (i=1; i<MAX_TOK; i++)
     1270    fprintf(outfile, ", %d", tok2mp[i]);
     1271  fprintf(outfile, "};\n\n");
     1272
     1273  // mp2tok
     1274  fprintf(outfile, "short mp2tok[MAX_SR_DICT][MAX_COP] = \n{");
     1275  for (i=0; i<MAX_SR_DICT; i++)
     1276  {
     1277    fprintf(outfile, "\n{\n");
     1278    for (j=0; j<MAX_COP; j++)
     1279    {
     1280      fprintf(outfile, " %d",mp2tok[i][j]);
     1281      if  (j!=MAX_COP-1) fprintf(outfile, ",");
     1282    }
     1283    if (i!=MAX_SR_DICT-1) fprintf(outfile, "},");
     1284    else                  fprintf(outfile, "}");
     1285  }
     1286  fprintf(outfile,"\n};\n\n");
     1287
     1288  fprintf(outfile, "#else /* MPSR_STRING_TABLE */\n"
     1289    "mpsr_cmd mpsr_cmds[] =\n"
     1290    "{\n"
     1291    "{ \"%s\",\t %d,\t %d }",
     1292    iiTwoOps(mpsrcmds[0].tok), mpsrcmds[0].dict, mpsrcmds[0].cop);
     1293
     1294  for (i=1; i<max_cmd; i++)
     1295  {
     1296    fprintf(outfile, ",\n  { \"%s\",\t %d,\t %d }",
     1297            iiTwoOps(mpsrcmds[i].tok), mpsrcmds[i].dict, mpsrcmds[i].cop);
     1298  }
     1299  fprintf(outfile, ",\n { NULL, \t 0, \t 0}");
     1300  fprintf(outfile,"\n};\n\n#endif /* ! MPSR_STRING_TABLE */");
     1301
     1302  fclose(outfile);
     1303} // That's all
     1304
     1305#else
     1306void mpsr_ttGen()
     1307{
     1308  system("touch mpsr_Tok.xx");
     1309}
     1310#endif
     1311
    8881312int main()
    8891313{
    890   //mpsr_ttGen();
     1314  mpsr_ttGen();
    8911315  ttGen4();
    8921316  ttGen1();
Note: See TracChangeset for help on using the changeset viewer.