My Project
Loading...
Searching...
No Matches
lists.h File Reference
#include "omalloc/omalloc.h"
#include "kernel/structs.h"
#include "kernel/ideals.h"
#include "Singular/subexpr.h"
#include "Singular/tok.h"

Go to the source code of this file.

Data Structures

class  slists

Macros

#define INLINE_THIS

Typedefs

typedef slistslists

Functions

int lSize (lists L)
lists lCopy (lists L)
lists lInsert0 (lists ul, leftv v, int pos)
BOOLEAN lInsert (leftv res, leftv u, leftv v)
BOOLEAN lInsert3 (leftv res, leftv u, leftv v, leftv w)
BOOLEAN lAppend (leftv res, leftv u, leftv v)
BOOLEAN lDelete (leftv res, leftv u, leftv v)
BOOLEAN lDeleteIV (leftv res, leftv u, leftv v)
BOOLEAN lAdd (leftv res, leftv u, leftv v)
BOOLEAN lRingDependend (lists L)
char * lString (lists l, BOOLEAN typed=FALSE, int dim=1)
lists liMakeResolv (resolvente r, int length, int reallen, int typ0, intvec **weights, int add_row_shift)
resolvente liFindRes (lists L, int *len, int *typ0, intvec ***weights=NULL)

Variables

EXTERN_VAR omBin slists_bin

Macro Definition Documentation

◆ INLINE_THIS

#define INLINE_THIS

Definition at line 17 of file lists.h.

Typedef Documentation

◆ lists

typedef slists* lists

Definition at line 49 of file lists.h.

Function Documentation

◆ lAdd()

BOOLEAN lAdd ( leftv res,
leftv u,
leftv v )

Definition at line 51 of file lists.cc.

52{
54 lists ul=(lists)u->CopyD();
55 lists vl=(lists)v->CopyD();
56 l->Init(ul->nr+vl->nr+2);
57 int i;
58
59 for(i=0;i<=ul->nr;i++)
60 {
61 //Print("u[%d]->r[%d]\n",i,i);
62 l->m[i].rtyp=ul->m[i].rtyp;
63 l->m[i].data=ul->m[i].data;
64 }
65 for(i=0;i<=vl->nr;i++)
66 {
67 //Print("v[%d]->r[%d]\n",i,i+ul->nr+1);
68 l->m[i+ul->nr+1].rtyp=vl->m[i].rtyp;
69 l->m[i+ul->nr+1].data=vl->m[i].data;
70 }
71 if (ul->m != NULL)
72 omFreeSize((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
74 if (vl->m != NULL)
75 omFreeSize((ADDRESS)vl->m,(vl->nr+1)*sizeof(sleftv));
77 memset(u,0,sizeof(*u));
78 memset(v,0,sizeof(*v));
79 res->data = (char *)l;
80 //res->Print();
81 return FALSE;
82}
#define FALSE
Definition auxiliary.h:97
void * ADDRESS
Definition auxiliary.h:120
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
Class used for (list of) interpreter objects.
Definition subexpr.h:83
void * CopyD(int t)
Definition subexpr.cc:714
int rtyp
Definition subexpr.h:91
void * data
Definition subexpr.h:88
sleftv * m
Definition lists.h:46
int nr
Definition lists.h:44
CanonicalForm res
Definition facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
VAR omBin slists_bin
Definition lists.cc:23
slists * lists
#define omFreeSize(addr, size)
#define omAllocBin(bin)
#define omFreeBin(addr, bin)
#define NULL
Definition omList.c:12

◆ lAppend()

BOOLEAN lAppend ( leftv res,
leftv u,
leftv v )

Definition at line 151 of file lists.cc.

152{
153 lists ul=(lists)u->CopyD();
154 res->data=(char *)lInsert0(ul,v,ul->nr+1);
155 return (res->data==NULL);
156}
lists lInsert0(lists ul, leftv v, int pos)
Definition lists.cc:87

◆ lCopy()

lists lCopy ( lists L)

Definition at line 32 of file lists.cc.

33{
35 int n=L->nr;
36 if (n>=0)
37 N->Init(n+1);
38 else
39 N->Init();
40 for(;n>=0;n--)
41 {
42 N->m[n].Copy(&L->m[n]);
43 }
44 //Print("copy list with %d -> %d elems\n",L->nr,N->nr);
45 return N;
46}
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
#define omAlloc0Bin(bin)

◆ lDelete()

BOOLEAN lDelete ( leftv res,
leftv u,
leftv v )

Definition at line 161 of file lists.cc.

162{
163 lists ul=(lists)u->Data();
164 int VIndex=(int)(long)v->Data()-1;
165 int EndIndex=lSize(ul);
166
167 if((0<=VIndex)&&(VIndex<=ul->nr))
168 {
169 ul=(lists)u->CopyD();
170 int i;
172 l->Init(EndIndex+(VIndex>EndIndex));
173
174 ul->m[VIndex].CleanUp();
175 for(i=0;i<VIndex;i++)
176 {
177 l->m[i]=ul->m[i];
178 }
179 for(i=VIndex+1;i<=ul->nr;i++)
180 {
181 l->m[i-1]=ul->m[i];
182 }
183 omFreeSize((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
185 res->data = (char *)l;
186 return FALSE;
187 }
188 Werror("wrong index %d in list(%d)",VIndex+1,ul->nr+1);
189 return TRUE;
190}
#define TRUE
Definition auxiliary.h:101
void * Data()
Definition subexpr.cc:1192
void CleanUp(ring r=currRing)
Definition subexpr.cc:351
int lSize(lists L)
Definition lists.cc:25
void Werror(const char *fmt,...)
Definition reporter.cc:189

◆ lDeleteIV()

BOOLEAN lDeleteIV ( leftv res,
leftv u,
leftv v )

Definition at line 192 of file lists.cc.

193{
194 lists ul=(lists)u->CopyD();
195 intvec* vl=(intvec*)v->Data();
196 int i,j,cnt;
197 cnt=0;
198 for(i=vl->length()-1;i>=0;i--)
199 {
200 j=(*vl)[i];
201 if ((j>0)&&(j<=ul->nr))
202 {
203 cnt++;
204 ul->m[j-1].CleanUp();
205 memcpy(&(ul->m[j-1]),&(ul->m[j]),(ul->nr-j+1)*sizeof(sleftv));
206 ul->m[ul->nr].rtyp=DEF_CMD;
207 ul->m[ul->nr].data=NULL;
208 }
209 }
210 if ((cnt*2>=ul->nr)||(cnt*sizeof(sleftv)>=1024))
211 {
212 ul->m=(leftv)omReallocSize(ul->m,(ul->nr+1)*sizeof(sleftv),(ul->nr-cnt+1)*sizeof(sleftv));
213 ul->nr -= cnt;
214 }
215 res->data = (char *)ul;
216 return FALSE;
217}
int length() const
Definition intvec.h:95
int j
Definition facHensel.cc:110
#define omReallocSize(addr, o_size, size)
sleftv * leftv
Definition structs.h:53
@ DEF_CMD
Definition tok.h:58

◆ liFindRes()

resolvente liFindRes ( lists L,
int * len,
int * typ0,
intvec *** weights = NULL )

Definition at line 344 of file lists.cc.

345{
346 resolvente r;
347 intvec ** w=NULL,*tw=NULL;
348
349 *len=L->nr+1;
350 if (*len<=0)
351 {
352 WerrorS("empty list");
353 return NULL;
354 }
355 r=(ideal *)omAlloc0((*len)*sizeof(ideal));
356 w=(intvec**)omAlloc0((*len)*sizeof(intvec*));
357 int i=0;
358 *typ0=MODUL_CMD;
359 while (i<(*len))
360 {
361 if (L->m[i].rtyp != MODUL_CMD)
362 {
363 if (L->m[i].rtyp!=IDEAL_CMD)
364 {
365 Werror("element %d is not of type module",i+1);
366 omFreeSize((ADDRESS)r,(*len)*sizeof(ideal));
367 return NULL;
368 }
369 *typ0=IDEAL_CMD;
370 }
371 if ((i>0) && (idIs0(r[i-1])))
372 {
373 //*len=i-1;
374 break;
375 }
376 r[i]=(ideal)L->m[i].data;
377 tw=(intvec*)atGet(&(L->m[i]),"isHomog",INTVEC_CMD);
378 if (tw!=NULL)
379 {
380 w[i]=ivCopy(tw);
381 }
382 tw = NULL;
383 i++;
384 }
385 BOOLEAN hom_complex=TRUE;
386 int j=0;
387 while ((j<i) && hom_complex)
388 {
389 hom_complex = hom_complex && (w[j]!=NULL);
390 j++;
391 }
392 if ((!hom_complex) || (weights==NULL))
393 {
394 for (j=0;j<i;j++)
395 {
396 if (w[j]!=NULL) delete w[j];
397 }
398 omFreeSize((ADDRESS)w,(*len)*sizeof(intvec*));
399 if (weights!=NULL) *weights=NULL;
400 }
401 else
402 {
403 *weights = w;
404 }
405 //Print("find res of length %d (0..%d) L:%d\n",*len,(*len)-1,L->nr);
406 return r;
407}
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition attrib.cc:132
int BOOLEAN
Definition auxiliary.h:88
const CanonicalForm & w
Definition facAbsFact.cc:51
void WerrorS(const char *s)
Definition feFopen.cc:24
@ IDEAL_CMD
Definition grammar.cc:285
@ MODUL_CMD
Definition grammar.cc:288
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
ideal * resolvente
Definition ideals.h:18
intvec * ivCopy(const intvec *o)
Definition intvec.h:146
#define omAlloc0(size)
@ INTVEC_CMD
Definition tok.h:101

◆ liMakeResolv()

lists liMakeResolv ( resolvente r,
int length,
int reallen,
int typ0,
intvec ** weights,
int add_row_shift )

Definition at line 239 of file lists.cc.

241{
242 // re-uses r, weights[i]
244 if (length<0)
245 {
246 // handle "empty" resolutions
247 L->Init(0);
248 }
249 else if (length==0)
250 {
251 L->Init(1);
252 L->m[0].rtyp=typ0;
253 L->m[0].data=(void*)idInit(1,1);
254 }
255 else
256 {
257 int oldlength=length;
258 while (r[length-1]==NULL) length--;
259 if (reallen<=0) reallen=currRing->N;
260 reallen=si_max(reallen,length);
261 L->Init(reallen);
262 int i=0;
263
264 while (i<length)
265 {
266 if (r[i]!=NULL)
267 {
268 if (i==0)
269 {
270 L->m[i].rtyp=typ0;
271 int j=IDELEMS(r[0])-1;
272 while ((j>0) && (r[0]->m[j]==NULL)) j--;
273 j++;
274 if (j!=IDELEMS(r[0]))
275 {
276 pEnlargeSet(&(r[0]->m),IDELEMS(r[0]),j-IDELEMS(r[0]));
277 IDELEMS(r[0])=j;
278 }
279 }
280 else
281 {
282 L->m[i].rtyp=MODUL_CMD;
283 int rank=IDELEMS(r[i-1]);
284 if (idIs0(r[i-1]))
285 {
286 idDelete(&(r[i]));
287 r[i]=id_FreeModule(rank, currRing);
288 }
289 else
290 {
291 r[i]->rank=si_max(rank,(int)id_RankFreeModule(r[i], currRing));
292 }
293 idSkipZeroes(r[i]);
294 }
295 L->m[i].data=(void *)r[i];
296 if ((weights!=NULL) && (weights[i]!=NULL))
297 {
298 intvec *w=weights[i];
299 (*w) += add_row_shift;
300 atSet((idhdl)&L->m[i],omStrDup("isHomog"),w,INTVEC_CMD);
301 weights[i] = NULL;
302 }
303 }
304 #ifdef TEST
305 else
306 {
307 // should not happen:
308 WarnS("internal NULL in resolvente");
309 L->m[i].data=(void *)idInit(1,1);
310 }
311 #endif
312 i++;
313 }
314 omFreeSize((ADDRESS)r,oldlength*sizeof(ideal));
315 if (weights!=NULL) omFreeSize(weights,oldlength*sizeof(intvec*));
316 if (i==0)
317 {
318 L->m[0].rtyp=typ0;
319 L->m[0].data=(char *)idInit(1,1);
320 i=1;
321 }
322 while (i<reallen)
323 {
324 L->m[i].rtyp=MODUL_CMD;
325 ideal I=(ideal)L->m[i-1].data;
326 ideal J;
327 int rank=IDELEMS(I);
328 if (idIs0(I))
329 {
330 J=idFreeModule(rank);
331 }
332 else
333 {
334 J=idInit(1,rank);
335 }
336 L->m[i].data=(void *)J;
337 i++;
338 }
339 //Print("make res of length %d (0..%d) L:%d\n",length,length-1,L->nr);
340 }
341 return L;
342}
void atSet(idhdl root, char *name, void *data, int typ)
Definition attrib.cc:153
static int si_max(const int a, const int b)
Definition auxiliary.h:125
int m
Definition cfEzgcd.cc:128
INLINE_THIS void Init(int l=0)
#define WarnS
Definition emacs.cc:78
#define idDelete(H)
delete an ideal
Definition ideals.h:29
ideal idFreeModule(int i)
Definition ideals.h:111
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
#define omStrDup(s)
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3821
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
idrec * idhdl
Definition ring.h:22
ideal idInit(int idsize, int rank)
initialise an ideal / module
ideal id_FreeModule(int i, const ring r)
the free module of rank i
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)

◆ lInsert()

BOOLEAN lInsert ( leftv res,
leftv u,
leftv v )

Definition at line 120 of file lists.cc.

121{
122 lists ul=(lists)u->CopyD();
123 res->data=(char *)lInsert0(ul,v,0);
124 if (res->data==NULL)
125 {
126 Werror("cannot insert type `%s`",Tok2Cmdname(v->Typ()));
127 return TRUE;
128 }
129 return FALSE;
130}
const char * Tok2Cmdname(int tok)
Definition gentable.cc:137

◆ lInsert0()

lists lInsert0 ( lists ul,
leftv v,
int pos )

Definition at line 87 of file lists.cc.

88{
89 if ((pos<0)||(v->rtyp==NONE))
90 return NULL;
92 l->Init(si_max(ul->nr+2,pos+1));
93 int i,j;
94
95 for(i=j=0;i<=ul->nr;i++,j++)
96 {
97 if(j==pos) j++;
98 l->m[j]=ul->m[i];
99 }
100 for(j=ul->nr+1;j<pos;j++)
101 l->m[j].rtyp=DEF_CMD;
102 // memset(&(l->m[pos]),0,sizeof(sleftv)); - done by Init
103 l->m[pos].rtyp=v->Typ();
104 l->m[pos].data=v->CopyD();
105 l->m[pos].flag=v->flag;
106 attr *a=v->Attribute();
107 if ((a!=NULL)&&(*a!=NULL))
108 {
109 l->m[pos].attribute=(*a)->Copy();
110 }
111 if (ul->m != NULL)
112 omFreeSize((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
114 return l;
115}
sattr * attr
Definition attrib.h:16
#define NONE
Definition tok.h:223

◆ lInsert3()

BOOLEAN lInsert3 ( leftv res,
leftv u,
leftv v,
leftv w )

Definition at line 135 of file lists.cc.

136{
137 lists ul=(lists)u->CopyD();
138 res->data=(char *)lInsert0(ul,v,(int)(long)w->Data());
139 if (res->data==NULL)
140 {
141 Werror("cannot insert type `%s` at pos. %d",
142 Tok2Cmdname(v->Typ()),(int)(long)w->Data());
143 return TRUE;
144 }
145 return FALSE;
146}

◆ lRingDependend()

BOOLEAN lRingDependend ( lists L)

Definition at line 222 of file lists.cc.

223{
224 if (L==NULL) return FALSE;
225 int i=L->nr;
226 while (i>=0)
227 {
228 REGISTER int t=L->m[i].rtyp;
229 if ((BEGIN_RING<t /*L->m[i].rtyp*/)
230 && (/*L->m[i].rtyp*/ t<END_RING))
231 return TRUE;
232 if ((/*L->m[i].rtyp*/ t==LIST_CMD)&&lRingDependend((lists)L->m[i].data))
233 return TRUE;
234 i--;
235 }
236 return FALSE;
237}
@ END_RING
Definition grammar.cc:311
@ BEGIN_RING
Definition grammar.cc:283
BOOLEAN lRingDependend(lists L)
Definition lists.cc:222
#define REGISTER
Definition omalloc.h:27
@ LIST_CMD
Definition tok.h:118

◆ lSize()

int lSize ( lists L)

Definition at line 25 of file lists.cc.

26{
27 int n=L->nr;
28 while ((n>=0)&&((L->m[n].rtyp==DEF_CMD)||(L->m[n].rtyp==0))) n--;
29 return n;
30}

◆ lString()

char * lString ( lists l,
BOOLEAN typed = FALSE,
int dim = 1 )

Definition at line 409 of file lists.cc.

410{
411 if (l->nr == -1)
412 {
413 if (typed) return omStrDup("list()");
414 return omStrDup("");
415 }
416
417 char** slist = (char**) omAlloc((l->nr+1) * sizeof(char*));
418 int i, j, k;
419 char *s;
420 for (i=0, j = 0, k = 0; i<=l->nr; i++)
421 {
422 slist[i] = l->m[i].String(NULL, typed, dim);
423 assume(slist[i] != NULL);
424 omCheckAddr(slist[i]);
425 if (*(slist[i]) != '\0')
426 {
427 j += strlen(slist[i]);
428 k++;
429 }
430 }
431 size_t len=j+k+2+(typed ? 10 : 0) + (dim == 2 ? k : 0);
432 s = (char*) omAlloc(len);
433
434 if (typed)
435 snprintf(s, len,"list(");
436 else
437 *s = '\0';
438
439 for (i=0; i<=l->nr; i++)
440 {
441 if (*(slist[i]) != '\0')
442 {
443 strcat(s, slist[i]);
444 strcat(s, ",");
445 if (dim == 2) strcat(s, "\n");
446 }
447 omCheckAddr(s);
448 omFree(slist[i]);
449 }
450 if (k > 0) s[strlen(s) - (dim == 2 ? 2 : 1)] = '\0';
451 if (typed) strcat(s, ")");
452 omCheckAddr(s);
453 omFreeSize(slist, (l->nr+1) * sizeof(char*));
454 return s;
455}
int k
Definition cfEzgcd.cc:99
const CanonicalForm int s
Definition facAbsFact.cc:51
#define assume(x)
Definition mod2.h:389
#define omCheckAddr(addr)
#define omAlloc(size)
#define omFree(addr)
int dim(ideal I, ring r)

Variable Documentation

◆ slists_bin

EXTERN_VAR omBin slists_bin

Definition at line 22 of file lists.h.