source: git/Singular/lists.cc @ 6ae4f5

spielwiese
Last change on this file since 6ae4f5 was 6ae4f5, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: - corrected scanner.l: parsing of strings in blocks: if (1) { write("","}"); } - corrected ipassign.cc: assignment of "dummy" types: DEF, NONE - corrected sleftv::Print(_), initialisation of _ - added conversion int->def - added CopyD(DEF) - in insert(..): object should not be of type NONE (lists.cc:lInsert0) - added int*intvec, int*intmat to iparith.cc git-svn-id: file:///usr/local/Singular/svn/trunk@145 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: lists.cc,v 1.4 1997-04-09 12:19:55 Singular Exp $ */
5/*
6* ABSTRACT: handling of the list type
7*/
8#include "mod2.h"
9#include "tok.h"
10#include "febase.h"
11#include "ipid.h"
12#include "polys.h"
13#include "ideals.h"
14#include "attrib.h"
15#include "lists.h"
16
17lists lCopy(lists L)
18{
19  lists N=(lists)Alloc0(sizeof(slists));
20  int n=L->nr;
21  if (L->nr>=0)
22    N->Init(n+1);
23  else
24    N->Init();
25  for(;n>=0;n--)
26  {
27    N->m[n].Copy(&L->m[n]);
28  }
29  //Print("copy list with %d -> %d elems\n",L->nr,N->nr);
30  return N;
31}
32
33/*2
34* concat 2 lists
35*/
36BOOLEAN lAdd(leftv res, leftv u, leftv v)
37{
38  lists l=(lists) Alloc(sizeof(slists));
39  lists ul=(lists)u->CopyD();
40  lists vl=(lists)v->CopyD();
41  l->Init(ul->nr+vl->nr+2);
42  int i;
43
44  for(i=0;i<=ul->nr;i++)
45  {
46    //Print("u[%d]->r[%d]\n",i,i);
47    l->m[i].rtyp=ul->m[i].rtyp;
48    l->m[i].data=ul->m[i].data;
49  }
50  for(i=0;i<=vl->nr;i++)
51  {
52    //Print("v[%d]->r[%d]\n",i,i+ul->nr+1);
53    l->m[i+ul->nr+1].rtyp=vl->m[i].rtyp;
54    l->m[i+ul->nr+1].data=vl->m[i].data;
55  }
56  Free((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
57  Free((ADDRESS)ul,sizeof(slists));
58  Free((ADDRESS)vl->m,(vl->nr+1)*sizeof(sleftv));
59  Free((ADDRESS)vl,sizeof(slists));
60  memset(u,0,sizeof(*u));
61  memset(v,0,sizeof(*v));
62  res->data = (char *)l;
63  //res->Print();
64  return FALSE;
65}
66
67/*2
68* insert v into list u, destroys u
69*/
70lists lInsert0(lists ul, leftv v, int pos)
71{
72  if ((pos<0)||(v->rtyp==NONE))
73    return NULL;
74  lists l=(lists) Alloc(sizeof(slists));
75  l->Init(max(ul->nr+2,pos+1));
76  int i,j;
77
78  for(i=j=0;i<=ul->nr;i++,j++)
79  {
80    if(j==pos) j++;
81    l->m[j].Copy(&ul->m[i]);
82  }
83  for(j=ul->nr+1;j<pos;j++)
84    l->m[j].rtyp=DEF_CMD;
85  memset(&(l->m[pos]),0,sizeof(sleftv));
86  l->m[pos].rtyp=v->Typ();
87  l->m[pos].data=v->CopyD();
88  l->m[pos].flag=v->flag;
89  l->m[pos].attribute=v->CopyA();
90  Free((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
91  Free((ADDRESS)ul,sizeof(slists));
92  return l;
93}
94
95/*2
96* insert v into list u, at the beginning
97*/
98BOOLEAN lInsert(leftv res, leftv u, leftv v)
99{
100  lists ul=(lists)u->CopyD();
101  res->data=(char *)lInsert0(ul,v,0);
102  return (res->data==NULL);
103}
104
105/*2
106* insert v into list u at pos w
107*/
108BOOLEAN lInsert3(leftv res, leftv u, leftv v, leftv w)
109{
110  lists ul=(lists)u->CopyD();
111  res->data=(char *)lInsert0(ul,v,(int)w->Data());
112  return (res->data==NULL);
113}
114
115/*2
116* append v to list u
117*/
118BOOLEAN lAppend(leftv res, leftv u, leftv v)
119{
120  lists ul=(lists)u->CopyD();
121  res->data=(char *)lInsert0(ul,v,ul->nr+1);
122  return (res->data==NULL);
123}
124
125/*2
126* delete v-th element from list u
127*/
128BOOLEAN lDelete(leftv res, leftv u, leftv v)
129{
130  lists ul=(lists)u->Data();
131  int VIndex=(int)v->Data()-1;
132
133  if((0<=VIndex)&&(VIndex<=ul->nr))
134  {
135    int i,j;
136    lists l=(lists) Alloc(sizeof(slists));
137    l->Init(ul->nr);
138
139    ul=(lists)u->CopyD();
140    for(i=j=0;i<=ul->nr;i++,j++)
141    {
142      if (i!=VIndex)
143      {
144        l->m[j].Copy(&(ul->m[i]));
145      }
146      else
147      {
148        j--;
149        ul->m[i].CleanUp();
150      }
151    }
152    Free((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
153    Free((ADDRESS)ul,sizeof(slists));
154    res->data = (char *)l;
155    return FALSE;
156  }
157  Werror("wrong index %d in list(%d)",VIndex+1,ul->nr+1);
158  return TRUE;
159}
160
161/*2
162* check, if a list contains any ring dependend data
163*/
164BOOLEAN lRingDependend(lists L)
165{
166  if (L==NULL) return TRUE;
167  int i=0;
168  while (i<=L->nr)
169  {
170    if ((L->m[i].rtyp!=QRING_CMD)
171    && (BEGIN_RING<L->m[i].rtyp)
172    && (L->m[i].rtyp<END_RING))
173      return TRUE;
174    if ((L->m[i].rtyp==LIST_CMD)&&lRingDependend((lists)L->m[i].data))
175      return TRUE;
176    i++;
177  }
178  return FALSE;
179}
180
181lists liMakeResolv(resolvente r, int length, int reallen,
182  int typ0, intvec ** weights)
183{
184  lists L=(lists)Alloc0(sizeof(slists));
185  int oldlength=length;
186  while (r[length-1]==NULL) length--;
187  if (reallen<=0) reallen=pVariables;
188  reallen=max(reallen,length);
189  L->Init(reallen);
190  int i=0;
191
192  while (i<length)
193  {
194    if (r[i]!=NULL)
195    {
196      if (i==0)
197      {
198        L->m[i].rtyp=typ0;
199      }
200      else
201      {
202        L->m[i].rtyp=MODUL_CMD;
203        int rank=IDELEMS(r[i-1]);
204        if (idIs0(r[i-1]))
205        {
206          idDelete(&(r[i]));
207          r[i]=idFreeModule(rank);
208        }
209        else
210        {
211          r[i]->rank=max(rank,idRankFreeModule(r[i]));
212        }
213        idSkipZeroes(r[i]);
214      }
215      L->m[i].data=(void *)r[i];
216      if ((weights!=NULL) && (weights[i]!=NULL))
217      {
218        atSet((idhdl)&L->m[i],mstrdup("isHomog"),weights[i],INTVEC_CMD);
219        weights[i] = NULL;
220      }
221    }
222    else
223    {
224      // should not happen:
225      Warn("internal NULL in resolvente");
226      L->m[i].data=(void *)idInit(1,1);
227    }
228    i++;
229  }
230  Free((ADDRESS)r,oldlength*sizeof(ideal));
231  if (i==0)
232  {
233    L->m[0].rtyp=typ0;
234    L->m[0].data=(char *)idInit(1,1);
235    i=1;
236  }
237  while (i<reallen)
238  {
239    L->m[i].rtyp=MODUL_CMD;
240    ideal I=(ideal)L->m[i-1].data;
241    ideal J;
242    int rank=IDELEMS(I);
243    if (idIs0(I))
244    {
245      J=idFreeModule(rank);
246    }
247    else
248    {
249      J=idInit(1,rank);
250    }
251    L->m[i].data=(void *)J;
252    i++;
253  }
254  //Print("make res of length %d (0..%d) L:%d\n",length,length-1,L->nr);
255  return L;
256}
257
258resolvente liFindRes(lists L, int * len, int *typ0)
259{
260  resolvente r;
261
262  *len=L->nr+1;
263  if (*len<=0)
264  {
265    WerrorS("empty list");
266    return NULL;
267  }
268  r=(ideal *)Alloc0((*len)*sizeof(ideal));
269  int i=0;
270  *typ0=MODUL_CMD;
271  while (i<(*len))
272  {
273    if (L->m[i].rtyp != MODUL_CMD)
274    {
275      if (L->m[i].rtyp!=IDEAL_CMD)
276      {
277        Werror("element %d is not of type module",i+1);
278        Free((ADDRESS)r,(*len)*sizeof(ideal));
279        return NULL;
280      }
281      *typ0=IDEAL_CMD;
282    }
283    if ((i>0) && (idIs0(r[i-1])))
284    {
285      //*len=i-1;
286      break;
287    }
288    r[i]=(ideal)L->m[i].data;
289    i++;
290  }
291  //Print("find res of length %d (0..%d) L:%d\n",*len,(*len)-1,L->nr);
292  return r;
293}
294
Note: See TracBrowser for help on using the repository browser.