source: git/Singular/ipshell.cc @ b7b08c

spielwiese
Last change on this file since b7b08c was b7b08c, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* us short exponent vectors in divisbility tests * AllocSizeOf * garbage collection * scanner/gmp: allow .0 and 1. input of reals git-svn-id: file:///usr/local/Singular/svn/trunk@3711 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 25.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: ipshell.cc,v 1.50 1999-10-14 14:27:10 obachman 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(" <%x>",IDRING(h));
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    if (!nSetMap(IDRING(r)))
597    {
598      if (rEqual(IDRING(r),currRing))
599      {
600        nMap=nCopy;
601      }
602      else
603      {
604        Werror("can not map from ground field of %s to current ground field",
605          theMap->preimage);
606        return NULL;
607      }
608    }
609    if (IDELEMS(theMap)<IDRING(r)->N)
610    {
611      theMap->m=(polyset)ReAlloc((ADDRESS)theMap->m,
612                                 IDELEMS(theMap)*sizeof(poly),
613                                 (IDRING(r)->N)*sizeof(poly));
614      for(i=IDELEMS(theMap);i<IDRING(r)->N;i++)
615        theMap->m[i]=NULL;
616      IDELEMS(theMap)=IDRING(r)->N;
617    }
618    if (what==NULL)
619    {
620      WerrorS("argument of a map must have a name");
621    }
622    else if ((w=IDRING(r)->idroot->get(what,myynest))!=NULL)
623    {
624      v=(leftv)Alloc0SizeOf(sleftv);
625      sleftv tmpW;
626      memset(&tmpW,0,sizeof(sleftv));
627      tmpW.rtyp=IDTYP(w);
628      tmpW.data=IDDATA(w);
629      if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,IDRING(r),NULL,NULL,0))
630      {
631        Werror("cannot map %s(%d)",Tok2Cmdname(w->typ),w->typ);
632        FreeSizeOf((ADDRESS)v,sleftv);
633        return NULL;
634      }
635      return v;
636    }
637    else
638    {
639      Werror("%s undefined in %s",what,theMap->preimage);
640    }
641  }
642  else
643  {
644    Werror("cannot find preimage %s",theMap->preimage);
645  }
646  return NULL;
647}
648
649#ifdef OLD_RES
650void  iiMakeResolv(resolvente r, int length, int rlen, char * name, int typ0,
651                   intvec ** weights)
652{
653  lists L=liMakeResolv(r,length,rlen,typ0,weights);
654  int i=0;
655  idhdl h;
656  char * s=(char *)Alloc(strlen(name)+5);
657
658  while (i<=L->nr)
659  {
660    sprintf(s,"%s(%d)",name,i+1);
661    if (i==0)
662      h=enterid(mstrdup(s),myynest,typ0,&(currRing->idroot), FALSE);
663    else
664      h=enterid(mstrdup(s),myynest,MODUL_CMD,&(currRing->idroot), FALSE);
665    if (h!=NULL)
666    {
667      h->data.uideal=(ideal)L->m[i].data;
668      h->attribute=L->m[i].attribute;
669      if (BVERBOSE(V_DEF_RES))
670        Print("//defining: %s as %d-th syzygy module\n",s,i+1);
671    }
672    else
673    {
674      idDelete((ideal *)&(L->m[i].data));
675      Warn("cannot define %s",s);
676    }
677    //L->m[i].data=NULL;
678    //L->m[i].rtyp=0;
679    //L->m[i].attribute=NULL;
680    i++;
681  }
682  Free((ADDRESS)L->m,(L->nr+1)*sizeof(sleftv));
683  FreeSizeOf((ADDRESS)L,slists);
684  Free((ADDRESS)s,strlen(name)+5);
685}
686#endif
687
688//resolvente iiFindRes(char * name, int * len, int *typ0)
689//{
690//  char *s=(char *)Alloc(strlen(name)+5);
691//  int i=-1;
692//  resolvente r;
693//  idhdl h;
694//
695//  do
696//  {
697//    i++;
698//    sprintf(s,"%s(%d)",name,i+1);
699//    h=currRing->idroot->get(s,myynest);
700//  } while (h!=NULL);
701//  *len=i-1;
702//  if (*len<=0)
703//  {
704//    Werror("no objects %s(1),.. found",name);
705//    Free((ADDRESS)s,strlen(name)+5);
706//    return NULL;
707//  }
708//  r=(ideal *)Alloc(/*(len+1)*/ i*sizeof(ideal));
709//  memset(r,0,(*len)*sizeof(ideal));
710//  i=-1;
711//  *typ0=MODUL_CMD;
712//  while (i<(*len))
713//  {
714//    i++;
715//    sprintf(s,"%s(%d)",name,i+1);
716//    h=currRing->idroot->get(s,myynest);
717//    if (h->typ != MODUL_CMD)
718//    {
719//      if ((i!=0) || (h->typ!=IDEAL_CMD))
720//      {
721//        Werror("%s is not of type module",s);
722//        Free((ADDRESS)r,(*len)*sizeof(ideal));
723//        Free((ADDRESS)s,strlen(name)+5);
724//        return NULL;
725//      }
726//      *typ0=IDEAL_CMD;
727//    }
728//    if ((i>0) && (idIs0(r[i-1])))
729//    {
730//      *len=i-1;
731//      break;
732//    }
733//    r[i]=IDIDEAL(h);
734//  }
735//  Free((ADDRESS)s,strlen(name)+5);
736//  return r;
737//}
738
739static resolvente iiCopyRes(resolvente r, int l)
740{
741  int i;
742  resolvente res=(ideal *)Alloc0((l+1)*sizeof(ideal));
743
744  for (i=0; i<l; i++)
745    res[i]=idCopy(r[i]);
746  return res;
747}
748
749BOOLEAN jjMINRES(leftv res, leftv v)
750{
751  int len=0;
752  int typ0;
753  resolvente rr=liFindRes((lists)v->Data(),&len,&typ0);
754  if (rr==NULL) return TRUE;
755  resolvente r=iiCopyRes(rr,len);
756
757  syMinimizeResolvente(r,len,0);
758  Free((ADDRESS)rr,len*sizeof(ideal));
759  len++;
760  res->data=(char *)liMakeResolv(r,len,-1,typ0,NULL);
761  return FALSE;
762}
763
764BOOLEAN jjBETTI(leftv res, leftv v)
765{
766  resolvente r;
767  int len;
768  int reg,typ0;
769
770  r=liFindRes((lists)v->Data(),&len,&typ0);
771  if (r==NULL) return TRUE;
772  res->data=(char *)syBetti(r,len,&reg);
773  Free((ADDRESS)r,(len)*sizeof(ideal));
774  return FALSE;
775}
776
777int iiRegularity(lists L)
778{
779  int len,reg,typ0;
780
781  resolvente r=liFindRes(L,&len,&typ0);
782
783  if (r==NULL)
784    return -2;
785  intvec * dummy=syBetti(r,len,&reg);
786  Free((ADDRESS)r,len*sizeof(ideal));
787  delete dummy;
788  return reg+1;
789}
790
791BOOLEAN iiDebugMarker=TRUE;
792#define BREAK_LINE_LENGTH 80
793void iiDebug()
794{
795  Print("\n-- break point in %s --\n",VoiceName());
796  if (iiDebugMarker) VoiceBackTrack();
797  char * s;
798  iiDebugMarker=FALSE;
799  s = (char *)AllocL(BREAK_LINE_LENGTH+4);
800  loop
801  {
802    memset(s,0,80);
803    fe_fgets_stdin("",s,BREAK_LINE_LENGTH);
804    if (s[BREAK_LINE_LENGTH-1]!='\0')
805    {
806      Print("line too long, max is %d chars\n",BREAK_LINE_LENGTH);
807    }
808    else
809      break;
810  }
811  if (*s=='\n')
812  {
813    iiDebugMarker=TRUE;
814  }
815#if MDEBUG
816  else if(strncmp(s,"cont;",5)==0)
817  {
818    iiDebugMarker=TRUE;
819  }
820#endif /* MDEBUG */
821  else
822  {
823    strcat( s, "\n;~\n");
824    newBuffer(s,BT_execute);
825  }
826}
827
828int iiDeclCommand(leftv sy, leftv name, int lev,int t, idhdl* root,BOOLEAN isring, BOOLEAN init_b)
829{
830  BOOLEAN res=FALSE;
831  char *id = name->name;
832
833  memset(sy,0,sizeof(sleftv));
834  if ((name->name==NULL)||(isdigit(name->name[0])))
835  {
836    WerrorS("object to declare is not a name");
837    res=TRUE;
838  }
839  else
840  {
841    //if (name->rtyp!=0)
842    //{
843    //  Warn("`%s` is already in use",name->name);
844    //}
845#ifdef HAVE_NAMESPACES
846    if(name->req_packhdl != NULL && name->packhdl != NULL &&
847       name->req_packhdl != name->packhdl)
848      id = mstrdup(name->name);
849
850    //if(name->req_packhdl != NULL /*&& !isring*/) {
851    if(name->req_packhdl != NULL && !isring &&
852       IDPACKAGE(name->req_packhdl) != root) {
853      //Print("iiDeclCommand: PUSH(%s)\n",IDID(name->req_packhdl));
854      namespaceroot->push( IDPACKAGE(name->req_packhdl) ,
855                           IDID(name->req_packhdl));
856      sy->data = (char *)enterid(id,lev,t,
857                                 &IDPACKAGE(name->req_packhdl)->idroot,init_b);
858      namespaceroot->pop();
859    }
860    else
861#endif /* HAVE_NAMESPACES */
862    {
863      sy->data = (char *)enterid(id,lev,t,root,init_b);
864    }
865    if (sy->data!=NULL)
866    {
867      sy->rtyp=IDHDL;
868      currid=sy->name=IDID((idhdl)sy->data);
869      name->name=NULL; /* used in enterid */
870      //sy->e = NULL;
871      if (name->next!=NULL)
872      {
873        sy->next=(leftv)AllocSizeOf(sleftv);
874        res=iiDeclCommand(sy->next,name->next,lev,t,root, isring);
875      }
876    }
877    else res=TRUE;
878  }
879  name->CleanUp();
880  return res;
881}
882
883BOOLEAN iiParameter(leftv p)
884{
885  if (iiCurrArgs==NULL)
886  {
887    if (strcmp(p->name,"#")==0) return FALSE;
888    Werror("not enough arguments for proc %s",VoiceName());
889    p->CleanUp();
890    return TRUE;
891  }
892  leftv h=iiCurrArgs;
893  if (strcmp(p->name,"#")==0)
894  {
895    iiCurrArgs=NULL;
896  }
897  else
898  {
899    iiCurrArgs=h->next;
900    h->next=NULL;
901  }
902  BOOLEAN res=iiAssign(p,h);
903  FreeSizeOf((ADDRESS)h,sleftv);
904  return res;
905}
906
907static BOOLEAN iiInternalExport (leftv v, int toLev)
908{
909  idhdl h=(idhdl)v->data;
910  //Print("iiInternalExport('%s',%d)%s\n", v->name, toLev,"");
911  if (IDLEV(h)==0) Warn("`%s` is already global",IDID(h));
912  else
913  {
914    h=IDROOT->get(v->name,toLev);
915    idhdl *root=&IDROOT;
916    if ((h==NULL)&&(currRing!=NULL))
917    {
918      h=currRing->idroot->get(v->name,toLev);
919      root=&currRing->idroot;
920    }
921    if ((h!=NULL)&&(IDLEV(h)==toLev))
922    {
923      if (IDTYP(h)==v->Typ())
924      {
925        if (BVERBOSE(V_REDEFINE))
926        {
927#ifdef KAI
928          Warn("!!! redefining %s",IDID(h));
929#else
930          Warn("redefining %s",IDID(h));
931#endif
932        }
933#ifdef HAVE_NAMESPACES
934        //if (namespaceroot->currRing==IDRING(h)) namespaceroot->currRing=NULL;
935#endif /* HAVE_NAMESPACES */
936#ifdef USE_IILOCALRING
937            if (iiLocalRing[0]==IDRING(h)) iiLocalRing[0]=NULL;
938#else
939            if (namespaceroot->root->currRing==IDRING(h))
940              namespaceroot->root->currRing=NULL;
941#endif
942        killhdl(h,root);
943      }
944      else
945      {
946        return TRUE;
947      }
948    }
949    h=(idhdl)v->data;
950    IDLEV(h)=toLev;
951    iiNoKeepRing=FALSE;
952  }
953  return FALSE;
954}
955
956#ifdef HAVE_NAMESPACES
957BOOLEAN iiInternalExport (leftv v, int toLev, idhdl roothdl)
958{
959  idhdl h=(idhdl)v->data;
960  if(h==NULL) {
961    Warn("'%s': no such identifier\n", v->name);
962    return FALSE;
963  }
964  package rootpack = IDPACKAGE(roothdl);
965  //Print("iiInternalExport('%s',%d,%s) %s\n", v->name, toLev, IDID(roothdl),"");
966//  if (IDLEV(h)==0) Warn("`%s` is already global",IDID(h));
967//  else
968  {
969    /* is not ring or ring-element */
970    if( (IDTYP(h) == RING_CMD) || (IDTYP(h) == QRING_CMD)) {
971      sleftv tmp_expr;
972      //Print("// ==> Ring set nesting to 0\n");
973      //Print("// ++> make a copy of ring\n");
974      if(iiInternalExport(v, toLev)) return TRUE;
975      if(IDPACKAGE(roothdl) != NSPACK(namespaceroot)) {
976        namespaceroot->push(rootpack, IDID(roothdl));
977        //namespaceroot->push(NSPACK(namespaceroot->root), "Top");
978        idhdl rl=enterid(mstrdup(v->name), toLev, IDTYP(h),
979                         &(rootpack->idroot), FALSE);
980        namespaceroot->pop();
981
982        if( rl == NULL) return TRUE;
983        ring r=(ring)v->Data();
984        if(r != NULL) {
985          if (&IDRING(rl)!=NULL) rKill(rl);
986          r->ref++;
987          IDRING(rl)=r;
988        }
989        else PrintS("! ! ! ! ! r is empty!!!!!!!!!!!!\n");
990      }
991    }
992    else if ((BEGIN_RING<IDTYP(h)) && (IDTYP(h)<END_RING)
993             || ((IDTYP(h)==LIST_CMD) && (lRingDependend(IDLIST(h))))) {
994      //Print("// ==> Ringdependent set nesting to 0\n");
995      if(iiInternalExport(v, toLev)) return TRUE;
996    } else {
997      if (h==IDROOT)
998      {
999        IDROOT=h->next;
1000      }
1001      else
1002      {
1003        idhdl hh=IDROOT;
1004        while ((hh->next!=h)&&(hh->next!=NULL))
1005          hh=hh->next;
1006        if (hh->next==h)
1007          hh->next=h->next;
1008        else
1009          return TRUE;
1010      }
1011      h->next=rootpack->idroot;
1012      rootpack->idroot=h;
1013    }
1014    IDLEV(h)=toLev;
1015  }
1016  return FALSE;
1017}
1018#endif /* HAVE_NAMESAPCES */
1019
1020BOOLEAN iiExport (leftv v, int toLev)
1021{
1022  BOOLEAN nok=FALSE;
1023  leftv r=v;
1024  while (v!=NULL)
1025  {
1026    if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL))
1027    {
1028      WerrorS("cannot export");
1029      nok=TRUE;
1030    }
1031    else
1032    {
1033      if(iiInternalExport(v, toLev)) {
1034        r->CleanUp();
1035        return TRUE;
1036      }
1037    }
1038    v=v->next;
1039  }
1040  r->CleanUp();
1041  return nok;
1042}
1043
1044/*assume root!=idroot*/
1045#ifdef HAVE_NAMESPACES
1046BOOLEAN iiExport (leftv v, int toLev, idhdl root)
1047{
1048  BOOLEAN nok=FALSE;
1049  leftv rv=v;
1050  while (v!=NULL)
1051  {
1052    if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL)
1053    )
1054    {
1055      WerrorS("cannot export");
1056      nok=TRUE;
1057    }
1058    else
1059    {
1060      idhdl old=root->get(v->name,toLev);
1061      if (old!=NULL)
1062      {
1063        if (IDTYP(old)==v->Typ())
1064        {
1065          if (BVERBOSE(V_REDEFINE))
1066          {
1067            Warn("redefining %s",IDID(old));
1068          }
1069          killhdl(old,&root);
1070        }
1071        else
1072        {
1073          rv->CleanUp();
1074          return TRUE;
1075        }
1076      }
1077      if(iiInternalExport(v, toLev, root)) {
1078        rv->CleanUp();
1079        return TRUE;
1080      }
1081    }
1082    v=v->next;
1083  }
1084  rv->CleanUp();
1085  return nok;
1086}
1087#endif /* HAVE_NAMESPACES */
1088
1089BOOLEAN iiCheckRing(int i)
1090{
1091  if (currRingHdl==NULL)
1092  {
1093    #ifdef SIQ
1094    if (siq<=0)
1095    {
1096    #endif
1097      if ((i>BEGIN_RING) && (i<END_RING))
1098      {
1099        WerrorS("no ring active");
1100        return TRUE;
1101      }
1102    #ifdef SIQ
1103    }
1104    #endif
1105  }
1106  return FALSE;
1107}
1108
1109poly    iiHighCorner(ideal I, int ak)
1110{
1111  BOOLEAN *UsedAxis=(BOOLEAN *)Alloc0(pVariables*sizeof(BOOLEAN));
1112  int i,n;
1113  poly po;
1114  for(i=IDELEMS(I)-1;i>=0;i--)
1115  {
1116    po=I->m[i];
1117    if ((po!=NULL) &&((n=pIsPurePower(po))!=0)) UsedAxis[n-1]=TRUE;
1118  }
1119  for(i=pVariables-1;i>=0;i--)
1120  {
1121    if(UsedAxis[i]==FALSE) return NULL; // not zero-dim.
1122  }
1123  if (currRing->OrdSgn== -1)
1124  {
1125    po=NULL;
1126    scComputeHC(I,ak,po);
1127    if (po!=NULL)
1128    {
1129      pGetCoeff(po)=nInit(1);
1130      for (i=pVariables; i>0; i--)
1131      {
1132        if (pGetExp(po, i) > 0) pDecrExp(po,i);
1133      }
1134    }
1135  }
1136  if (po!=NULL)
1137  {
1138    pSetComp(po,ak);
1139    pSetm(po);
1140  }
1141  return po;
1142}
Note: See TracBrowser for help on using the repository browser.