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 <kernel/mod2.h> |
---|
22 | |
---|
23 | #ifdef HAVE_MPSR |
---|
24 | |
---|
25 | #include <kernel/febase.h> |
---|
26 | #include <tok.h> |
---|
27 | |
---|
28 | #include <Singular/mpsr.h> |
---|
29 | #include <Singular/mpsr_Tok.h> |
---|
30 | |
---|
31 | |
---|
32 | #define MAX_COP 256 // there may be at most 256 cops |
---|
33 | |
---|
34 | // this is the main data struct for storing the relation |
---|
35 | // Singular token <-> (Dict, OP) |
---|
36 | typedef struct mpsr_cmd |
---|
37 | { |
---|
38 | |
---|
39 | short tok; // The Singular token encoding |
---|
40 | |
---|
41 | // The MP Dict tag in which this token is defined, |
---|
42 | MP_DictTag_t dict; |
---|
43 | |
---|
44 | // The MP operator corresponding to this token |
---|
45 | MP_Common_t cop; // operator |
---|
46 | } mpsr_cmd; |
---|
47 | |
---|
48 | #define MAX_SR_DICT 5 |
---|
49 | |
---|
50 | // this provides a mapping from MP dict tags to more useful (small) |
---|
51 | // array indicies |
---|
52 | inline short mpdict2srdict(MP_DictTag_t dict) |
---|
53 | { |
---|
54 | if (dict == MP_SingularDict) return 0; |
---|
55 | else if (dict == MP_BasicDict) return 1; |
---|
56 | else if (dict == MP_PolyDict) return 2; |
---|
57 | else if (dict == MP_MatrixDict) return 3; |
---|
58 | else if (dict == MP_NumberDict) return 4; |
---|
59 | else return MAX_SR_DICT; |
---|
60 | } |
---|
61 | |
---|
62 | // Here are the actual definition of these token tables |
---|
63 | #include"mpsr_Tok.inc" |
---|
64 | |
---|
65 | |
---|
66 | // And here are the main routines which provide the mappings |
---|
67 | mpsr_Status_t mpsr_tok2mp(short tok, MP_DictTag_t *dict, MP_Common_t *cop) |
---|
68 | { |
---|
69 | short tok_index = tok2mp[tok]; |
---|
70 | |
---|
71 | if (tok_index != MAX_TOK) |
---|
72 | { |
---|
73 | *dict = mpsr_cmds[tok_index].dict; |
---|
74 | *cop = mpsr_cmds[tok_index].cop; |
---|
75 | return mpsr_Success; |
---|
76 | } |
---|
77 | else |
---|
78 | return mpsr_UnknownSingularToken; |
---|
79 | } |
---|
80 | |
---|
81 | mpsr_Status_t mpsr_mp2tok(MP_DictTag_t dict, MP_Common_t cop, short *o_tok) |
---|
82 | { |
---|
83 | short sr_dict = mpdict2srdict(dict); |
---|
84 | short tok; |
---|
85 | |
---|
86 | if (sr_dict == MAX_SR_DICT) |
---|
87 | return mpsr_UnknownDictionary; |
---|
88 | |
---|
89 | tok = mp2tok[sr_dict][cop]; |
---|
90 | if (tok == MAX_TOK) |
---|
91 | return mpsr_UnkownOperator; |
---|
92 | |
---|
93 | *o_tok = tok; |
---|
94 | return mpsr_Success; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | #define MAX_ORD ringorder_unspec |
---|
99 | |
---|
100 | static struct |
---|
101 | { |
---|
102 | int sing_ord; |
---|
103 | int mp_ord; |
---|
104 | } sing_mp_ord[] = |
---|
105 | { |
---|
106 | {ringorder_no, MP_CcPolyOrdering_Unknown}, |
---|
107 | {ringorder_a, MP_CcPolyOrdering_Vector}, |
---|
108 | {ringorder_c, MP_CcPolyOrdering_IncComp}, |
---|
109 | {ringorder_C, MP_CcPolyOrdering_DecComp}, |
---|
110 | {ringorder_M, MP_CcPolyOrdering_Matrix}, |
---|
111 | {ringorder_lp, MP_CcPolyOrdering_Lex}, |
---|
112 | {ringorder_dp, MP_CcPolyOrdering_DegRevLex}, |
---|
113 | {ringorder_Dp, MP_CcPolyOrdering_DegLex}, |
---|
114 | {ringorder_wp, MP_CcPolyOrdering_RevLex}, |
---|
115 | {ringorder_Wp, MP_CcPolyOrdering_Lex}, |
---|
116 | {ringorder_ls, MP_CcPolyOrdering_NegLex}, |
---|
117 | {ringorder_ds, MP_CcPolyOrdering_NegDegRevLex}, |
---|
118 | {ringorder_Ds, MP_CcPolyOrdering_NegDegLex}, |
---|
119 | {ringorder_ws, MP_CcPolyOrdering_NegRevLex}, |
---|
120 | {ringorder_Ws, MP_CcPolyOrdering_NegLex}, |
---|
121 | {ringorder_unspec, MP_CcPolyOrdering_Unknown} |
---|
122 | }; |
---|
123 | |
---|
124 | MP_Common_t mpsr_ord2mp(int sr_ord) |
---|
125 | { |
---|
126 | int i = ringorder_no; |
---|
127 | |
---|
128 | while (sing_mp_ord[i].sing_ord != sr_ord && |
---|
129 | sing_mp_ord[i].sing_ord <= ringorder_unspec) i++; |
---|
130 | |
---|
131 | return sing_mp_ord[i].mp_ord; |
---|
132 | } |
---|
133 | |
---|
134 | short mpsr_mp2ord(MP_Common_t mp_ord) |
---|
135 | { |
---|
136 | int ord = ringorder_no; |
---|
137 | |
---|
138 | while (sing_mp_ord[ord].mp_ord != mp_ord && |
---|
139 | sing_mp_ord[ord].sing_ord <= ringorder_unspec) ord++; |
---|
140 | return sing_mp_ord[ord].sing_ord; |
---|
141 | } |
---|
142 | |
---|
143 | #endif // HAVE_MPSR |
---|