source: git/libfac/factor/homogfactor.cc @ d9edaf

spielwiese
Last change on this file since d9edaf was b22f61, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: removed debug code git-svn-id: file:///usr/local/Singular/svn/trunk@10668 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.8 KB
Line 
1/* Copyright 1997 Michael Messollen. All rights reserved. */
2////////////////////////////////////////////////////////////
3// $Id: homogfactor.cc,v 1.11 2008-04-09 09:41:48 Singular Exp $
4////////////////////////////////////////////////////////////
5// FACTORY - Includes
6#include <factory.h>
7#ifdef HAVE_IOSTREAM
8#include <iostream>
9#define OSTREAM std::ostream
10#define ISTREAM std::istream
11#define CERR std::cerr
12#define CIN std::cin
13#elif defined(HAVE_IOSTREAM_H)
14#include <iostream.h>
15#define OSTREAM ostream
16#define ISTREAM istream
17#define CERR cerr
18#define CIN cin
19#endif
20
21// Factor - Includes
22#include "tmpl_inst.h"
23#include "Factor.h"
24// some CC's need it:
25#include "homogfactor.h"
26
27void out_cf(char *s1,const CanonicalForm &f,char *s2);
28
29CFFList Factorize2(CanonicalForm F, const CanonicalForm & minpoly );
30
31#ifdef HFACTORDEBUG
32#  define DEBUGOUTPUT
33#else
34#  undef DEBUGOUTPUT
35#endif
36
37#include "debug.h"
38#include "timing.h"
39TIMING_DEFINE_PRINT(hfactorize_time);
40
41#if 0
42///////////////////////////////////////////////////////////////
43// get_Terms: Split the polynomial in the containing terms.  //
44// getTerms: the real work is done here.                     //
45///////////////////////////////////////////////////////////////
46static void
47getTerms( const CanonicalForm & f, const CanonicalForm & t, CFList & result ){
48
49  if ( getNumVars(f) == 0 ) result.append(f*t);
50  else{
51    Variable x(level(f));
52    for ( CFIterator i=f; i.hasTerms(); i++ )
53      getTerms( i.coeff(), t*power(x,i.exp()), result);
54  }
55}
56
57CFList
58get_Terms( const CanonicalForm & f ){
59  CFList result,dummy,dummy2;
60  CFIterator i;
61  CFListIterator j;
62
63  if ( getNumVars(f) == 0 ) result.append(f);
64  else{
65    Variable _x(level(f));
66    for ( i=f; i.hasTerms(); i++ ){
67      getTerms(i.coeff(), 1, dummy);
68      for ( j=dummy; j.hasItem(); j++ )
69        result.append(j.getItem() * power(_x, i.exp()));
70
71      dummy= dummy2; // have to initalize new
72    }
73  }
74  return result;
75}
76#endif
77
78#if 0
79///////////////////////////////////////////////////////////////
80// is_homogeneous returns 1 iff f is homogeneous, 0 otherwise//
81///////////////////////////////////////////////////////////////
82bool
83is_homogeneous( const CanonicalForm & f){
84  CFList termlist= get_Terms(f);
85  CFListIterator i;
86  int deg= totaldegree(termlist.getFirst());
87
88  for ( i=termlist; i.hasItem(); i++ )
89    if ( totaldegree(i.getItem()) != deg ) return 0;
90  return 1;
91  // now: return f.isHomogeneous();
92}
93#endif
94
95#if 0
96///////////////////////////////////////////////////////////////
97// get_max_degree_Variable returns Variable with             //
98// highest degree. We assume f is *not* a constant!          //
99///////////////////////////////////////////////////////////////
100static Variable
101get_max_degree_Variable(const CanonicalForm & f){
102  ASSERT( ( ! f.inCoeffDomain() ), "no constants" );
103  int max=0, maxlevel=0, n=level(f);
104  for ( int i=1; i<=n; i++ )
105    if (degree(f,Variable(i)) >= max) {
106      max= degree(f,Variable(i)); maxlevel= i;
107    }
108  return Variable(maxlevel);
109}
110#endif
111
112#if 0
113///////////////////////////////////////////////////////////////
114// homogenize homogenizes f with Variable x                  //
115///////////////////////////////////////////////////////////////
116static CanonicalForm
117homogenize( const CanonicalForm & f, const Variable & x){
118  CFList Newlist, Termlist= get_Terms(f);
119  int maxdeg=totaldegree(f), deg;
120  CFListIterator i;
121  CanonicalForm elem, result=f.genZero();
122 
123  for (i=Termlist; i.hasItem(); i++){
124    elem= i.getItem();
125    deg = totaldegree(elem);
126    if ( deg < maxdeg )
127      Newlist.append(elem * power(x,maxdeg-deg));
128    else
129      Newlist.append(elem);
130  }
131  for (i=Newlist; i.hasItem(); i++) // rebuild
132    result += i.getItem();
133   
134  return result;
135}
136#endif
137
138// we assume g is square-free
139CFFList
140HomogFactor( const CanonicalForm & g, const CanonicalForm  & minpoly, const int Mainvar )
141{
142  DEBINCLEVEL(CERR, "HomogFactor");
143  Variable xn = get_max_degree_Variable(g);
144  //out_cf("HomogFactor:",g,"\n");
145  int d_xn = degree(g,xn);
146  CanonicalForm F = g(1,xn);
147
148  DEBOUTLN(CERR, "xn= ", xn);
149  DEBOUTLN(CERR, "d_xn=   ", d_xn);
150  DEBOUTLN(CERR, "F= ", F); 
151  //out_cf("HomogFactor:subst ",F,"\n");
152
153  // should we do this for low degree polys g ? e.g. quadratic?
154  //
155  CFFList Intermediatelist;
156  CFFList Homoglist;
157  CFFListIterator j;
158  if ( getCharacteristic() > 0 )
159  {
160     CFMap n;
161     if (minpoly.isZero())
162       Intermediatelist = Factorize(compress(F,n), 1);
163     else
164       Intermediatelist = Factorized(compress(F,n), minpoly, Mainvar);
165     for ( j=Intermediatelist; j.hasItem(); j++ )
166       Homoglist.append(CFFactor( n(j.getItem().factor()), j.getItem().exp()) );
167  }
168  else
169  {
170     if (minpoly.isZero())
171       Homoglist = factorize(F);
172     else
173       Homoglist = Factorize2(F,minpoly);
174  }
175  // Now we have uncompressed factors in Homoglist
176  DEBOUTLN(CERR, "F factors as: ", Homoglist);
177  CFFList Unhomoglist;
178  CanonicalForm unhomogelem;
179  if ((!(minpoly.isZero())) &&(getCharacteristic() == 0) )
180  {
181    for ( j=Homoglist; j.hasItem(); j++ )
182    {
183      // assume that minpoly.level() < level of all "real" variables of g
184      DEBOUTLN(CERR, "Homogenizing ",j.getItem().factor()); 
185      unhomogelem= homogenize(j.getItem().factor(),xn,
186                         Variable(minpoly.level()+1),g.mvar());
187      DEBOUTLN(CERR, "      that is ", unhomogelem);
188      Unhomoglist.append(CFFactor(unhomogelem,j.getItem().exp()));
189      d_xn -= degree(unhomogelem,xn)*j.getItem().exp();
190    }
191  }
192  else
193  {
194    for ( j=Homoglist; j.hasItem(); j++ )
195    {
196      DEBOUTLN(CERR, "Homogenizing ",j.getItem().factor()); 
197      unhomogelem= homogenize(j.getItem().factor(),xn);
198      DEBOUTLN(CERR, "      that is ", unhomogelem);
199      //out_cf("unhomogelem:",unhomogelem,"\n");
200      Unhomoglist.append(CFFactor(unhomogelem,j.getItem().exp()));
201      d_xn -= degree(unhomogelem,xn)*j.getItem().exp();
202    }
203  }
204  DEBOUTLN(CERR, "Power of xn to append is ", d_xn);
205  if ( d_xn != 0 ) // have to append xn^(d_xn)
206    Unhomoglist.append(CFFactor(CanonicalForm(xn),d_xn));
207
208  DEBDECLEVEL(CERR, "HomogFactor");
209  return Unhomoglist;
210}
211
212/*
213$Log: not supported by cvs2svn $
214Revision 1.10  2008/04/08 16:19:10  Singular
215*hannes: removed rcsid
216
217Revision 1.9  2008/03/18 17:46:16  Singular
218*hannes: gcc 4.2
219
220Revision 1.8  2007/10/25 14:45:41  Singular
221*hannes: homgfactor for alg.ext of Q
222
223Revision 1.7  2006/05/16 14:46:50  Singular
224*hannes: gcc 4.1 fixes
225
226Revision 1.6  2005/12/09 08:36:11  Singular
227*hannes: stuff for homog. polys ->factory
228
229Revision 1.5  2005/12/05 15:47:32  Singular
230*hannes: is_homogeneous -> factory: isHomogeneous
231
232Revision 1.4  2002/08/19 11:11:34  Singular
233* hannes/pfister: alg_gcd etc.
234
235Revision 1.3  1997/09/12 07:19:57  Singular
236* hannes/michael: libfac-0.3.0
237
238Revision 1.2  1997/04/25 22:35:20  michael
239changed cerr and cout messages for use with Singular
240Version for libfac-0.2.1
241
242Revision 1.1  1997/01/17 05:05:48  michael
243Initial revision
244
245*/
Note: See TracBrowser for help on using the repository browser.