1 | #include "Singular/libsingular.h" |
---|
2 | #include "kernel/combinatorics/stairc.h" |
---|
3 | #include <vector> |
---|
4 | |
---|
5 | #if !defined(__CYGWIN__) || defined(STATIC_VERSION) |
---|
6 | // acces from a module to routines from the main program |
---|
7 | // does not work on windows (restrict of the dynamic linker), |
---|
8 | // a static version is required: |
---|
9 | // ./configure --with-builtinmodules=freealgebra,... |
---|
10 | |
---|
11 | #ifdef HAVE_SHIFTBBA |
---|
12 | static BOOLEAN freeAlgebra(leftv res, leftv args) |
---|
13 | { |
---|
14 | const short t1[]={2,RING_CMD,INT_CMD}; |
---|
15 | const short t2[]={3,RING_CMD,INT_CMD,INT_CMD}; |
---|
16 | if (iiCheckTypes(args, t2, 0) || iiCheckTypes(args, t1, 1)) |
---|
17 | { |
---|
18 | ring r=(ring)args->Data(); |
---|
19 | int d=(int)(long)args->next->Data(); |
---|
20 | if (d<2) |
---|
21 | { |
---|
22 | WerrorS("degree must be >=2"); |
---|
23 | return TRUE; |
---|
24 | } |
---|
25 | int i=0; |
---|
26 | while(r->order[i]!=0) |
---|
27 | { |
---|
28 | if ((r->order[i]==ringorder_c) ||(r->order[i]==ringorder_C)) i++; |
---|
29 | else if ((r->block0[i]==1)&&(r->block1[i]==r->N)) i++; |
---|
30 | else |
---|
31 | { |
---|
32 | WerrorS("only for rings with a global ordering of one block"); |
---|
33 | return TRUE; |
---|
34 | } |
---|
35 | } |
---|
36 | if ((r->order[i]!=0) |
---|
37 | || (rHasLocalOrMixedOrdering(r))) |
---|
38 | { |
---|
39 | WerrorS("only for rings with a global ordering of one block"); |
---|
40 | //Werror("only for rings with a global ordering of one block,i=%d, o=%d",i,r->order[i]); |
---|
41 | return TRUE; |
---|
42 | } |
---|
43 | int ncGenCount = 0; |
---|
44 | if (iiCheckTypes(args,t2,0)) |
---|
45 | ncGenCount = (int)(long) args->next->next->Data(); |
---|
46 | ring R=freeAlgebra(r,d,ncGenCount); |
---|
47 | res->rtyp=RING_CMD; |
---|
48 | res->data=R; |
---|
49 | return R==NULL; |
---|
50 | } |
---|
51 | return TRUE; |
---|
52 | } |
---|
53 | |
---|
54 | static BOOLEAN stest(leftv res, leftv args) |
---|
55 | { |
---|
56 | const short t[]={2,POLY_CMD,INT_CMD}; |
---|
57 | if (iiCheckTypes(args,t,1)) |
---|
58 | { |
---|
59 | poly p=(poly)args->CopyD(); |
---|
60 | args=args->next; |
---|
61 | int sh=(int)((long)(args->Data())); |
---|
62 | if (sh<0) |
---|
63 | { |
---|
64 | WerrorS("negative shift for pLPshift"); |
---|
65 | return TRUE; |
---|
66 | } |
---|
67 | int L = pLastVblock(p); |
---|
68 | if (L+sh > currRing->N/currRing->isLPring) |
---|
69 | { |
---|
70 | WerrorS("pLPshift: too big shift requested\n"); |
---|
71 | return TRUE; |
---|
72 | } |
---|
73 | p_LPshift(p,sh,currRing); |
---|
74 | res->data = p; |
---|
75 | res->rtyp = POLY_CMD; |
---|
76 | return FALSE; |
---|
77 | } |
---|
78 | else return TRUE; |
---|
79 | } |
---|
80 | |
---|
81 | static BOOLEAN btest(leftv res, leftv h) |
---|
82 | { |
---|
83 | const short t[]={1,POLY_CMD}; |
---|
84 | if (iiCheckTypes(h,t,1)) |
---|
85 | { |
---|
86 | poly p=(poly)h->Data(); |
---|
87 | res->rtyp = INT_CMD; |
---|
88 | res->data = (void*)(long)pLastVblock(p); |
---|
89 | return FALSE; |
---|
90 | } |
---|
91 | else return TRUE; |
---|
92 | } |
---|
93 | |
---|
94 | static BOOLEAN lpLmDivides(leftv res, leftv h) |
---|
95 | { |
---|
96 | const short t1[]={2,POLY_CMD,POLY_CMD}; |
---|
97 | const short t2[]={2,IDEAL_CMD,POLY_CMD}; |
---|
98 | if (iiCheckTypes(h,t1,0)) |
---|
99 | { |
---|
100 | poly p=(poly)h->Data(); |
---|
101 | poly q=(poly)h->next->Data(); |
---|
102 | res->rtyp = INT_CMD; |
---|
103 | res->data = (void*)(long)p_LPDivisibleBy(p, q, currRing); |
---|
104 | return FALSE; |
---|
105 | } |
---|
106 | else if (iiCheckTypes(h,t2,1)) |
---|
107 | { |
---|
108 | ideal I=(ideal)h->Data(); |
---|
109 | poly q=(poly)h->next->Data(); |
---|
110 | res->rtyp = INT_CMD; |
---|
111 | res->data=(void*)(long) p_LPDivisibleBy(I, q, currRing); |
---|
112 | return FALSE; |
---|
113 | } |
---|
114 | else return TRUE; |
---|
115 | } |
---|
116 | |
---|
117 | static BOOLEAN lpVarAt(leftv res, leftv h) |
---|
118 | { |
---|
119 | const short t[]={2,POLY_CMD,INT_CMD}; |
---|
120 | if (iiCheckTypes(h,t,1)) |
---|
121 | { |
---|
122 | poly p=(poly)h->Data(); |
---|
123 | int pos=(int)((long)(h->next->Data())); |
---|
124 | res->rtyp = POLY_CMD; |
---|
125 | res->data = p_LPVarAt(p, pos, currRing); |
---|
126 | return FALSE; |
---|
127 | } |
---|
128 | else return TRUE; |
---|
129 | } |
---|
130 | |
---|
131 | static BOOLEAN lpUfnarovskiGraph(leftv res, leftv h) |
---|
132 | { |
---|
133 | const short t[]={1,IDEAL_CMD}; |
---|
134 | if (iiCheckTypes(h,t,1)) |
---|
135 | { |
---|
136 | ideal I = (ideal) h->Data(); |
---|
137 | res->rtyp = LIST_CMD; |
---|
138 | |
---|
139 | ideal standardWords; |
---|
140 | intvec* graph = lp_ufnarovskiGraph(I, standardWords); |
---|
141 | |
---|
142 | lists li=(lists)omAllocBin(slists_bin); |
---|
143 | li->Init(2); |
---|
144 | li->m[0].rtyp=INTMAT_CMD; |
---|
145 | li->m[1].rtyp=IDEAL_CMD; |
---|
146 | li->m[0].data=graph; |
---|
147 | li->m[1].data=standardWords; |
---|
148 | |
---|
149 | res->data = li; |
---|
150 | |
---|
151 | if (errorreported) return TRUE; |
---|
152 | return FALSE; |
---|
153 | } |
---|
154 | else return TRUE; |
---|
155 | } |
---|
156 | #endif |
---|
157 | |
---|
158 | //------------------------------------------------------------------------ |
---|
159 | // initialisation of the module |
---|
160 | extern "C" int SI_MOD_INIT(freealgebra)(SModulFunctions* p) |
---|
161 | { |
---|
162 | #ifdef HAVE_SHIFTBBA |
---|
163 | p->iiAddCproc("freealgebra.so","freeAlgebra",FALSE,freeAlgebra); |
---|
164 | p->iiAddCproc("freealgebra.so","lpLmDivides",FALSE,lpLmDivides); |
---|
165 | p->iiAddCproc("freealgebra.so","lpVarAt",FALSE,lpVarAt); |
---|
166 | p->iiAddCproc("freealgebra.so","lpUfnarovskiGraph",FALSE,lpUfnarovskiGraph); |
---|
167 | |
---|
168 | p->iiAddCproc("freealgebra.so","stest",TRUE,stest); |
---|
169 | p->iiAddCproc("freealgebra.so","btest",TRUE,btest); |
---|
170 | #endif |
---|
171 | return (MAX_TOK); |
---|
172 | } |
---|
173 | #endif |
---|