source: git/Singular/clapsing.cc @ 71ac17e

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