source: git/Singular/ipshell.cc @ 706c95

fieker-DuValspielwiese
Last change on this file since 706c95 was 2eeb7d, checked in by Hans Schönemann <hannes@…>, 25 years ago
*hannes: minor optimizations git-svn-id: file:///usr/local/Singular/svn/trunk@3266 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 25.4 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: ipshell.cc,v 1.44 1999-07-13 16:24:44 Singular Exp $ */
5/*
6* ABSTRACT:
7*/
8
9//#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12#include <ctype.h>
13
14#include "mod2.h"
15#include "tok.h"
16#include "ipid.h"
17#include "intvec.h"
18#include "mmemory.h"
19#include "febase.h"
20#include "polys.h"
21#include "ideals.h"
22#include "matpol.h"
23#include "kstd1.h"
24#include "ring.h"
25#include "subexpr.h"
26#include "maps.h"
27#include "syz.h"
28#include "numbers.h"
29#include "lists.h"
30#include "attrib.h"
31#include "ipconv.h"
32#include "silink.h"
33#include "stairc.h"
34#include "ipshell.h"
35#ifdef HAVE_FACTORY
36#define SI_DONT_HAVE_GLOBAL_VARS
37#include <factory.h>
38#endif
39
40leftv iiCurrArgs=NULL;
41int  traceit = 0;
42char *lastreserved=NULL;
43
44int  myynest = -1;
45
46static BOOLEAN iiNoKeepRing=TRUE;
47
48/*0 implementation*/
49
50char * Tok2Cmdname(int tok)
51{
52  int i = 0;
53  if (tok < 0)
54  {
55    return cmds[0].name;
56  }
57  if (tok==ANY_TYPE) return "any_type";
58  if (tok==NONE) return "nothing";
59  //if (tok==IFBREAK) return "if_break";
60  //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys";
61  //if (tok==ORDER_VECTOR) return "ordering";
62  //if (tok==REF_VAR) return "ref";
63  //if (tok==OBJECT) return "object";
64  //if (tok==PRINT_EXPR) return "print_expr";
65  if (tok==IDHDL) return "identifier";
66  while (cmds[i].tokval!=0)
67  {
68    if ((cmds[i].tokval == tok)&&(cmds[i].alias==0))
69    {
70      return cmds[i].name;
71    }
72    i++;
73  }
74  return cmds[0].name;
75}
76
77char * iiTwoOps(int t)
78{
79  if (t<127)
80  {
81    static char ch[2];
82    switch (t)
83    {
84      case '&':
85        return "and";
86      case '|':
87        return "or";
88      default:
89        ch[0]=t;
90        ch[1]='\0';
91        return ch;
92    }
93  }
94  switch (t)
95  {
96    case COLONCOLON:  return "::";
97    case DOTDOT:      return "..";
98    //case PLUSEQUAL:   return "+=";
99    //case MINUSEQUAL:  return "-=";
100    case MINUSMINUS:  return "--";
101    case PLUSPLUS:    return "++";
102    case EQUAL_EQUAL: return "==";
103    case LE:          return "<=";
104    case GE:          return ">=";
105    case NOTEQUAL:    return "<>";
106    default:          return Tok2Cmdname(t);
107  }
108}
109
110static void list1(char* s, idhdl h,BOOLEAN c, BOOLEAN fullname)
111{
112  char buffer[22];
113  int l;
114  char buf2[128];
115
116  if(fullname) sprintf(buf2, "%s::%s", "", IDID(h));
117  else sprintf(buf2, "%s", IDID(h));
118
119  Print("%s%-20.20s [%d]  ",s,buf2,IDLEV(h));
120  if (h == currRingHdl) PrintS("*");
121  PrintS(Tok2Cmdname((int)IDTYP(h)));
122
123  ipListFlag(h);
124  switch(IDTYP(h))
125  {
126    case INT_CMD:   Print(" %d",IDINT(h)); break;
127    case INTVEC_CMD:Print(" (%d)",IDINTVEC(h)->length()); break;
128    case INTMAT_CMD:Print(" %d x %d",IDINTVEC(h)->rows(),IDINTVEC(h)->cols());
129                    break;
130    case POLY_CMD:
131    case VECTOR_CMD:if (c)
132                    {
133                      PrintS(" ");wrp(IDPOLY(h));
134                      if(IDPOLY(h) != NULL)
135                      {
136                        Print(", %d monomial(s)",pLength(IDPOLY(h)));
137                      }
138                    }
139                    break;
140    case MODUL_CMD: Print(", rk %d", IDIDEAL(h)->rank);
141    case IDEAL_CMD: Print(", %u generator(s)",
142                    IDELEMS(IDIDEAL(h)),IDIDEAL(h)->rank); break;
143    case MAP_CMD:
144                    Print(" from %s",IDMAP(h)->preimage); break;
145    case MATRIX_CMD:Print(" %u x %u"
146                      ,MATROWS(IDMATRIX(h))
147                      ,MATCOLS(IDMATRIX(h))
148                    );
149                    break;
150    case PACKAGE_CMD:
151                    PrintS(" (");
152                    switch (IDPACKAGE(h)->language)
153                    {
154                        case LANG_SINGULAR: PrintS("S"); break;
155                        case LANG_C:        PrintS("C"); break;
156                        case LANG_TOP:      PrintS("T"); break;
157                        case LANG_NONE:     PrintS("N"); break;
158                        default:            PrintS("U");
159                    }
160                    if(IDPACKAGE(h)->libname!=NULL)
161                      Print(",%s", IDPACKAGE(h)->libname);
162                    PrintS(")");
163                    break;
164    case PROC_CMD: if(strlen(IDPROC(h)->libname)>0)
165                     Print(" from %s",IDPROC(h)->libname);
166                   if(IDPROC(h)->is_static)
167                     PrintS(" (static)");
168                   break;
169    case STRING_CMD:
170                   {
171                     char *s;
172                     l=strlen(IDSTRING(h));
173                     memset(buffer,0,22);
174                     strncpy(buffer,IDSTRING(h),min(l,20));
175                     if ((s=strchr(buffer,'\n'))!=NULL)
176                     {
177                       *s='\0';
178                     }
179                     PrintS(" ");
180                     PrintS(buffer);
181                     if((s!=NULL) ||(l>20))
182                     {
183                       Print("..., %d char(s)",l);
184                     }
185                     break;
186                   }
187    case LIST_CMD: Print(", size: %d",IDLIST(h)->nr+1);
188                   break;
189    case QRING_CMD:
190    case RING_CMD:
191#ifdef RDEBUG
192                   if (traceit &TRACE_SHOW_RINGS)
193                     Print(" <%d>",IDRING(h)->no);
194#endif
195                   break;
196    /*default:     break;*/
197  }
198  PrintLn();
199}
200
201void type_cmd(idhdl h)
202{
203  int saveShortOut=pShortOut;
204  pShortOut=1;
205  list1("// ",h,FALSE,FALSE);
206  if (IDTYP(h)!=INT_CMD)
207  {
208    sleftv expr;
209    memset(&expr,0,sizeof(expr));
210    expr.rtyp=IDHDL;
211    expr.name=IDID(h);
212    expr.data=(void *)h;
213    expr.Print();
214  }
215  pShortOut=saveShortOut;
216}
217
218static void killlocals0(int v, idhdl * localhdl)
219{
220  idhdl h = *localhdl;
221  while (h!=NULL)
222  {
223    int vv;
224    //Print("consider %s, lev: %d:",IDID(h),IDLEV(h));
225    if ((vv=IDLEV(h))>0)
226    {
227      if (vv < v)
228      {
229        if (iiNoKeepRing)
230        {
231          //PrintS(" break\n");
232          return;
233        }
234        h = IDNEXT(h);
235        //PrintLn();
236      }
237      else if (vv >= v)
238      {
239        idhdl nexth = IDNEXT(h);
240        killhdl(h,localhdl);
241        h = nexth;
242        //PrintS("kill\n");
243      }
244    }
245    else
246    {
247      h = IDNEXT(h);
248      //PrintLn();
249    }
250  }
251}
252
253void killlocals(int v)
254{
255#ifndef HAVE_NAMESPACES
256  killlocals0(v,&IDROOT);
257
258  idhdl h = IDROOT;
259  idhdl sh=currRingHdl;
260  BOOLEAN changed=FALSE;
261
262  while (h!=NULL)
263  {
264    if (((IDTYP(h)==QRING_CMD) || (IDTYP(h) == RING_CMD))
265    && (IDRING(h)->idroot!=NULL))
266    {
267      if (h!=currRingHdl) {changed=TRUE;rSetHdl(h,FALSE);}
268      killlocals0(v,&(IDRING(h)->idroot));
269    }
270    h = IDNEXT(h);
271  }
272#else
273  killlocals0(v,&IDROOT);
274
275  idhdl h = NSROOT(namespaceroot->root);
276  idhdl sh=currRingHdl;
277  BOOLEAN changed=FALSE;
278
279  while (h!=NULL)
280  {
281    if (((IDTYP(h)==QRING_CMD) || (IDTYP(h) == RING_CMD))
282    && (IDRING(h)->idroot!=NULL))
283    {
284      //Print("=====> Toplevel: ring %s, lev: %d:\n",IDID(h),IDLEV(h));
285      if (h!=currRingHdl) {changed=TRUE;rSetHdl(h,FALSE);}
286      killlocals0(v,&(IDRING(h)->idroot));
287    }
288    if (IDTYP(h)==PACKAGE_CMD && (IDPACKAGE(h)->idroot!=NULL))
289    {
290      idhdl h0 = (IDPACKAGE(h))->idroot;
291
292      //Print("=====> package: %s, lev: %d:\n",IDID(h),IDLEV(h));
293      while (h0!=NULL)
294      {
295        if (((IDTYP(h0)==QRING_CMD) || (IDTYP(h0) == RING_CMD))
296            && (IDRING(h0)->idroot!=NULL))
297        {
298          //Print("=====> '%s': ring %s, lev: %d:\n",IDID(h),IDID(h0),IDLEV(h0));
299          if (h0!=currRingHdl) {changed=TRUE;rSetHdl(h0,FALSE);}
300          killlocals0(v,&(IDRING(h0)->idroot));
301        }
302        h0 = IDNEXT(h0);
303      }
304      killlocals0(v,&((IDPACKAGE(h))->idroot));
305    }
306    h = IDNEXT(h);
307  }
308#endif /* HAVE_NAMESPACES */
309  if (changed)
310  {
311    currRing=NULL;
312    currRingHdl=NULL;
313    rSetHdl(sh,TRUE);
314  }
315
316  if (myynest<=1) iiNoKeepRing=TRUE;
317}
318
319void list_cmd(int typ, const char* what, char *prefix,BOOLEAN iterate, BOOLEAN fullname)
320{
321  idhdl h,start;
322  BOOLEAN all = typ<0;
323  BOOLEAN really_all=FALSE;
324  BOOLEAN do_packages=FALSE;
325
326  if ( typ == -1 ) do_packages=TRUE;
327  if ( typ==0 )
328  {
329    if (strcmp(what,"all")==0)
330    {
331      really_all=TRUE;
332      h=IDROOT;
333    }
334    else
335    {
336#ifdef HAVE_NAMESPACES
337      idhdl pack;
338      if(strchr(what, ':')!= NULL)
339        iiname2hdl(what, &pack, &h);
340      else h = ggetid(what);
341#else /* HAVE_NAMESPACES */
342      h = ggetid(what);
343#endif /* HAVE_NAMESPACES */
344      if (h!=NULL)
345      {
346        if (iterate) list1(prefix,h,TRUE,fullname);
347        if ((IDTYP(h)==RING_CMD)
348            || (IDTYP(h)==QRING_CMD))
349        {
350          h=IDRING(h)->idroot;
351        }
352        else if((IDTYP(h)==PACKAGE_CMD) || (IDTYP(h)==POINTER_CMD))
353        {
354          //Print("list_cmd:package or pointer\n");
355          if(strcmp(IDID(h), "Top")!=0) h=IDPACKAGE(h)->idroot;
356          else return;
357        }
358        else
359          return;
360      }
361      else
362      {
363        Werror("%s is undefined",what);
364        return;
365      }
366    }
367    all=TRUE;
368  }
369  else if ((typ>BEGIN_RING) && (typ<END_RING))
370  {
371    h = currRing->idroot;
372  }
373  else
374    h = IDROOT;
375  start=h;
376  while (h!=NULL)
377  {
378    if ((all && (IDTYP(h)!=PROC_CMD)) || (typ == IDTYP(h))
379    || ((IDTYP(h)==QRING_CMD) && (typ==RING_CMD)))
380    {
381      list1(prefix,h,start==currRingHdl, fullname);
382      if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD))
383        && (really_all || (all && (h==currRingHdl)))
384        && ((IDLEV(h)==0)||(IDLEV(h)==myynest)))
385      {
386        list_cmd(0,IDID(h),"//      ",FALSE);
387      }
388#ifdef HAVE_NAMESPACES
389      if (IDTYP(h)==PACKAGE_CMD && really_all && strcmp(IDID(h), "Top"))
390      {
391        namespaceroot->push(IDPACKAGE(h), IDID(h));
392        list_cmd(0,IDID(h),"//      ",FALSE);
393        namespaceroot->pop();
394      }
395#endif /* HAVE_NAMESPACES */
396    }
397    h = IDNEXT(h);
398  }
399#ifdef HAVE_NAMESPACES
400  if(!namespaceroot->isroot && do_packages) {
401    namespaceroot->push(namespaceroot->root->pack, "Top", myynest);
402    list_cmd(PACKAGE_CMD,"Top","// ",FALSE, TRUE);
403    namespaceroot->pop();
404  }
405#endif /* HAVE_NAMESPACES */
406}
407
408void test_cmd(int i)
409{
410  int ii=(char)i;
411
412  if (i == (-32))
413  {
414    test = 0;
415  }
416  else
417  {
418    if (i<0)
419    {
420      ii= -i;
421      if (Sy_bit(ii) & kOptions)
422      {
423        Warn("Gerhard, use the option command");
424        test &= ~Sy_bit(ii);
425      }
426      else if (Sy_bit(ii) & validOpts)
427        test &= ~Sy_bit(ii);
428    }
429    else if (i<32)
430    {
431      if (Sy_bit(ii) & kOptions)
432      {
433        Warn("Gerhard, use the option command");
434        test |= Sy_bit(ii);
435      }
436      else if (Sy_bit(ii) & validOpts)
437        test |= Sy_bit(ii);
438    }
439  }
440}
441
442int exprlist_length(leftv v)
443{
444  int rc = 0;
445  while (v!=NULL)
446  {
447    switch (v->Typ())
448    {
449      case INT_CMD:
450      case POLY_CMD:
451      case VECTOR_CMD:
452      case NUMBER_CMD:
453        rc++;
454        break;
455      case INTVEC_CMD:
456      case INTMAT_CMD:
457        rc += ((intvec *)(v->Data()))->length();
458        break;
459      case MATRIX_CMD:
460      case IDEAL_CMD:
461      case MODUL_CMD:
462        {
463          matrix mm = (matrix)(v->Data());
464          rc += mm->rows() * mm->cols();
465        }
466        break;
467      case LIST_CMD:
468        rc+=((lists)v->Data())->nr+1;
469        break;
470      default:
471        rc++;
472    }
473    v = v->next;
474  }
475  return rc;
476}
477
478void iiWriteMatrix(matrix im, const char *n, int dim,int spaces)
479{
480  int i,ii = MATROWS(im)-1;
481  int j,jj = MATCOLS(im)-1;
482  poly *pp = im->m;
483
484  for (i=0; i<=ii; i++)
485  {
486    for (j=0; j<=jj; j++)
487    {
488      if (spaces>0)
489        Print("%-*.*s",spaces,spaces," ");
490      if (dim == 2) Print("%s[%u,%u]=",n,i+1,j+1);
491      else if (dim == 1) Print("%s[%u]=",n,j+1);
492      else if (dim == 0) Print("%s=",n);
493      if ((i<ii)||(j<jj)) pWrite(*pp++);
494      else                pWrite0(*pp);
495    }
496  }
497}
498
499char * iiStringMatrix(matrix im, int dim,char ch)
500{
501  int i,ii = MATROWS(im);
502  int j,jj = MATCOLS(im);
503  poly *pp = im->m;
504  char *s=StringSetS("");
505
506  for (i=0; i<ii; i++)
507  {
508    for (j=0; j<jj; j++)
509    {
510      pString0(*pp++);
511      s=StringAppend("%c",ch);
512      if (dim > 1) s = StringAppendS("\n");
513    }
514  }
515  s[strlen(s)- (dim > 1 ? 2 : 1)]='\0';
516  return s;
517}
518
519int IsPrime(int p)  /* brute force !!!! */
520{
521  int i,j;
522  if      (p == 0) return 0;
523  else if (p == 1) return 1/*1*/;
524  else if (p == 2) return p;
525  else if (p <  0) return (-IsPrime(-p));
526  else if (!(p & 1)) return IsPrime(p-1);
527#ifdef HAVE_FACTORY
528  int a=0;
529  int e=cf_getNumSmallPrimes();
530  i=e/2;
531  do
532  {
533    if (p==(j=cf_getSmallPrime(i))) return p;
534    if (p<j) e=i-1;
535    else     a=i+1;
536    i=a+(e-a)/2;
537  } while ( a<= e);
538  if (p>j) return j;
539  else     return cf_getSmallPrime(i-1);
540#else 
541  for (j=p/2+1,i=3; i<p; i+=2)
542  {
543    if ((p%i) == 0) return IsPrime(p-2);
544    if (j < i) return p;
545  }
546  return p;
547#endif
548}
549
550BOOLEAN iiWRITE(leftv res,leftv v)
551{
552  sleftv vf;
553  if (iiConvert(v->Typ(),LINK_CMD,iiTestConvert(v->Typ(),LINK_CMD),v,&vf))
554  {
555    WerrorS("link expected");
556    return TRUE;
557  }
558  si_link l=(si_link)vf.Data();
559  if (vf.next == NULL)
560  {
561    WerrorS("write: need at least two arguments");
562    return TRUE;
563  }
564
565  BOOLEAN b=slWrite(l,vf.next); /* iiConvert preserves next */
566  if (b)
567  {
568    const char *s;
569    if ((l!=NULL)&&(l->name!=NULL)) s=l->name;
570    else                            s=sNoName;
571    Werror("cannot write to %s",s);
572  }
573  vf.CleanUp();
574  return b;
575}
576
577leftv iiMap(map theMap, char * what)
578{
579  idhdl w,r;
580  leftv v;
581  int i;
582
583#ifdef HAVE_NAMESPACES
584  idhdl pack;
585  //r=namespaceroot->get(theMap->preimage,myynest);
586  iiname2hdl(theMap->preimage,&pack,&r);
587#else
588  r=idroot->get(theMap->preimage,myynest);
589#endif /* HAVE_NAMESPACES */
590  if ((r!=NULL) && ((r->typ == RING_CMD) || (r->typ== QRING_CMD)))
591  {
592    if (!nSetMap(rInternalChar(IDRING(r)),
593                 IDRING(r)->parameter,
594                 rPar(IDRING(r)),
595                 IDRING(r)->minpoly))
596    {
597      Werror("can not map from ground field of %s to current ground field", theMap->preimage);
598      return NULL;
599    }
600    if (IDELEMS(theMap)<IDRING(r)->N)
601    {
602      theMap->m=(polyset)ReAlloc((ADDRESS)theMap->m,
603                                 IDELEMS(theMap)*sizeof(poly),
604                                 (IDRING(r)->N)*sizeof(poly));
605      for(i=IDELEMS(theMap);i<IDRING(r)->N;i++)
606        theMap->m[i]=NULL;
607      IDELEMS(theMap)=IDRING(r)->N;
608    }
609    if (what==NULL)
610    {
611      WerrorS("argument of a map must have a name");
612    }
613    else if ((w=IDRING(r)->idroot->get(what,myynest))!=NULL)
614    {
615      v=(leftv)Alloc0(sizeof(*v));
616      sleftv tmpW;
617      memset(&tmpW,0,sizeof(sleftv));
618      tmpW.rtyp=IDTYP(w);
619      tmpW.data=IDDATA(w);
620      if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,IDRING(r),NULL,NULL,0))
621      {
622        Werror("cannot map %s(%d)",Tok2Cmdname(w->typ),w->typ);
623        Free((ADDRESS)v,sizeof(*v));
624        return NULL;
625      }
626      return v;
627    }
628    else
629    {
630      Werror("%s undefined in %s",what,theMap->preimage);
631    }
632  }
633  else
634  {
635    Werror("cannot find preimage %s",theMap->preimage);
636  }
637  return NULL;
638}
639
640#ifdef OLD_RES
641void  iiMakeResolv(resolvente r, int length, int rlen, char * name, int typ0,
642                   intvec ** weights)
643{
644  lists L=liMakeResolv(r,length,rlen,typ0,weights);
645  int i=0;
646  idhdl h;
647  char * s=(char *)Alloc(strlen(name)+5);
648
649  while (i<=L->nr)
650  {
651    sprintf(s,"%s(%d)",name,i+1);
652    if (i==0)
653      h=enterid(mstrdup(s),myynest,typ0,&(currRing->idroot), FALSE);
654    else
655      h=enterid(mstrdup(s),myynest,MODUL_CMD,&(currRing->idroot), FALSE);
656    if (h!=NULL)
657    {
658      h->data.uideal=(ideal)L->m[i].data;
659      h->attribute=L->m[i].attribute;
660      if (BVERBOSE(V_DEF_RES))
661        Print("//defining: %s as %d-th syzygy module\n",s,i+1);
662    }
663    else
664    {
665      idDelete((ideal *)&(L->m[i].data));
666      Warn("cannot define %s",s);
667    }
668    //L->m[i].data=NULL;
669    //L->m[i].rtyp=0;
670    //L->m[i].attribute=NULL;
671    i++;
672  }
673  Free((ADDRESS)L->m,(L->nr+1)*sizeof(sleftv));
674  Free((ADDRESS)L,sizeof(slists));
675  Free((ADDRESS)s,strlen(name)+5);
676}
677#endif
678
679//resolvente iiFindRes(char * name, int * len, int *typ0)
680//{
681//  char *s=(char *)Alloc(strlen(name)+5);
682//  int i=-1;
683//  resolvente r;
684//  idhdl h;
685//
686//  do
687//  {
688//    i++;
689//    sprintf(s,"%s(%d)",name,i+1);
690//    h=currRing->idroot->get(s,myynest);
691//  } while (h!=NULL);
692//  *len=i-1;
693//  if (*len<=0)
694//  {
695//    Werror("no objects %s(1),.. found",name);
696//    Free((ADDRESS)s,strlen(name)+5);
697//    return NULL;
698//  }
699//  r=(ideal *)Alloc(/*(len+1)*/ i*sizeof(ideal));
700//  memset(r,0,(*len)*sizeof(ideal));
701//  i=-1;
702//  *typ0=MODUL_CMD;
703//  while (i<(*len))
704//  {
705//    i++;
706//    sprintf(s,"%s(%d)",name,i+1);
707//    h=currRing->idroot->get(s,myynest);
708//    if (h->typ != MODUL_CMD)
709//    {
710//      if ((i!=0) || (h->typ!=IDEAL_CMD))
711//      {
712//        Werror("%s is not of type module",s);
713//        Free((ADDRESS)r,(*len)*sizeof(ideal));
714//        Free((ADDRESS)s,strlen(name)+5);
715//        return NULL;
716//      }
717//      *typ0=IDEAL_CMD;
718//    }
719//    if ((i>0) && (idIs0(r[i-1])))
720//    {
721//      *len=i-1;
722//      break;
723//    }
724//    r[i]=IDIDEAL(h);
725//  }
726//  Free((ADDRESS)s,strlen(name)+5);
727//  return r;
728//}
729
730static resolvente iiCopyRes(resolvente r, int l)
731{
732  int i;
733  resolvente res=(ideal *)Alloc0((l+1)*sizeof(ideal));
734
735  for (i=0; i<l; i++)
736    res[i]=idCopy(r[i]);
737  return res;
738}
739
740BOOLEAN jjMINRES(leftv res, leftv v)
741{
742  int len=0;
743  int typ0;
744  resolvente rr=liFindRes((lists)v->Data(),&len,&typ0);
745  if (rr==NULL) return TRUE;
746  resolvente r=iiCopyRes(rr,len);
747
748  syMinimizeResolvente(r,len,0);
749  Free((ADDRESS)rr,len*sizeof(ideal));
750  len++;
751  res->data=(char *)liMakeResolv(r,len,-1,typ0,NULL);
752  return FALSE;
753}
754
755BOOLEAN jjBETTI(leftv res, leftv v)
756{
757  resolvente r;
758  int len;
759  int reg,typ0;
760
761  r=liFindRes((lists)v->Data(),&len,&typ0);
762  if (r==NULL) return TRUE;
763  res->data=(char *)syBetti(r,len,&reg);
764  Free((ADDRESS)r,(len)*sizeof(ideal));
765  return FALSE;
766}
767
768int iiRegularity(lists L)
769{
770  resolvente r;
771  int len,reg,typ0;
772  intvec * dummy;
773
774  r=liFindRes(L,&len,&typ0);
775  if (r==NULL) return -2;
776  dummy=syBetti(r,len,&reg);
777  Free((ADDRESS)r,len*sizeof(ideal));
778  delete dummy;
779  return reg-1;
780}
781
782BOOLEAN iiDebugMarker=TRUE;
783#define BREAK_LINE_LENGTH 80
784void iiDebug()
785{
786  Print("\n-- break point in %s --\n",VoiceName());
787  if (iiDebugMarker) VoiceBackTrack();
788  char * s;
789  iiDebugMarker=FALSE;
790  s = (char *)AllocL(BREAK_LINE_LENGTH+4);
791  loop
792  {
793    memset(s,0,80);
794    fe_fgets_stdin("",s,BREAK_LINE_LENGTH);
795    if (s[BREAK_LINE_LENGTH-1]!='\0')
796    {
797      Print("line too long, max is %d chars\n",BREAK_LINE_LENGTH);
798    }
799    else
800      break;
801  }
802  if (*s=='\n')
803  {
804    iiDebugMarker=TRUE;
805  }
806#if MDEBUG
807  else if(strncmp(s,"cont;",5)==0)
808  {
809    iiDebugMarker=TRUE;
810  }
811#endif /* MDEBUG */
812  else
813  {
814    strcat( s, "\n;~\n");
815    newBuffer(s,BT_execute);
816  }
817}
818
819int iiDeclCommand(leftv sy, leftv name, int lev,int t, idhdl* root,BOOLEAN isring, BOOLEAN init_b)
820{
821  BOOLEAN res=FALSE;
822  char *id = name->name;
823
824  memset(sy,0,sizeof(sleftv));
825  if ((name->name==NULL)||(isdigit(name->name[0])))
826  {
827    WerrorS("object to declare is not a name");
828    res=TRUE;
829  }
830  else
831  {
832    //if (name->rtyp!=0)
833    //{
834    //  Warn("`%s` is already in use",name->name);
835    //}
836#ifdef HAVE_NAMESPACES
837    if(name->req_packhdl != NULL && name->packhdl != NULL &&
838       name->req_packhdl != name->packhdl)
839      id = mstrdup(name->name);
840
841    //if(name->req_packhdl != NULL /*&& !isring*/) {
842    if(name->req_packhdl != NULL && !isring &&
843       IDPACKAGE(name->req_packhdl) != root) {
844      //Print("iiDeclCommand: PUSH(%s)\n",IDID(name->req_packhdl));
845      namespaceroot->push( IDPACKAGE(name->req_packhdl) ,
846                           IDID(name->req_packhdl));
847      sy->data = (char *)enterid(id,lev,t,
848                                 &IDPACKAGE(name->req_packhdl)->idroot,init_b);
849      namespaceroot->pop();
850    }
851    else
852#endif /* HAVE_NAMESPACES */
853    {
854      sy->data = (char *)enterid(id,lev,t,root,init_b);
855    }
856    if (sy->data!=NULL)
857    {
858      sy->rtyp=IDHDL;
859      currid=sy->name=IDID((idhdl)sy->data);
860      name->name=NULL; /* used in enterid */
861      //sy->e = NULL;
862      if (name->next!=NULL)
863      {
864        sy->next=(leftv)Alloc(sizeof(sleftv));
865        res=iiDeclCommand(sy->next,name->next,lev,t,root, isring);
866      }
867    }
868    else res=TRUE;
869  }
870  name->CleanUp();
871  return res;
872}
873
874BOOLEAN iiParameter(leftv p)
875{
876  if (iiCurrArgs==NULL)
877  {
878    if (strcmp(p->name,"#")==0) return FALSE;
879    Werror("not enough arguments for proc %s",VoiceName());
880    p->CleanUp();
881    return TRUE;
882  }
883  leftv h=iiCurrArgs;
884  if (strcmp(p->name,"#")==0)
885  {
886    iiCurrArgs=NULL;
887  }
888  else
889  {
890    iiCurrArgs=h->next;
891    h->next=NULL;
892  }
893  BOOLEAN res=iiAssign(p,h);
894  Free((ADDRESS)h,sizeof(sleftv));
895  return res;
896}
897
898static BOOLEAN iiInternalExport (leftv v, int toLev)
899{
900  idhdl h=(idhdl)v->data;
901  //Print("iiInternalExport('%s',%d)%s\n", v->name, toLev,"");
902  if (IDLEV(h)==0) Warn("`%s` is already global",IDID(h));
903  else
904  {
905    h=IDROOT->get(v->name,toLev);
906    idhdl *root=&IDROOT;
907    if ((h==NULL)&&(currRing!=NULL))
908    {
909      h=currRing->idroot->get(v->name,toLev);
910      root=&currRing->idroot;
911    }
912    if ((h!=NULL)&&(IDLEV(h)==toLev))
913    {
914      if (IDTYP(h)==v->Typ())
915      {
916        if (BVERBOSE(V_REDEFINE))
917        {
918#ifdef KAI
919          Warn("!!! redefining %s",IDID(h));
920#else
921          Warn("redefining %s",IDID(h));
922#endif
923        }
924#ifdef HAVE_NAMESPACES
925        //if (namespaceroot->currRing==IDRING(h)) namespaceroot->currRing=NULL;
926#endif /* HAVE_NAMESPACES */
927#ifdef USE_IILOCALRING
928            if (iiLocalRing[0]==IDRING(h)) iiLocalRing[0]=NULL;
929#else
930            if (namespaceroot->root->currRing==IDRING(h))
931              namespaceroot->root->currRing=NULL;
932#endif
933        killhdl(h,root);
934      }
935      else
936      {
937        return TRUE;
938      }
939    }
940    h=(idhdl)v->data;
941    IDLEV(h)=toLev;
942    iiNoKeepRing=FALSE;
943  }
944  return FALSE;
945}
946
947#ifdef HAVE_NAMESPACES
948BOOLEAN iiInternalExport (leftv v, int toLev, idhdl roothdl)
949{
950  idhdl h=(idhdl)v->data;
951  if(h==NULL) {
952    Warn("'%s': no such identifier\n", v->name);
953    return FALSE;
954  }
955  package rootpack = IDPACKAGE(roothdl);
956  //Print("iiInternalExport('%s',%d,%s) %s\n", v->name, toLev, IDID(roothdl),"");
957//  if (IDLEV(h)==0) Warn("`%s` is already global",IDID(h));
958//  else
959  {
960    /* is not ring or ring-element */
961    if( (IDTYP(h) == RING_CMD) || (IDTYP(h) == QRING_CMD)) {
962      sleftv tmp_expr;
963      //Print("// ==> Ring set nesting to 0\n");
964      //Print("// ++> make a copy of ring\n");
965      if(iiInternalExport(v, toLev)) return TRUE;
966      if(IDPACKAGE(roothdl) != NSPACK(namespaceroot)) {
967        namespaceroot->push(rootpack, IDID(roothdl));
968        //namespaceroot->push(NSPACK(namespaceroot->root), "Top");
969        idhdl rl=enterid(mstrdup(v->name), toLev, IDTYP(h),
970                         &(rootpack->idroot), FALSE);
971        namespaceroot->pop();
972
973        if( rl == NULL) return TRUE;
974        ring r=(ring)v->Data();
975        if(r != NULL) {
976          if (&IDRING(rl)!=NULL) rKill(rl);
977          r->ref++;
978          IDRING(rl)=r;
979        }
980        else PrintS("! ! ! ! ! r is empty!!!!!!!!!!!!\n");
981      }
982    }
983    else if ((BEGIN_RING<IDTYP(h)) && (IDTYP(h)<END_RING)
984             || ((IDTYP(h)==LIST_CMD) && (lRingDependend(IDLIST(h))))) {
985      //Print("// ==> Ringdependent set nesting to 0\n");
986      if(iiInternalExport(v, toLev)) return TRUE;
987    } else {
988      if (h==IDROOT)
989      {
990        IDROOT=h->next;
991      }
992      else
993      {
994        idhdl hh=IDROOT;
995        while ((hh->next!=h)&&(hh->next!=NULL))
996          hh=hh->next;
997        if (hh->next==h)
998          hh->next=h->next;
999        else
1000          return TRUE;
1001      }
1002      h->next=rootpack->idroot;
1003      rootpack->idroot=h;
1004    }
1005    IDLEV(h)=toLev;
1006  }
1007  return FALSE;
1008}
1009#endif /* HAVE_NAMESAPCES */
1010
1011BOOLEAN iiExport (leftv v, int toLev)
1012{
1013  BOOLEAN nok=FALSE;
1014  leftv r=v;
1015  while (v!=NULL)
1016  {
1017    if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL))
1018    {
1019      WerrorS("cannot export");
1020      nok=TRUE;
1021    }
1022    else
1023    {
1024      if(iiInternalExport(v, toLev)) {
1025        r->CleanUp();
1026        return TRUE;
1027      }
1028    }
1029    v=v->next;
1030  }
1031  r->CleanUp();
1032  return nok;
1033}
1034
1035/*assume root!=idroot*/
1036#ifdef HAVE_NAMESPACES
1037BOOLEAN iiExport (leftv v, int toLev, idhdl root)
1038{
1039  BOOLEAN nok=FALSE;
1040  leftv rv=v;
1041  while (v!=NULL)
1042  {
1043    if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL)
1044    )
1045    {
1046      WerrorS("cannot export");
1047      nok=TRUE;
1048    }
1049    else
1050    {
1051      idhdl old=root->get(v->name,toLev);
1052      if (old!=NULL)
1053      {
1054        if (IDTYP(old)==v->Typ())
1055        {
1056          if (BVERBOSE(V_REDEFINE))
1057          {
1058            Warn("redefining %s",IDID(old));
1059          }
1060          killhdl(old,&root);
1061        }
1062        else
1063        {
1064          rv->CleanUp();
1065          return TRUE;
1066        }
1067      }
1068      if(iiInternalExport(v, toLev, root)) {
1069        rv->CleanUp();
1070        return TRUE;
1071      }
1072    }
1073    v=v->next;
1074  }
1075  rv->CleanUp();
1076  return nok;
1077}
1078#endif /* HAVE_NAMESPACES */
1079
1080BOOLEAN iiCheckRing(int i)
1081{
1082  if (currRingHdl==NULL)
1083  {
1084    #ifdef SIQ
1085    if (siq<=0)
1086    {
1087    #endif
1088      if ((i>BEGIN_RING) && (i<END_RING))
1089      {
1090        WerrorS("no ring active");
1091        return TRUE;
1092      }
1093    #ifdef SIQ
1094    }
1095    #endif
1096  }
1097  return FALSE;
1098}
1099
1100poly    iiHighCorner(ideal I, int ak)
1101{
1102  BOOLEAN *UsedAxis=(BOOLEAN *)Alloc0(pVariables*sizeof(BOOLEAN));
1103  int i,n;
1104  poly po;
1105  for(i=IDELEMS(I)-1;i>=0;i--)
1106  {
1107    po=I->m[i];
1108    if ((po!=NULL) &&((n=pIsPurePower(po))!=0)) UsedAxis[n-1]=TRUE;
1109  }
1110  for(i=pVariables-1;i>=0;i--)
1111  {
1112    if(UsedAxis[i]==FALSE) return NULL; // not zero-dim.
1113  }
1114  if (currRing->OrdSgn== -1)
1115  {
1116    po=NULL;
1117    scComputeHC(I,ak,po);
1118    if (po!=NULL)
1119    {
1120      pGetCoeff(po)=nInit(1);
1121      for (i=pVariables; i>0; i--)
1122      {
1123        if (pGetExp(po, i) > 0) pDecrExp(po,i);
1124      }
1125    }
1126  }
1127  if (po!=NULL)
1128  {
1129    pSetComp(po,ak);
1130    pSetm(po);
1131  }
1132  return po;
1133}
Note: See TracBrowser for help on using the repository browser.