source: git/Singular/clapsing.cc @ cc94b0a

spielwiese
Last change on this file since cc94b0a was cc94b0a, checked in by Hans Schönemann <hannes@…>, 26 years ago
Tue Mar 31 10:47:06 MET DST 1998 hannes * feread.cc: fixed handling of empty history * clapsing.cc: fixed gcd(0,..) and gcd(..,0) -> pOne() * febase.h/febase.inc: renaming of scanner variables ( yy_blocklineno, yy_noeof) * febase.inc: increased speed in feReadLine * minor changes in scanner/grammar/iparith.cc (example) git-svn-id: file:///usr/local/Singular/svn/trunk@1291 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 21.9 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2/****************************************
3*  Computer Algebra System SINGULAR     *
4****************************************/
5// $Id: clapsing.cc,v 1.26 1998-03-31 09:00:43 Singular Exp $
6/*
7* ABSTRACT: interface between Singular and factory
8*/
9
10
11#include "mod2.h"
12#ifdef HAVE_FACTORY
13#define SI_DONT_HAVE_GLOBAL_VARS
14#include "tok.h"
15#include "clapsing.h"
16#include "ipid.h"
17#include "numbers.h"
18#include "subexpr.h"
19#include "ipshell.h"
20#include <factory.h>
21#include "clapconv.h"
22#ifdef HAVE_LIBFAC_P
23#include <factor.h>
24#endif
25
26poly singclap_gcd ( poly f, poly g )
27{
28  if ((f==NULL)||(g==NULL))
29    return pOne();
30
31  poly res=NULL;
32 
33  pCleardenom(f);
34  pCleardenom(g);
35 
36  // for now there is only the possibility to handle polynomials over
37  // Q and Fp ...
38  if (( nGetChar() == 0 || nGetChar() > 1 )
39  && (currRing->parameter==NULL))
40  {
41    setCharacteristic( nGetChar() );
42    CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) );
43    res=convClapPSingP( gcd( F, G ) );
44    Off(SW_RATIONAL);
45  }
46  // and over Q(a) / Fp(a)
47  else if (( nGetChar()==1 ) /* Q(a) */
48  || (nGetChar() <-1))       /* Fp(a) */
49  {
50    if (nGetChar()==1) setCharacteristic( 0 );
51    else               setCharacteristic( -nGetChar() );
52    if (currRing->minpoly!=NULL)
53    {
54      CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
55      Variable a=rootOf(mipo);
56      CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) );
57      res= convClapAPSingAP( gcd( F, G ) );
58    }
59    else
60    {
61      CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) );
62      res= convClapPSingTrP( gcd( F, G ) );
63    }
64    Off(SW_RATIONAL);
65  }
66  #if 0
67  else if (( nGetChar()>1 )&&(currRing->parameter!=NULL)) /* GF(q) */
68  {
69    int p=rChar(currRing);
70    int n=2;
71    int t=p*p;
72    while (t!=nChar) { t*=p;n++; }
73    setCharacteristic(p,n,'a');
74    CanonicalForm F( convSingGFClapGF( f ) ), G( convSingGFClapGF( g ) );
75    res= convClapGFSingGF( gcd( F, G ) );
76  }
77  #endif
78  else
79    WerrorS( "not implemented" );
80
81  pDelete(&f);
82  pDelete(&g);
83  return res;
84}
85
86poly singclap_resultant ( poly f, poly g , poly x)
87{
88  int i=pIsPurePower(x);
89  if (i==0)
90  {
91    WerrorS("3rd argument must be a ring variable");
92    return NULL;
93  }
94  Variable X(i);
95  // for now there is only the possibility to handle polynomials over
96  // Q and Fp ...
97  if (( nGetChar() == 0 || nGetChar() > 1 )
98  && (currRing->parameter==NULL))
99  {
100    setCharacteristic( nGetChar() );
101    CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) );
102    poly res=convClapPSingP( resultant( F, G, X ) );
103    Off(SW_RATIONAL);
104    return res;
105  }
106  // and over Q(a) / Fp(a)
107  else if (( nGetChar()==1 ) /* Q(a) */
108  || (nGetChar() <-1))       /* Fp(a) */
109  {
110    if (nGetChar()==1) setCharacteristic( 0 );
111    else               setCharacteristic( -nGetChar() );
112    poly res;
113    if (currRing->minpoly!=NULL)
114    {
115      CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
116      Variable a=rootOf(mipo);
117      CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) );
118      res= convClapAPSingAP( resultant( F, G, X ) );
119    }
120    else
121    {
122      CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) );
123      res= convClapPSingTrP( resultant( F, G, X ) );
124    }
125    Off(SW_RATIONAL);
126    return res;
127  }
128  else
129    WerrorS( "not implemented" );
130  return NULL;
131}
132//poly singclap_resultant ( poly f, poly g , poly x)
133//{
134//  int i=pVar(x);
135//  if (i==0)
136//  {
137//    WerrorS("ringvar expected");
138//    return NULL;
139//  }
140//  ideal I=idInit(1,1);
141//
142//  // get the coeffs von f wrt. x:
143//  I->m[0]=pCopy(f);
144//  matrix ffi=mpCoeffs(I,i);
145//  ffi->rank=1;
146//  ffi->ncols=ffi->nrows;
147//  ffi->nrows=1;
148//  ideal fi=(ideal)ffi;
149//
150//  // get the coeffs von g wrt. x:
151//  I->m[0]=pCopy(g);
152//  matrix ggi=mpCoeffs(I,i);
153//  ggi->rank=1;
154//  ggi->ncols=ggi->nrows;
155//  ggi->nrows=1;
156//  ideal gi=(ideal)ggi;
157//
158//  // contruct the matrix:
159//  int fn=IDELEMS(fi); //= deg(f,x)+1
160//  int gn=IDELEMS(gi); //= deg(g,x)+1
161//  matrix m=mpNew(fn+gn-2,fn+gn-2);
162//  if(m==NULL)
163//  {
164//    return NULL;
165//  }
166//
167//  // enter the coeffs into m:
168//  int j;
169//  for(i=0;i<gn-1;i++)
170//  {
171//    for(j=0;j<fn;j++)
172//    {
173//      MATELEM(m,i+1,fn-j+i)=pCopy(fi->m[j]);
174//    }
175//  }
176//  for(i=0;i<fn-1;i++)
177//  {
178//    for(j=0;j<gn;j++)
179//    {
180//      MATELEM(m,gn+i,gn-j+i)=pCopy(gi->m[j]);
181//    }
182//  }
183//
184//  poly r=mpDet(m);
185//
186//  idDelete(&fi);
187//  idDelete(&gi);
188//  idDelete((ideal *)&m);
189//  return r;
190//}
191
192lists singclap_extgcd ( poly f, poly g )
193{
194  // for now there is only the possibility to handle univariate
195  // polynomials over
196  // Q and Fp ...
197  poly res=NULL,pa=NULL,pb=NULL;
198  On(SW_SYMMETRIC_FF);
199  if (( nGetChar() == 0 || nGetChar() > 1 )
200  && (currRing->parameter==NULL))
201  {
202    setCharacteristic( nGetChar() );
203    CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) );
204    if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
205    {
206      Off(SW_RATIONAL);
207      WerrorS("not univariate");
208      return NULL;
209    }
210    CanonicalForm Fa,Gb;
211    res=convClapPSingP( extgcd( F, G, Fa, Gb ) );
212    pa=convClapPSingP(Fa);
213    pb=convClapPSingP(Gb);
214    Off(SW_RATIONAL);
215  }
216  // and over Q(a) / Fp(a)
217  else if (( nGetChar()==1 ) /* Q(a) */
218  || (nGetChar() <-1))       /* Fp(a) */
219  {
220    if (nGetChar()==1) setCharacteristic( 0 );
221    else               setCharacteristic( -nGetChar() );
222    CanonicalForm Fa,Gb;
223    if (currRing->minpoly!=NULL)
224    {
225      CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
226      Variable a=rootOf(mipo);
227      CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) );
228      if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
229      {
230        WerrorS("not univariate");
231        return NULL;
232      }
233      res= convClapAPSingAP( extgcd( F, G, Fa, Gb ) );
234      pa=convClapAPSingAP(Fa);
235      pb=convClapAPSingAP(Gb);
236    }
237    else
238    {
239      CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) );
240      if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
241      {
242        Off(SW_RATIONAL);
243        WerrorS("not univariate");
244        return NULL;
245      }
246      res= convClapPSingTrP( extgcd( F, G, Fa, Gb ) );
247      pa=convClapPSingTrP(Fa);
248      pb=convClapPSingTrP(Gb);
249    }
250    Off(SW_RATIONAL);
251  }
252  else
253  {
254    WerrorS( "not implemented" );
255    return NULL;
256  }
257  lists L=(lists)Alloc(sizeof(slists));
258  L->Init(3);
259  L->m[0].rtyp=POLY_CMD;
260  L->m[0].data=(void *)res;
261  L->m[1].rtyp=POLY_CMD;
262  L->m[1].data=(void *)pa;
263  L->m[2].rtyp=POLY_CMD;
264  L->m[2].data=(void *)pb;
265  return L;
266}
267
268poly singclap_pdivide ( poly f, poly g )
269{
270  // for now there is only the possibility to handle polynomials over
271  // Q and Fp ...
272  poly res=NULL;
273  On(SW_RATIONAL);
274  if (( nGetChar() == 0 || nGetChar() > 1 )
275  && (currRing->parameter==NULL))
276  {
277    setCharacteristic( nGetChar() );
278    CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) );
279    res = convClapPSingP( F / G );
280  }
281  // and over Q(a) / Fp(a)
282  else if (( nGetChar()==1 ) /* Q(a) */
283  || (nGetChar() <-1))       /* Fp(a) */
284  {
285    if (nGetChar()==1) setCharacteristic( 0 );
286    else               setCharacteristic( -nGetChar() );
287    if (currRing->minpoly!=NULL)
288    {
289      CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
290      Variable a=rootOf(mipo);
291      CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) );
292      res= convClapAPSingAP(  F / G  );
293    }
294    else
295    {
296      CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) );
297      res= convClapPSingTrP(  F / G  );
298    }
299  }
300  else
301    WerrorS( "not implemented" );
302  Off(SW_RATIONAL);
303  return res;
304}
305
306void singclap_divide_content ( poly f )
307{
308  if ( nGetChar() == 1 )
309    setCharacteristic( 0 );
310  else  if ( nGetChar() == -1 )
311    return; /* not implemented for R */
312  else  if ( nGetChar() < 0 )
313    setCharacteristic( -nGetChar() );
314  else if (currRing->parameter==NULL) /* not GF(q) */
315    setCharacteristic( nGetChar() );
316  else
317    return; /* not implemented*/
318  if ( f==NULL )
319  {
320    return;
321  }
322  else  if ( pNext( f ) == NULL )
323  {
324    pSetCoeff( f, nInit( 1 ) );
325    return;
326  }
327  else
328  {
329    CFList L;
330    CanonicalForm g, h;
331    poly p = pNext(f);
332    nTest(pGetCoeff(f));
333    g = convSingTrClapP( ((lnumber)pGetCoeff(f))->z );
334    L.append( g );
335    while ( p && (g != 1) )
336    {
337      nTest(pGetCoeff(p));
338      h = convSingTrClapP( ((lnumber)pGetCoeff(p))->z );
339      p = pNext( p );
340      g = gcd( g, h );
341      L.append( h );
342    }
343    if ( g == 1 )
344    {
345      pTest(f);
346      return;
347    }
348    #ifdef LDEBUG
349    else if ( g == 0 )
350    {
351      pTest(f);
352      pWrite(f);
353      PrintS("=> gcd 0 in divide_content\n");
354      return;
355    }
356    #endif
357    else
358    {
359      CFListIterator i;
360      for ( i = L, p = f; i.hasItem(); i++, p=pNext(p) )
361      {
362        lnumber c=(lnumber)pGetCoeff(p);
363        napDelete(&c->z);
364        #ifdef LDEBUG
365        number nt=(number)Alloc0(sizeof(rnumber));
366        lnumber nnt=(lnumber)nt;
367        nnt->z=convClapPSingTr( i.getItem());
368        nTest(nt);
369        #endif
370        c->z=convClapPSingTr( i.getItem() / g );
371        nTest((number)c);
372        //#ifdef LDEBUG
373        //number cn=(number)c;
374        //StringSet(""); nWrite(nt); StringAppend(" ==> ");
375        //nWrite(cn);PrintS(StringAppend("\n"));
376        //#endif
377      }
378    }
379    pTest(f);
380  }
381}
382
383ideal singclap_factorize ( poly f, intvec ** v , int with_exps)
384{
385  // with_exps: 1 return only true factors
386  //            2 return true factors and exponents
387  //            0 return factors and exponents
388
389  ideal res=NULL;
390  if (f==NULL)
391  {
392    res=idInit(1,1);
393    if (with_exps!=1)
394    {
395      (*v)=new intvec(1);
396    }
397    return res;
398  }
399  Off(SW_RATIONAL);
400  On(SW_SYMMETRIC_FF);
401  CFFList L;
402  number N=NULL;
403
404  if (( (nGetChar() == 0) || (nGetChar() > 1) )
405  && (currRing->parameter==NULL))
406  {
407    setCharacteristic( nGetChar() );
408    if (nGetChar()==0) /* Q */
409    {
410      if (f!=NULL)
411      {
412        if (with_exps==0)
413          N=nCopy(pGetCoeff(f));
414        pCleardenom(f);
415        if (with_exps==0)
416        {
417          number nn=nDiv(N,pGetCoeff(f));
418          nDelete(&N);
419          N=nn;
420        }
421      }
422    }
423    CanonicalForm F( convSingPClapP( f ) );
424    if (nGetChar()==0) /* Q */
425    {
426      L = factorize( F );
427    }
428    else /* Fp */
429    {
430#ifdef HAVE_LIBFAC_P
431      L = Factorize( F );
432#else
433      return NULL;
434#endif
435    }
436  }
437  // and over Q(a) / Fp(a)
438  else if (( nGetChar()==1 ) /* Q(a) */
439  || (nGetChar() <-1))       /* Fp(a) */
440  {
441    if (nGetChar()==1) setCharacteristic( 0 );
442    else               setCharacteristic( -nGetChar() );
443    if (currRing->minpoly!=NULL)
444    {
445      //if (nGetChar()==1)
446      //{
447      //  WerrorS("not implemented");
448      //  return NULL;
449      //}
450      CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
451      Variable a=rootOf(mipo);
452      CanonicalForm F( convSingAPClapAP( f,a ) );
453      L = factorize( F, a );
454    }
455    else
456    {
457      CanonicalForm F( convSingTrPClapP( f ) );
458      if (nGetChar()==1) /* Q(a) */
459      {
460        L = factorize( F );
461      }
462      else /* Fp(a) */
463      {
464#ifdef HAVE_LIBFAC_P
465        L = Factorize( F );
466#else
467        return NULL;
468#endif
469      }
470    }
471  }
472  else
473  {
474    WerrorS( "not implemented" );
475    goto end;
476  }
477  {
478    // the first factor should be a constant
479    if ( ! L.getFirst().factor().inCoeffDomain() )
480      L.insert(CFFactor(1,1));
481    // convert into ideal
482    int n = L.length();
483    CFFListIterator J=L;
484    int j=0;
485    if (with_exps!=1)
486    {
487      if ((with_exps==2)&&(n>1))
488      {
489        n--;
490        J++;
491      }
492      *v = new intvec( n );
493    }
494    res = idInit( n ,1);
495    for ( ; J.hasItem(); J++, j++ )
496    {
497      if (with_exps!=1) (**v)[j] = J.getItem().exp();
498      if ((nGetChar()==0)||(nGetChar()>1))           /* Q, Fp */
499        res->m[j] = convClapPSingP( J.getItem().factor() );
500      else if ((nGetChar()==1)||(nGetChar()<-1))     /* Q(a), Fp(a) */
501      {
502        if (currRing->minpoly==NULL)
503          res->m[j] = convClapPSingTrP( J.getItem().factor() );
504        else
505          res->m[j] = convClapAPSingAP( J.getItem().factor() );
506      }
507    }
508    if (N!=NULL)
509    {
510      pMultN(res->m[0],N);
511      nDelete(&N);
512    }
513    // delete constants
514    if ((with_exps!=0) && (res!=NULL))
515    {
516      int i=IDELEMS(res)-1;
517      int j=0;
518      for(;i>=0;i--)
519      {
520        if (pIsConstant(res->m[i]))
521        {
522          pDelete(&(res->m[i]));
523          if ((v!=NULL) && ((*v)!=NULL))
524            (**v)[i]=0;
525          j++;
526        }
527      }
528      if (j>0)
529      {
530        idSkipZeroes(res);
531        if ((v!=NULL) && ((*v)!=NULL))
532        {
533          intvec *w=*v;
534          *v = new intvec( max(n-j,1) );
535          for (i=0,j=0;i<w->length();i++)
536          {
537            if((*w)[i]!=0)
538            {
539              (**v)[j]=(*w)[i]; j++;
540            }
541          } 
542          delete w;
543        } 
544      }
545      if (res->m[0]==NULL)
546      {
547        res->m[0]=pOne();
548      }
549    }
550  }
551end:
552  return res;
553}
554
555matrix singclap_irrCharSeries ( ideal I)
556{
557#ifdef HAVE_LIBFAC_P
558  // for now there is only the possibility to handle polynomials over
559  // Q and Fp ...
560  matrix res=NULL;
561  int i;
562  Off(SW_RATIONAL);
563  On(SW_SYMMETRIC_FF);
564  CFList L;
565  ListCFList LL;
566  if (((nGetChar() == 0) || (nGetChar() > 1) )
567  && (currRing->parameter==NULL))
568  {
569    setCharacteristic( nGetChar() );
570    for(i=0;i<IDELEMS(I);i++)
571    {
572      L.append(convSingPClapP(I->m[i]));
573    }
574  }
575  // and over Q(a) / Fp(a)
576  else if (( nGetChar()==1 ) /* Q(a) */
577  || (nGetChar() <-1))       /* Fp(a) */
578  {
579    if (nGetChar()==1) setCharacteristic( 0 );
580    else               setCharacteristic( -nGetChar() );
581    for(i=0;i<IDELEMS(I);i++)
582    {
583      L.append(convSingTrPClapP(I->m[i]));
584    }
585  }
586  else
587  {
588    WerrorS("not implemented");
589    return res;
590  }
591
592  LL=IrrCharSeries(L);
593  int m= LL.length(); // Anzahl Zeilen
594  int n=0;
595  ListIterator<CFList> LLi;
596  CFListIterator Li;
597  for ( LLi = LL; LLi.hasItem(); LLi++ )
598  {
599    n = max(LLi.getItem().length(),n);
600  }
601  res=mpNew(m,n);
602  if ((m==0) || (n==0))
603  {
604    Warn("char_series returns %d x %d matrix from %d input polys (%d)\n",m,n,IDELEMS(I)+1,LL.length());
605    iiWriteMatrix((matrix)I,"I",2,0);
606  }
607  for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ )
608  {
609    for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++)
610    {
611      if ( (nGetChar() == 0) || (nGetChar() > 1) )
612        MATELEM(res,m,n)=convClapPSingP(Li.getItem());
613      else
614        MATELEM(res,m,n)=convClapPSingTrP(Li.getItem());
615    }
616  }
617  Off(SW_RATIONAL);
618  return res;
619#else
620  return NULL;
621#endif
622}
623
624char* singclap_neworder ( ideal I)
625{
626#ifdef HAVE_LIBFAC_P
627  int i;
628  Off(SW_RATIONAL);
629  On(SW_SYMMETRIC_FF);
630  CFList L;
631  if (((nGetChar() == 0) || (nGetChar() > 1) )
632  && (currRing->parameter==NULL))
633  {
634    setCharacteristic( nGetChar() );
635    for(i=0;i<IDELEMS(I);i++)
636    {
637      L.append(convSingPClapP(I->m[i]));
638    }
639  }
640  // and over Q(a) / Fp(a)
641  else if (( nGetChar()==1 ) /* Q(a) */
642  || (nGetChar() <-1))       /* Fp(a) */
643  {
644    if (nGetChar()==1) setCharacteristic( 0 );
645    else               setCharacteristic( -nGetChar() );
646    for(i=0;i<IDELEMS(I);i++)
647    {
648      L.append(convSingTrPClapP(I->m[i]));
649    }
650  }
651  else
652  {
653    WerrorS("not implemented");
654    return NULL;
655  }
656
657  List<int> IL=neworderint(L);
658  ListIterator<int> Li;
659  StringSet("");
660  Li = IL;
661  int* mark=(int*)Alloc0(pVariables*sizeof(int));
662  int cnt=pVariables;
663  loop
664  {
665    i=Li.getItem()-1;
666    mark[i]=1;
667    StringAppend(currRing->names[i]);
668    Li++;
669    cnt--;
670    if(cnt==0) break;
671    StringAppend(",");
672    if(! Li.hasItem()) break;
673  }
674  for(i=0;i<pVariables;i++)
675  {
676    if(mark[i]==0)
677    {
678      StringAppend(currRing->names[i]);
679      cnt--;
680      if(cnt==0) break;
681      StringAppend(",");
682    }
683  }
684  return mstrdup(StringAppend(""));
685#else
686  return NULL;
687#endif
688}
689
690BOOLEAN singclap_isSqrFree(poly f)
691{
692  BOOLEAN b=FALSE;
693  Off(SW_RATIONAL);
694  //  Q / Fp
695  if (((nGetChar() == 0) || (nGetChar() > 1) )
696  &&(currRing->parameter==NULL))
697  {
698    setCharacteristic( nGetChar() );
699    CanonicalForm F( convSingPClapP( f ) );
700    if((nGetChar()>1)&&(!F.isUnivariate()))
701      goto err;
702    b=(BOOLEAN)isSqrFree(F);
703  }
704  // and over Q(a) / Fp(a)
705  else if (( nGetChar()==1 ) /* Q(a) */
706  || (nGetChar() <-1))       /* Fp(a) */
707  {
708    if (nGetChar()==1) setCharacteristic( 0 );
709    else               setCharacteristic( -nGetChar() );
710    //if (currRing->minpoly!=NULL)
711    //{
712    //  CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
713    //  Variable a=rootOf(mipo);
714    //  CanonicalForm F( convSingAPClapAP( f,a ) );
715    //  ...
716    //}
717    //else
718    {
719      CanonicalForm F( convSingTrPClapP( f ) );
720      b=(BOOLEAN)isSqrFree(F);
721    }
722    Off(SW_RATIONAL);
723  }
724  else
725  {
726err:
727    WerrorS( "not implemented" );
728  }
729  return b;
730}
731
732poly singclap_det( const matrix m )
733{
734  int r=m->rows();
735  if (r!=m->cols())
736  {
737    Werror("det of %d x %d matrix",r,m->cols());
738    return NULL;
739  }
740  poly res=NULL;
741  if (( nGetChar() == 0 || nGetChar() > 1 )
742  && (currRing->parameter==NULL))
743  {
744    setCharacteristic( nGetChar() );
745    CFMatrix M(r,r);
746    int i,j;
747    for(i=r;i>0;i--)
748    {
749      for(j=r;j>0;j--)
750      {
751        M(i,j)=convSingPClapP(MATELEM(m,i,j));
752      }
753    }
754    res= convClapPSingP( determinant(M,r) ) ;
755  }
756  // and over Q(a) / Fp(a)
757  else if (( nGetChar()==1 ) /* Q(a) */
758  || (nGetChar() <-1))       /* Fp(a) */
759  {
760    if (nGetChar()==1) setCharacteristic( 0 );
761    else               setCharacteristic( -nGetChar() );
762    CFMatrix M(r,r);
763    poly res;
764    if (currRing->minpoly!=NULL)
765    {
766      CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
767      Variable a=rootOf(mipo);
768      int i,j;
769      for(i=r;i>0;i--)
770      {
771        for(j=r;j>0;j--)
772        {
773          M(i,j)=convSingAPClapAP(MATELEM(m,i,j),a);
774        }
775      }
776      res= convClapAPSingAP( determinant(M,r) ) ;
777    }
778    else
779    {
780      int i,j;
781      for(i=r;i>0;i--)
782      {
783        for(j=r;j>0;j--)
784        {
785          M(i,j)=convSingTrPClapP(MATELEM(m,i,j));
786        }
787      }
788      res= convClapPSingTrP( determinant(M,r) );
789    }
790  }
791  else
792    WerrorS( "not implemented" );
793  Off(SW_RATIONAL);
794  return res;
795}
796
797int singclap_det_i( intvec * m )
798{
799  setCharacteristic( 0 );
800  CFMatrix M(m->rows(),m->cols());
801  int i,j;
802  for(i=m->rows();i>0;i--)
803  {
804    for(j=m->cols();j>0;j--)
805    {
806      M(i,j)=IMATELEM(*m,i,j);
807    }
808  }
809  int res= convClapISingI( determinant(M,m->rows())) ;
810  Off(SW_RATIONAL);
811  return res;
812}
813/*==============================================================*/
814/* interpreter interface : */
815BOOLEAN jjGCD_P(leftv res, leftv u, leftv v)
816{
817  res->data=(void *)singclap_gcd((poly)(u->CopyD()),((poly)v->CopyD()));
818  return FALSE;
819}
820
821BOOLEAN jjFAC_P(leftv res, leftv u)
822{
823  intvec *v=NULL;
824  ideal f=singclap_factorize((poly)(u->Data()), &v, 0);
825#ifndef HAVE_LIBFAC_P
826  if (f==NULL) return TRUE;
827#endif
828  lists l=(lists)Alloc(sizeof(slists));
829  l->Init(2);
830  l->m[0].rtyp=IDEAL_CMD;
831  l->m[0].data=(void *)f;
832  l->m[1].rtyp=INTVEC_CMD;
833  l->m[1].data=(void *)v;
834  res->data=(void *)l;
835  return FALSE;
836}
837
838BOOLEAN jjSQR_FREE_DEC(leftv res, leftv u,leftv dummy)
839{
840  intvec *v=NULL;
841  int sw=(int)dummy->Data();
842  ideal f=singclap_factorize((poly)(u->Data()), &v, sw);
843  switch(sw)
844  {
845    case 0:
846    case 2:
847    {
848      lists l=(lists)Alloc(sizeof(slists));
849      l->Init(2);
850      l->m[0].rtyp=IDEAL_CMD;
851      l->m[0].data=(void *)f;
852      l->m[1].rtyp=INTVEC_CMD;
853      l->m[1].data=(void *)v;
854      res->data=(void *)l;
855      res->rtyp=LIST_CMD;
856      return FALSE;
857    }
858    case 1:
859      res->data=(void *)f;
860      return f==NULL;
861  }
862  WerrorS("invalid switch");
863  return TRUE;
864}
865
866#if 0
867BOOLEAN jjIS_SQR_FREE(leftv res, leftv u)
868{
869  BOOLEAN b=singclap_factorize((poly)(u->Data()), &v, 0);
870  res->data=(void *)b;
871}
872#endif
873
874BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v)
875{
876  res->data=singclap_extgcd((poly)u->Data(),(poly)v->Data());
877  return (res->data==NULL);
878}
879BOOLEAN jjRESULTANT(leftv res, leftv u, leftv v, leftv w)
880{
881  res->data=singclap_resultant((poly)u->Data(),(poly)v->Data(), (poly)w->Data());
882  return (res->data==NULL);
883}
884BOOLEAN jjCHARSERIES(leftv res, leftv u)
885{
886  res->data=singclap_irrCharSeries((ideal)u->Data());
887  return (res->data==NULL);
888}
889
890alg singclap_alglcm ( alg f, alg g )
891{
892  // over Q(a) / Fp(a)
893 if (nGetChar()==1) setCharacteristic( 0 );
894 else               setCharacteristic( -nGetChar() );
895 alg res;
896 if (currRing->minpoly!=NULL)
897 {
898   CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
899   Variable a=rootOf(mipo);
900   CanonicalForm F( convSingAClapA( f,a ) ), G( convSingAClapA( g,a ) );
901   res= convClapASingA( (F/ gcd( F, G ))*G );
902 }
903 else
904 {
905   CanonicalForm F( convSingTrClapP( f ) ), G( convSingTrClapP( g ) );
906   res= convClapPSingTr( (F/gcd( F, G ))*G );
907 }
908 Off(SW_RATIONAL);
909 return res;
910}
911
912#ifdef FACTORY_DEBUG_OUT
913#include "longalg.h"
914#include "febase.h"
915#endif
916
917void singclap_algdividecontent ( alg f, alg g, alg &ff, alg &gg )
918{
919#ifdef FACTORY_DEBUG_OUT
920    StringSetS("f = ");
921    napWrite(f);
922    PrintS(StringAppend("\n"));
923    StringSetS("g = ");
924    napWrite(g);
925    PrintS(StringAppend("\n"));
926#endif
927  // over Q(a) / Fp(a)
928 if (nGetChar()==1) setCharacteristic( 0 );
929 else               setCharacteristic( -nGetChar() );
930 ff=gg=NULL;
931 if (currRing->minpoly!=NULL)
932 {
933   CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z);
934   Variable a=rootOf(mipo);
935   CanonicalForm F( convSingAClapA( f,a ) ), G( convSingAClapA( g,a ) );
936   CanonicalForm GCD=gcd( F, G );
937   if (GCD!=1)
938   {
939     ff= convClapASingA( F/ GCD );
940     gg= convClapASingA( G/ GCD );
941   }
942 }
943 else
944 {
945   CanonicalForm F( convSingTrClapP( f ) ), G( convSingTrClapP( g ) );
946   CanonicalForm GCD=gcd( F, G );
947   if (GCD!=1)
948   {
949     ff= convClapPSingTr( F/ GCD );
950     gg= convClapPSingTr( G/ GCD );
951   }
952 }
953 Off(SW_RATIONAL);
954#ifdef FACTORY_DEBUG_OUT
955    StringSetS("ff = ");
956    napWrite(ff);
957    PrintS(StringAppend("\n"));
958    StringSetS("gg = ");
959    napWrite(gg);
960    PrintS(StringAppend("\n"));
961#endif
962}
963#endif
Note: See TracBrowser for help on using the repository browser.