source: git/Singular/clapsing.cc @ 9b6641

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