source: git/Singular/mpsr_Tok.cc @ 0df59c8

spielwiese
Last change on this file since 0df59c8 was 762407, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
config.h is for sources files only FIX: config.h should only be used by source (not from inside kernel/mod2.h!) NOTE: each source file should better include mod2.h right after config.h, while headers should better not include mod2.h.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4
5/* $Id$ */
6
7/***************************************************************
8 *
9 * File:       mpsr_Tok.cc
10 * Purpose:    Routines which realize Singular CMD <-> MP (dict, cop) mappings
11 *             (and ordering mappings)
12 * Author:     Olaf Bachmann (1/97)
13 *
14 * Change History (most recent first):
15 *
16 ***************************************************************/
17
18#include <sys/types.h>
19#include <unistd.h>
20
21#include "config.h"
22#include <kernel/mod2.h>
23
24#ifdef HAVE_MPSR
25
26#include <kernel/febase.h>
27#include <tok.h>
28
29#include <Singular/mpsr.h>
30#include <Singular/mpsr_Tok.h>
31
32
33#define MAX_COP 256 // there may be at most 256 cops
34
35// this is the main data struct for storing the relation
36// Singular token <-> (Dict, OP)
37typedef struct mpsr_cmd
38{
39
40  short         tok;    // The Singular token encoding
41
42  // The MP Dict tag in which this token is defined,
43  MP_DictTag_t  dict;
44
45  // The MP operator corresponding to this token
46  MP_Common_t   cop; // operator
47} mpsr_cmd;
48
49#define MAX_SR_DICT     5
50
51// this provides a mapping from MP dict tags to more useful (small)
52// array indicies
53inline short mpdict2srdict(MP_DictTag_t dict)
54{
55  if (dict == MP_SingularDict) return 0;
56  else if (dict == MP_BasicDict) return 1;
57  else if (dict == MP_PolyDict) return 2;
58  else if (dict == MP_MatrixDict) return 3;
59  else if (dict == MP_NumberDict) return 4;
60  else return MAX_SR_DICT;
61}
62
63// Here are the actual definition of these token tables
64#include"mpsr_Tok.inc"
65
66
67// And here are the main routines which provide the mappings
68mpsr_Status_t mpsr_tok2mp(short tok, MP_DictTag_t *dict, MP_Common_t *cop)
69{
70  short tok_index = tok2mp[tok];
71
72  if (tok_index != MAX_TOK)
73  {
74    *dict = mpsr_cmds[tok_index].dict;
75    *cop = mpsr_cmds[tok_index].cop;
76    return mpsr_Success;
77  }
78  else
79    return mpsr_UnknownSingularToken;
80}
81
82mpsr_Status_t mpsr_mp2tok(MP_DictTag_t dict, MP_Common_t cop, short *o_tok)
83{
84  short sr_dict = mpdict2srdict(dict);
85  short tok;
86
87  if (sr_dict == MAX_SR_DICT)
88    return mpsr_UnknownDictionary;
89
90  tok = mp2tok[sr_dict][cop];
91  if (tok == MAX_TOK)
92    return mpsr_UnkownOperator;
93
94  *o_tok = tok;
95  return mpsr_Success;
96}
97
98
99#define MAX_ORD ringorder_unspec
100
101static struct
102{
103  int sing_ord;
104  int mp_ord;
105} sing_mp_ord[] =
106{
107  {ringorder_no,    MP_CcPolyOrdering_Unknown},
108  {ringorder_a,     MP_CcPolyOrdering_Vector},
109  {ringorder_c,     MP_CcPolyOrdering_IncComp},
110  {ringorder_C,     MP_CcPolyOrdering_DecComp},
111  {ringorder_M,     MP_CcPolyOrdering_Matrix},
112  {ringorder_lp,    MP_CcPolyOrdering_Lex},
113  {ringorder_dp,    MP_CcPolyOrdering_DegRevLex},
114  {ringorder_Dp,    MP_CcPolyOrdering_DegLex},
115  {ringorder_wp,    MP_CcPolyOrdering_RevLex},
116  {ringorder_Wp,    MP_CcPolyOrdering_Lex},
117  {ringorder_ls,    MP_CcPolyOrdering_NegLex},
118  {ringorder_ds,    MP_CcPolyOrdering_NegDegRevLex},
119  {ringorder_Ds,    MP_CcPolyOrdering_NegDegLex},
120  {ringorder_ws,    MP_CcPolyOrdering_NegRevLex},
121  {ringorder_Ws,    MP_CcPolyOrdering_NegLex},
122  {ringorder_unspec, MP_CcPolyOrdering_Unknown}
123};
124
125MP_Common_t mpsr_ord2mp(int sr_ord)
126{
127  int i = ringorder_no;
128
129  while (sing_mp_ord[i].sing_ord != sr_ord &&
130         sing_mp_ord[i].sing_ord <= ringorder_unspec) i++;
131
132  return sing_mp_ord[i].mp_ord;
133}
134
135short mpsr_mp2ord(MP_Common_t mp_ord)
136{
137  int ord = ringorder_no;
138
139  while (sing_mp_ord[ord].mp_ord != mp_ord &&
140         sing_mp_ord[ord].sing_ord <= ringorder_unspec) ord++;
141  return sing_mp_ord[ord].sing_ord;
142}
143
144#endif // HAVE_MPSR
Note: See TracBrowser for help on using the repository browser.