source: git/libfac/charset/alg_factor.cc @ 456842

spielwiese
Last change on this file since 456842 was b87513c, checked in by Hans Schönemann <hannes@…>, 23 years ago
* hannes: code cleanup git-svn-id: file:///usr/local/Singular/svn/trunk@5563 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.3 KB
Line 
1/* Copyright 1997 Michael Messollen. All rights reserved. */
2////////////////////////////////////////////////////////////
3// emacs edit mode for this file is -*- C++ -*-
4////////////////////////////////////////////////////////////
5static char * rcsid = "$Id: alg_factor.cc,v 1.8 2001-08-06 08:32:53 Singular Exp $";
6////////////////////////////////////////////////////////////
7// FACTORY - Includes
8#include <factory.h>
9// Factor - Includes
10#include <tmpl_inst.h>
11#include <Factor.h>
12#include <SqrFree.h>
13#include <helpstuff.h>
14// Charset - Includes
15#include "csutil.h"
16#include "charset.h"
17#include "reorder.h"
18#include "algfactor.h"
19// some CC's need this:
20#include "alg_factor.h"
21
22#ifdef ALGFACTORDEBUG
23#  define DEBUGOUTPUT
24#else
25#  undef DEBUGOUTPUT
26#endif
27
28#include "debug.h"
29#include "timing.h"
30TIMING_DEFINE_PRINT(newfactoras_time);
31
32static Varlist
33Var_is_in_AS(const Varlist & uord, const CFList & Astar);
34
35int getAlgVar(const CanonicalForm &f, Variable &X)
36{
37  if (f.inBaseDomain()) return 0;
38  if (f.inCoeffDomain())
39  {
40    if (f.level()!=0)
41    {
42      X= f.mvar();
43      return 1;
44    }
45    return getAlgVar(f.LC(),X);
46  }
47  if (f.inPolyDomain())
48  {
49    if (getAlgVar(f.LC(),X)) return 1;
50    for( CFIterator i=f; i.hasTerms(); i++)
51    {
52      if (getAlgVar(i.coeff(),X)) return 1;
53    }
54  }
55  return 0;
56}
57
58////////////////////////////////////////////////////////////////////////
59// This implements the algorithm of Trager for factorization of
60// (multivariate) polynomials over algebraic extensions and so called
61// function field extensions.
62////////////////////////////////////////////////////////////////////////
63
64// // missing class: IntGenerator:
65bool IntGenerator::hasItems() const
66{
67    return 1;
68}
69
70CanonicalForm IntGenerator::item() const
71//int IntGenerator::item() const
72{
73  //return current; //CanonicalForm( current );
74  return mapinto(CanonicalForm( current ));
75}
76
77void IntGenerator::next()
78{
79    current++;
80}
81
82// replacement for factory's broken psr
83static CanonicalForm
84mypsr ( const CanonicalForm &rr, const CanonicalForm &vv, const Variable & x ){
85  CanonicalForm r=rr, v=vv, l, test, lu, lv, t, retvalue;
86  int dr, dv, d,n=0;
87
88
89  dr = degree( r, x );
90  dv = degree( v, x );
91  if (dv <= dr) {l=LC(v,x); v = v -l*power(x,dv);}
92  else { l = 1; }
93  d= dr-dv+1;
94  while ( ( dv <= dr  ) && ( r != r.genZero()) ){
95    test = power(x,dr-dv)*v*LC(r,x);
96    if ( dr == 0 ) { r= CanonicalForm(0); }
97    else { r= r - LC(r,x)*power(x,dr); }
98    r= l*r -test;
99    dr= degree(r,x);
100    n+=1;
101  }
102  r= power(l, d-n)*r;
103  return r;
104}
105
106// replacement for factory's broken resultant
107static CanonicalForm
108resultante( const CanonicalForm & f, const CanonicalForm& g, const Variable & v ){
109return resultant(f,g,v);
110
111  CanonicalForm h, beta, help, F, G;
112  int delta;
113
114  DEBOUTLN( cout, "resultante: called  f= ", f);
115  DEBOUTLN( cout, "resultante: called  g= ", g);
116  DEBOUTLN( cout, "resultante: called  v= ", v);
117  if ( f.mvar() < v || g.mvar() < v ){
118    DEBOUTMSG(cout, "resultante: f.mvar() < v || g.mvar() < v");
119    return 1;
120  }
121
122  if ( f.degree( v ) < 1 || g.degree( v ) < 1 ){
123    DEBOUTMSG(cout, "resultante: f.degree( v ) < 1 || g.degree( v ) < 1");
124    // If deg(F,v) == 0 , then resultante(F,G,v) = F^n, where n=deg(G,v)
125    if ( f.degree( v ) < 1 ) return power(f,degree(g,v));
126    else return power(g,degree(f,v));
127  }
128
129   if ( f.degree( v ) >= g.degree( v ) ) { F = f; G = g; }
130   else { G = f; F = g; }
131
132  h = CanonicalForm(1);
133  while ( G != G.genZero() ) {
134     delta= degree(F,v) -degree(G,v);
135     beta = power(CanonicalForm(-1), delta+1) * LC(F,v)* power(h, delta);
136     h= (h * power(LC(G,v), delta)) / power(h, delta);
137     help= G;
138     G= mypsr(F,G,v);
139     G= G/beta;
140     F=help;
141   }
142   if ( degree(F,v) != 0 ) F= CanonicalForm(0);
143   return F;
144}
145
146// sqr-free routine for algebraic extensions
147// we need it! Ex.: f=c^2+2*a*c-1; as=[a^2+1]; f=(c+a)^2
148static CFFList
149alg_sqrfree( const CanonicalForm & f ){
150  CFFList L;
151
152  L.append(CFFactor(f,1));
153  return L;
154}
155
156// Calculates a square free norm
157// Input: f(x, alpha) a square free polynomial over K(alpha),
158// alpha is defined by the minimal polynomial Palpha
159// K has more than S elements (S is defined in thesis; look getextension)
160static void
161sqrf_norm_sub( const CanonicalForm & f, const CanonicalForm & PPalpha,
162           CFGenerator & myrandom, CanonicalForm & s,  CanonicalForm & g,
163           CanonicalForm & R){
164  Variable y=PPalpha.mvar(),vf=f.mvar();
165  CanonicalForm temp, Palpha=PPalpha, t;
166  int sqfreetest=0;
167  CFFList testlist;
168  CFFListIterator i;
169
170  DEBOUTLN(cout, "sqrf_norm_sub:      f= ", f);
171  DEBOUTLN(cout, "sqrf_norm_sub: Palpha= ", Palpha);
172  myrandom.reset();   s=f.mvar()-myrandom.item()*Palpha.mvar();   g=f;
173  R= CanonicalForm(0);
174  DEBOUTLN(cout, "sqrf_norm_sub: myrandom s= ", s);
175
176  // Norm, resultante taken with respect to y
177  while ( !sqfreetest ){
178    DEBOUTLN(cout, "sqrf_norm_sub: Palpha= ", Palpha);
179    R = resultante(Palpha, g, y); R= R* bCommonDen(R);
180    DEBOUTLN(cout, "sqrf_norm_sub: R= ", R);
181    // sqfree check ; R is a polynomial in K[x]
182    if ( getCharacteristic() == 0 )
183    {
184      temp= gcd(R, R.deriv(vf));
185      DEBOUTLN(cout, "sqrf_norm_sub: temp= ", temp);
186      if (degree(temp,vf) != 0 || temp == temp.genZero() ){ sqfreetest= 0; }
187      else { sqfreetest= 1; }
188      DEBOUTLN(cout, "sqrf_norm_sub: sqfreetest= ", sqfreetest);
189    }
190    else{
191      DEBOUTMSG(cout, "Starting SqrFreeTest(R)!");
192      // Look at SqrFreeTest!
193      // (z+a^5+w)^4 with z<w<a should not give sqfreetest=1 !
194      // for now we use this workaround with Factorize...
195      // ...but it should go away soon!!!!
196      testlist= Factorize(R);
197      DEBOUTLN(cout, "testlist= ", testlist);
198      testlist.removeFirst();
199      sqfreetest=1;
200      for ( i=testlist; i.hasItem(); i++)
201        if ( i.getItem().exp() > 1 && degree(i.getItem().factor(), R.mvar()) > 0) { sqfreetest=0; break; }
202      DEBOUTLN(cout, "SqrFreeTest(R)= ", sqfreetest);
203    }
204    if ( ! sqfreetest ){
205      myrandom.next();
206      DEBOUTLN(cout, "sqrf_norm_sub generated new myrandom item: ", myrandom.item());
207      if ( getCharacteristic() == 0 ) t= CanonicalForm(mapinto(myrandom.item()));
208      else t= CanonicalForm(myrandom.item());
209      s= f.mvar()+t*Palpha.mvar(); // s defines backsubstitution
210      DEBOUTLN(cout, "sqrf_norm_sub: testing s= ", s);
211      g= f(f.mvar()-t*Palpha.mvar(), f.mvar());
212      DEBOUTLN(cout, "             gives g= ", g);
213    }
214  }
215}
216
217static void
218sqrf_norm( const CanonicalForm & f, const CanonicalForm & PPalpha,
219           const Variable & Extension, CanonicalForm & s,  CanonicalForm & g,
220           CanonicalForm & R){
221
222  DEBOUTLN(cout, "sqrf_norm:      f= ", f);
223  DEBOUTLN(cout, "sqrf_norm: Palpha= ", PPalpha);
224  if ( getCharacteristic() == 0 ) {
225    IntGenerator myrandom;
226    DEBOUTMSG(cout, "sqrf_norm: no extension, char=0");
227    sqrf_norm_sub(f,PPalpha, myrandom, s,g,R);
228    DEBOUTLN(cout, "sqrf_norm:      f= ", f);
229    DEBOUTLN(cout, "sqrf_norm: Palpha= ", PPalpha);
230    DEBOUTLN(cout, "sqrf_norm:      s= ", s);
231    DEBOUTLN(cout, "sqrf_norm:      g= ", g);
232    DEBOUTLN(cout, "sqrf_norm:      R= ", R);
233  }
234  else if ( degree(Extension) > 0 ){ // working over Extensions
235    DEBOUTLN(cout, "sqrf_norm: degree of extension is ", degree(Extension));
236    AlgExtGenerator myrandom(Extension);
237    sqrf_norm_sub(f,PPalpha, myrandom, s,g,R);
238  }
239  else{
240    FFGenerator myrandom;
241    DEBOUTMSG(cout, "sqrf_norm: degree of extension is 0");
242    sqrf_norm_sub(f,PPalpha, myrandom, s,g,R);
243  }
244}
245
246static Varlist
247Var_is_in_AS(const Varlist & uord, const CFList & Astar){
248  Varlist output;
249  CanonicalForm elem;
250  Variable x;
251
252  for ( VarlistIterator i=uord; i.hasItem(); i++){
253    x=i.getItem();
254    for ( CFListIterator j=Astar; j.hasItem(); j++ ){
255      elem= j.getItem();
256      if ( degree(elem,x) > 0 ){ // x actually occures in Astar
257        output.append(x);
258        break;
259      }
260    }
261  }
262  return output;
263}
264
265// Look if Minimalpolynomials in Astar define seperable Extensions
266// Must be a power of p: i.e. y^{p^e}-x
267static int
268inseperable(const CFList & Astar){
269  CanonicalForm elem;
270  int Counter= 1;
271
272  if ( Astar.length() == 0 ) return 0;
273  for ( CFListIterator i=Astar; i.hasItem(); i++){
274    elem= i.getItem();
275    if ( elem.deriv() == elem.genZero() ) return Counter;
276    else Counter += 1;
277  }
278  return 0;
279}
280
281// calculate gcd of f and g in char=0
282static CanonicalForm
283gcd0( CanonicalForm f, CanonicalForm g ){
284  int charac= getCharacteristic();
285  setCharacteristic(0); Off(SW_RATIONAL);
286  CanonicalForm ff= mapinto(f), gg= mapinto(g);
287  CanonicalForm result= gcd(ff,gg);
288  setCharacteristic(charac); On(SW_RATIONAL);
289  return mapinto(result);
290}
291
292// calculate big enough extension for finite fields
293// Idea: first calculate k, such that q^k > S (->thesis, -> getextension)
294// Second, search k with gcd(k,m_i)=1, where m_i is the degree of the i'th
295// minimal polynomial. Then the minpoly f_i remains irrd. over q^k and we
296// have enough elements to plug in.
297static int
298getextension( IntList & degreelist, int n){
299  int charac= getCharacteristic();
300  setCharacteristic(0); // need it for k !
301  int k=1, m=1, length=degreelist.length();
302  IntListIterator i;
303
304  for (i=degreelist; i.hasItem(); i++) m= m*i.getItem();
305  int q=charac;
306  while (q <= ((n*m)*(n*m)/2)) { k= k+1; q= q*charac;}
307  int l=0;
308  do {
309    for (i=degreelist; i.hasItem(); i++){
310      l= l+1;
311      if ( gcd0(k,i.getItem()) == 1){
312        DEBOUTLN(cout, "getextension: gcd == 1, l=",l);
313        if ( l==length ){ setCharacteristic(charac);  return k; }
314      }
315      else { DEBOUTMSG(cout, "getextension: Next iteration"); break; }
316    }
317    k= k+1; l=0;
318  }
319  while ( 1 );
320}
321
322// calculate a "primitive element"
323// K must have more than S elements (->thesis, -> getextension)
324static CFList
325simpleextension(const CFList & Astar, const Variable & Extension,
326                CanonicalForm & R){
327  CFList Returnlist, Bstar=Astar;
328  CanonicalForm s, g;
329
330  DEBOUTLN(cout, "simpleextension: Astar= ", Astar);
331  DEBOUTLN(cout, "simpleextension:     R= ", R);
332  DEBOUTLN(cout, "simpleextension: Extension= ", Extension);
333  if ( Astar.length() == 1 ){ R= Astar.getFirst();}
334  else{
335    R=Bstar.getFirst(); Bstar.removeFirst();
336    for ( CFListIterator i=Bstar; i.hasItem(); i++){
337      DEBOUTLN(cout, "simpleextension: f(x)= ", i.getItem());
338      DEBOUTLN(cout, "simpleextension: P(x)= ", R);
339      sqrf_norm(i.getItem(), R, Extension, s, g, R);
340      // spielt die Repraesentation eine Rolle?
341      // muessen wir die Nachfolger aendern, wenn s != 0 ?
342      DEBOUTLN(cout, "simpleextension: g= ", g);
343      if ( s != 0 ) DEBOUTLN(cout, "simpleextension: s= ", s);
344      else DEBOUTLN(cout, "simpleextension: s= ", s);
345      DEBOUTLN(cout, "simpleextension: R= ", R);
346      Returnlist.insert(s);
347    }
348  }
349
350  return Returnlist;
351}
352
353// the heart of the algorithm: the one from Trager
354static CFFList
355alg_factor( const CanonicalForm & f, const CFList & Astar, const Variable & vminpoly, const Varlist & oldord, const CFList & as){
356  CFFList L, Factorlist;
357  CanonicalForm R, Rstar, s, g, h;
358  CFList substlist;
359
360  DEBINCLEVEL(cout,"alg_factor");
361  DEBOUTLN(cout, "alg_factor: f= ", f);
362  substlist= simpleextension(Astar, vminpoly, Rstar);
363  DEBOUTLN(cout, "alg_factor: substlist= ", substlist);
364  DEBOUTLN(cout, "alg_factor: minpoly Rstar= ", Rstar);
365  DEBOUTLN(cout, "alg_factor: vminpoly= ", vminpoly);
366
367  sqrf_norm(f, Rstar, vminpoly, s, g, R );
368  DEBOUTLN(cout, "alg_factor: g= ", g);
369  DEBOUTLN(cout, "alg_factor: s= ", s);
370  DEBOUTLN(cout, "alg_factor: R= ", R);
371  Off(SW_RATIONAL);
372  Variable X;
373  if (getAlgVar(R,X))
374  {
375    // factorize R over alg.extension with X
376//cout << "alg: "<< X << " mipo=" << getMipo(X,Variable('X')) <<endl;
377    if (R.isUnivariate())
378      Factorlist =  factorize( R, X );
379    else
380    {
381      #if 1
382      Variable XX;
383      CanonicalForm mipo=getMipo(X,XX);
384      CFList as(mipo);
385      Factorlist = newfactoras(R, as , 1);
386      #else
387      // factor R over k
388      Factorlist = Factorize(R);
389      #endif
390    }
391  }
392  else
393  {
394    // factor R over k
395    Factorlist = Factorize(R);
396  }
397  On(SW_RATIONAL);
398  DEBOUTLN(cout, "alg_factor: Factorize(R)= ", Factorlist);
399  if ( !Factorlist.getFirst().factor().inCoeffDomain() )
400    Factorlist.insert(CFFactor(1,1));
401  if ( Factorlist.length() == 2 && Factorlist.getLast().exp()== 1){ // irreduzibel (first entry is a constant)
402    L.append(CFFactor(f,1));
403  }
404  else{
405    DEBOUTLN(cout, "alg_factor: g= ", g);
406    CanonicalForm gnew= g(s,s.mvar());
407    DEBOUTLN(cout, "alg_factor: gnew= ", gnew);
408    g=gnew;
409    for ( CFFListIterator i=Factorlist; i.hasItem(); i++){
410      CanonicalForm fnew=i.getItem().factor();
411      fnew= fnew(s,s.mvar());
412      DEBOUTLN(cout, "alg_factor: fnew= ", fnew);
413      DEBOUTLN(cout, "alg_factor: substlist= ", substlist);
414      for ( CFListIterator ii=substlist; ii.hasItem(); ii++){
415        DEBOUTLN(cout, "alg_factor: item= ", ii.getItem());
416        fnew= fnew(ii.getItem(), ii.getItem().mvar());
417        DEBOUTLN(cout, "alg_factor: fnew= ", fnew);
418      }
419      if (degree(i.getItem().factor()) > 0 ){
420        // undo linear transformation!!!! and then gcd!
421        //cout << "algcd(" << g << "," << fnew << ",as" << as << ")" << endl;
422        h= algcd(g,fnew, as, oldord);
423        //cout << "algcd result:" << h << endl;
424        DEBOUTLN(cout, "  alg_factor: h= ", h);
425        DEBOUTLN(cout, "  alg_factor: oldord= ", oldord);
426        if ( degree(h) > 0 ){ //otherwise it's a constant
427          g= divide(g, h,as);
428          DEBOUTLN(cout, "alg_factor: g/h= ", g);
429          DEBOUTLN(cout, "alg_factor: s= ", s);
430          DEBOUTLN(cout, "alg_factor: substlist= ", substlist);
431          L.append(CFFactor(h,1));
432        }
433      }
434    }
435    // we are not interested in a
436    // constant (over K_r, which can be a polynomial!)
437    if (degree(g, f.mvar())>0){ L.append(CFFactor(g,1)); }
438  }
439  DEBOUTLN(cout, "alg_factor: L= ", L);
440  DEBDECLEVEL(cout,"alg_factor");
441  return L;
442}
443
444static CFFList
445endler( const CanonicalForm & f, const CFList & AS, const Varlist & uord ){
446  CanonicalForm F=f, g, q,r;
447  CFFList Output;
448  CFList One, Two, asnew, as=AS;
449  CFListIterator i,ii;
450  VarlistIterator j;
451  Variable vg;
452
453  for (i=as; i.hasItem(); i++){
454    g= i.getItem();
455    if (g.deriv() == 0 ){
456      DEBOUTLN(cout, "Inseperable extension detected: ", g);
457      for (j=uord; j.hasItem(); j++){
458        if ( degree(g,j.getItem()) > 0 ) vg= j.getItem();
459      }
460      // Now we have the highest transzendental in vg;
461      DEBOUTLN(cout, "Transzendental is ", vg);
462      CanonicalForm gg=-1*g[0];
463      divrem(gg,vg,q,r); r= gg-q*vg;   gg= gg-r;
464      //DEBOUTLN(cout, "q= ", q); DEBOUTLN(cout, "r= ", r);
465      DEBOUTLN(cout, "  that is ", gg);
466      DEBOUTLN(cout, "  maps to ", g+gg);
467      One.insert(gg); Two.insert(g+gg);
468      // Now transform all remaining polys in as:
469      int x=0;
470      for (ii=i; ii.hasItem(); ii++){
471        if ( x != 0 ){
472          divrem(ii.getItem(), gg, q,r);
473//          cout << ii.getItem() << " divided by " << gg << endl;
474          DEBOUTLN(cout, "q= ", q); DEBOUTLN(cout, "r= ", r);
475          ii.append(ii.getItem()+q*g); ii.remove(1);
476          DEBOUTLN(cout, "as= ", as);
477        }
478        x+= 1;
479      }
480      // Now transform F:
481      divrem(F, gg, q,r);
482      F= F+q*g;
483      DEBOUTLN(cout, "new F= ", F);
484    }
485    else{ asnew.append(i.getItem());  }// just the identity
486  }
487  // factor F with minimal polys given in asnew:
488  DEBOUTLN(cout, "Factor F=  ", F);
489  DEBOUTLN(cout, "  with as= ", asnew);
490  int success=0;
491  CFFList factorlist= newcfactor(F,asnew, success);
492  DEBOUTLN(cout, "  gives =  ", factorlist);
493  DEBOUTLN(cout, "One= ", One);
494  DEBOUTLN(cout, "Two= ", Two);
495
496  // Transform back:
497  for ( CFFListIterator k=factorlist; k.hasItem(); k++){
498    CanonicalForm factor= k.getItem().factor();
499    ii=One;
500    for (i=Two; i.hasItem(); i++){
501      DEBOUTLN(cout, "Mapping ", i.getItem());
502      DEBOUTLN(cout, "     to ", ii.getItem());
503      DEBOUTLN(cout, "     in ", factor);
504      divrem(factor,i.getItem(),q,r); r=factor -q*i.getItem();
505      DEBOUTLN(cout, "q= ", q); DEBOUTLN(cout, "r= ", r);
506      factor= ii.getItem()*q +r; //
507      ii++;
508    }
509    Output.append(CFFactor(factor,k.getItem().exp()));
510  }
511
512  return Output;
513}
514
515
516// 1) prepares data
517// 2) for char=p we distinguish 3 cases:
518//           no transcendentals, seperable and inseperable extensions
519CFFList
520newfactoras( const CanonicalForm & f, const CFList & as, int success){
521  Variable vf=f.mvar();
522  CFListIterator i;
523  CFFListIterator jj;
524  CFList reduceresult;
525  CFFList result;
526
527  success=1;
528  DEBINCLEVEL(cout, "newfactoras");
529  DEBOUTMSG(cerr, rcsid);
530  DEBOUTLN(cout, "newfactoras called with f= ", f);
531  DEBOUTLN(cout, "               content(f)= ", content(f));
532  DEBOUTLN(cout, "                       as= ", as);
533  DEBOUTLN(cout, "newfactoras: cls(vf)= ", cls(vf));
534  DEBOUTLN(cout, "newfactoras: cls(as.getLast())= ", cls(as.getLast()));
535  DEBOUTLN(cout, "newfactoras: degree(f,vf)= ", degree(f,vf));
536
537// F1: [Test trivial cases]
538// 1) first trivial cases:
539  if ( (cls(vf) <= cls(as.getLast())) ||  degree(f,vf)<=1 ){
540// ||( (as.length()==1) && (degree(f,vf)==3) && (degree(as.getFirst()==2)) )
541    DEBDECLEVEL(cout,"newfactoras");
542    return CFFList(CFFactor(f,1));
543  }
544
545// 2) List of variables:
546// 2a) Setup list of those polys in AS having degree(AS[i], AS[i].mvar()) > 1
547// 2b) Setup variableordering
548  CFList Astar;
549  Variable x;
550  CanonicalForm elem;
551  Varlist ord, uord,oldord;
552  for ( int ii=1; ii< level(vf) ; ii++ ) { uord.append(Variable(ii));  }
553  oldord= uord; oldord.append(vf);
554
555  for ( i=as; i.hasItem(); i++ ){
556    elem= i.getItem();
557    x= elem.mvar();
558    if ( degree(elem,x) > 1){ // otherwise it's not an extension
559      //if ( degree(f,x) > 0 ){ // does it occure in f? RICHTIG?
560        Astar.append(elem);
561        ord.append(x);
562        //}
563    }
564  }
565  uord= Difference(uord,ord);
566  DEBOUTLN(cout, "Astar is: ", Astar);
567  DEBOUTLN(cout, "ord is: ", ord);
568  DEBOUTLN(cout, "uord is: ", uord);
569
570// 3) second trivial cases: we already prooved irr. of f over no extensions
571  if ( Astar.length() == 0 ){
572    DEBDECLEVEL(cout,"newfactoras");
573    return CFFList(CFFactor(f,1));
574  }
575
576// 4) Try to obtain a partial factorization using prop2 and prop3
577//    Use with caution! We have to proof these propositions first!
578  // Not yet implemented
579
580// 5) Look if elements in uord actually occure in any of the minimal
581//    polynomials. If no element of uord occures in any of the minimal
582//   polynomials, we don't have transzendentals.
583  Varlist newuord=Var_is_in_AS(uord,Astar);
584  DEBOUTLN(cout, "newuord is: ", newuord);
585
586  CFFList Factorlist;
587  Varlist gcdord= Union(ord,newuord); gcdord.append(f.mvar());
588  // This is for now. we need alg_sqrfree implemented!
589  //cout << "algcd(" << f << "," << f.deriv() << " as:" << Astar <<endl;
590  CanonicalForm Fgcd= algcd(f,f.deriv(),Astar,gcdord);
591 // cout << "algcd result:"  << Fgcd << endl;
592  if ( Fgcd == 0 ) DEBOUTMSG(cerr, "WARNING: p'th root ?");
593  if ( degree(Fgcd, f.mvar()) > 0 ){
594    DEBOUTLN(cout, "Nontrivial GCD found of ", f);
595    CanonicalForm Ggcd= divide(f, Fgcd,Astar);
596    DEBOUTLN(cout, "  split into ", Fgcd);
597    DEBOUTLN(cout, "         and ", Ggcd);
598    Fgcd= pp(Fgcd); Ggcd= pp(Ggcd);
599    DEBDECLEVEL(cout,"newfactoras");
600    return myUnion(newfactoras(Fgcd,as,success) , newfactoras(Ggcd,as,success));
601  }
602  if ( getCharacteristic() > 0 ){
603
604    // First look for extension!
605    IntList degreelist;
606    Variable vminpoly;
607    for (i=Astar; i.hasItem(); i++){degreelist.append(degree(i.getItem()));}
608    int extdeg= getextension(degreelist, degree(f));
609    DEBOUTLN(cout, "Extension needed of degree ", extdeg);
610
611    // Now the real stuff!
612    if ( newuord.length() == 0 ){ // no transzendentals
613      DEBOUTMSG(cout, "No transzendentals!");
614      if ( extdeg > 1 ){
615        CanonicalForm MIPO= generate_mipo( extdeg, vminpoly);
616        DEBOUTLN(cout, "Minpoly produced ", MIPO);
617        vminpoly= rootOf(MIPO);
618      }
619      Factorlist= alg_factor(f, Astar, vminpoly, oldord, as);
620      DEBDECLEVEL(cout,"newfactoras");
621      return Factorlist;
622    }
623    else if ( inseperable(Astar) > 0 ){ // Look if extensions are seperable
624      // a) Use Endler
625      DEBOUTMSG(cout, "Inseperable extensions! Using Endler!");
626      CFFList templist= endler(f,Astar, newuord);
627      DEBOUTLN(cout, "Endler gives: ", templist);
628      return templist;
629    }
630    else{ // we are on the save side: Use trager
631      DEBOUTMSG(cout, "Only seperable extensions!");
632      if (extdeg > 1 ){
633        CanonicalForm MIPO=generate_mipo(extdeg, vminpoly );
634        vminpoly= rootOf(MIPO);
635        DEBOUTLN(cout, "Minpoly generated: ", MIPO);
636        DEBOUTLN(cout, "vminpoly= ", vminpoly);
637        DEBOUTLN(cout, "degree(vminpoly)= ", degree(vminpoly));
638      }
639      Factorlist= alg_factor(f, Astar, vminpoly, oldord, as);
640      DEBDECLEVEL(cout,"newfactoras");
641      return Factorlist;
642      ;
643    }
644  }
645  else{ // char=0 apply trager directly
646    DEBOUTMSG(cout, "Char=0! Apply Trager!");
647    Variable vminpoly;
648    Factorlist= alg_factor(f, Astar, vminpoly, oldord, as);
649      DEBDECLEVEL(cout,"newfactoras");
650      return Factorlist;
651    ;
652  }
653
654  DEBDECLEVEL(cout,"newfactoras");
655  return CFFList(CFFactor(f,1));
656}
657
658CFFList
659newcfactor(const CanonicalForm & f, const CFList & as, int success ){
660  Off(SW_RATIONAL);
661  CFFList Output, output, Factors=Factorize(f); On(SW_RATIONAL);
662  Factors.removeFirst();
663
664  if ( as.length() == 0 ){ success=1; return Factors;}
665  if ( cls(f) <= cls(as.getLast()) ) { success=1; return Factors;}
666
667  success=1;
668  for ( CFFListIterator i=Factors; i.hasItem(); i++ ){
669    output=newfactoras(i.getItem().factor(),as, success);
670    for ( CFFListIterator j=output; j.hasItem(); j++)
671      Output = myappend(Output,CFFactor(j.getItem().factor(),j.getItem().exp()*i.getItem().exp()));
672  }
673  return Output;
674}
675
676/*
677$Log: not supported by cvs2svn $
678Revision 1.7  2001/06/27 13:58:05  Singular
679*hannes/GP: debug newfactoras, char_series, ...
680
681Revision 1.6  2001/06/21 14:57:04  Singular
682*hannes/GP: Factorize, newfactoras, ...
683
684Revision 1.5  2001/06/18 08:44:39  pfister
685* hannes/GP/michael: factory debug, Factorize
686
687Revision 1.4  1998/05/25 18:32:38  obachman
6881998-05-25  Olaf Bachmann  <obachman@mathematik.uni-kl.de>
689
690        * charset/alg_factor.cc: replaced identifiers 'random' by
691        'myrandom' to avoid name conflicts with the built-in (stdlib)
692        library function 'random' which might be a macro -- and, actually
693        is  under gcc v 2.6.3
694
695Revision 1.3  1998/03/12 12:34:24  schmidt
696        * charset/csutil.cc, charset/alg_factor.cc: all references to
697          `common_den()' replaced by `bCommonDen()'
698
699Revision 1.2  1997/09/12 07:19:37  Singular
700* hannes/michael: libfac-0.3.0
701
702*/
Note: See TracBrowser for help on using the repository browser.