source: git/Singular/mpsr_Tok.cc @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[f6b5f0]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4
[32df82]5
[0e1846]6/***************************************************************
7 *
8 * File:       mpsr_Tok.cc
9 * Purpose:    Routines which realize Singular CMD <-> MP (dict, cop) mappings
10 *             (and ordering mappings)
11 * Author:     Olaf Bachmann (1/97)
12 *
13 * Change History (most recent first):
14 *
15 ***************************************************************/
16
[53f204]17#include <sys/types.h>
18#include <unistd.h>
19
[762407]20#include "config.h"
[b1dfaf]21#include <kernel/mod2.h>
[0e1846]22
23#ifdef HAVE_MPSR
24
[b1dfaf]25#include <kernel/febase.h>
26#include <tok.h>
[0e1846]27
[599326]28#include <Singular/mpsr.h>
29#include <Singular/mpsr_Tok.h>
[0e1846]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)
36typedef struct mpsr_cmd
37{
[979a09f]38
[0e1846]39  short         tok;    // The Singular token encoding
40
41  // The MP Dict tag in which this token is defined,
[979a09f]42  MP_DictTag_t  dict;
[0e1846]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
52inline 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
67mpsr_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
[6b32990]78    return mpsr_UnknownSingularToken;
[0e1846]79}
80
81mpsr_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)
[6b32990]87    return mpsr_UnknownDictionary;
[0e1846]88
89  tok = mp2tok[sr_dict][cop];
90  if (tok == MAX_TOK)
[6b32990]91    return mpsr_UnkownOperator;
[0e1846]92
93  *o_tok = tok;
94  return mpsr_Success;
95}
96
97
98#define MAX_ORD ringorder_unspec
[4a8d95]99
[a9a7be]100static struct
[4a8d95]101{
102  int sing_ord;
103  int mp_ord;
104} sing_mp_ord[] =
[0e1846]105{
[4a8d95]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}
[0e1846]122};
[a9a7be]123
[0e1846]124MP_Common_t mpsr_ord2mp(int sr_ord)
125{
[15a5b5d]126  int i = ringorder_no;
[a9a7be]127
[15a5b5d]128  while (sing_mp_ord[i].sing_ord != sr_ord &&
129         sing_mp_ord[i].sing_ord <= ringorder_unspec) i++;
[a9a7be]130
[15a5b5d]131  return sing_mp_ord[i].mp_ord;
[0e1846]132}
133
134short mpsr_mp2ord(MP_Common_t mp_ord)
135{
[50cbdc]136  int ord = ringorder_no;
[a9a7be]137
[50cbdc]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;
[0e1846]141}
[979a09f]142
[0e1846]143#endif // HAVE_MPSR
Note: See TracBrowser for help on using the repository browser.