source: git/libfac/charset/algfactor.cc @ 9d6bf4

spielwiese
Last change on this file since 9d6bf4 was 18500b, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: moved libfac back
  • Property mode set to 100644
File size: 5.1 KB
Line 
1////////////////////////////////////////////////////////////
2// emacs edit mode for this file is -*- C++ -*-
3////////////////////////////////////////////////////////////
4////////////////////////////////////////////////////////////
5// FACTORY - Includes
6#include <factory.h>
7// Factor - Includes
8#include <tmpl_inst.h>
9#include <Factor.h>
10#include <helpstuff.h>
11// Charset - Includes
12#include "csutil.h"
13#include "charset.h"
14#include "reorder.h"
15#include "alg_factor.h"
16// some CC's need this:
17#include "algfactor.h"
18
19#ifdef ALGFACTORDEBUG
20#  define DEBUGOUTPUT
21#else
22#  undef DEBUGOUTPUT
23#endif
24
25#include <libfac/factor/debug.h>
26#include "timing.h"
27TIMING_DEFINE_PRINT(newfactoras_time)
28
29int hasVar(const CanonicalForm &f, const Variable &v);
30
31static CFFList
32myminus( const CFFList & Inputlist, const CFFactor & TheFactor){
33  CFFList Outputlist ;
34  CFFactor copy;
35
36  for ( CFFListIterator i=Inputlist ; i.hasItem() ; i++ ){
37    copy = i.getItem();
38    if ( copy.factor() != TheFactor.factor() ){
39      Outputlist.append( copy );
40    }
41  }
42  return Outputlist;
43}
44
45static CFFList
46myDifference(const CFFList & Inputlist1,const CFFList & Inputlist2){
47  CFFList Outputlist=Inputlist1;
48
49  for ( CFFListIterator i=Inputlist2 ; i.hasItem() ; i++ )
50    Outputlist = myminus(Outputlist, i.getItem() );
51
52  return Outputlist;
53}
54
55
56// return 1 if as is quasilinear; 0 if not.
57static int
58isquasilinear( const CFList & as ){
59  if (as.length() <= 1) { return 1; }
60  else {
61    CFList AS=as;
62    AS.removeFirst(); // we are not interested in the first elem
63    for ( CFListIterator i=AS; i.hasItem(); i++)
64      if ( degree(i.getItem()) > 1 ) return 0;
65  }
66return 1;
67}
68
69#ifdef CHARSETNADEBUG
70#  define DEBUGOUTPUT
71#else
72#  undef DEBUGOUTPUT
73#endif
74#include <libfac/factor/debug.h>
75static CFList
76charsetnA(const CFList & AS, const CFList &PS, PremForm & Remembern, const Variable & vf ){
77  CFList QS = PS, RS = PS, Cset;
78  int nas= AS.length() +1;
79
80  DEBOUTLN(CERR, "charsetnA: called with ps= ", PS);
81  while ( ! RS.isEmpty() ) {
82    Cset = BasicSet( QS );
83    DEBOUTLN(CERR, "charsetnA: Cset= ", Cset);
84    Cset=Union(Cset,AS);
85    DEBOUTLN(CERR, "charsetnA: Cset= ", Cset);
86    Remembern.FS1 = Union(Remembern.FS1, initalset1(Cset));
87    DEBOUTLN(CERR, "charsetnA: Remembern.FS1= ", Remembern.FS1);
88    DEBOUTLN(CERR, "charsetnA: Remembern.FS2= ", Remembern.FS2);
89    RS = CFList();
90    if ( Cset.length() == nas && degree(Cset.getLast(),vf) > 0 ) {
91      CFList D = Difference( QS, Cset );
92      DEBOUT(CERR, "charsetnA: Difference( ", QS);
93      DEBOUT(CERR, " , ", Cset);
94      DEBOUTLN(CERR, " ) = ", D);
95      for ( CFListIterator i = D; i.hasItem(); ++i ) {
96        CanonicalForm r = Prem( i.getItem(), Cset );
97        DEBOUT(CERR,"charsetnA: Prem(", i.getItem()  );
98        DEBOUT(CERR, ",", Cset);
99        DEBOUTLN(CERR,") = ", r);
100        if ( r != 0 ){
101          //removefactor( r, Remembern );
102            RS=Union(RS,CFList(r));
103        }
104      }
105      if ( ! checkok(RS,Remembern.FS2)) return CFList(CanonicalForm(1));
106      DEBOUTLN(CERR, "charsetnA: RS= ", RS);
107      //QS = Union( QS, RS );
108      QS=Union(AS,RS); QS.append(Cset.getLast());
109      DEBOUTLN(CERR, "charsetnA: QS= Union(QS,RS)= ", QS);
110    }
111    else{ return CFList(CanonicalForm(1)); }
112  }
113  DEBOUTLN(CERR, "charsetnA: Removed factors: ", Remembern.FS2);
114  DEBOUTLN(CERR, "charsetnA: Remembern.FS1: ", Remembern.FS1);
115
116  return Cset;
117}
118
119#ifdef ALGFACTORDEBUG
120#  define DEBUGOUTPUT
121#else
122#  undef DEBUGOUTPUT
123#endif
124#include <libfac/factor/debug.h>
125// compute the GCD of f and g over the algebraic field having
126// adjoing ascending set as
127CanonicalForm
128algcd(const CanonicalForm & F, const CanonicalForm & g, const CFList & as, const Varlist & order){
129  CanonicalForm f=F;
130  int nas= as.length()+1; // the length the new char. set should have!
131  Variable vf=f.mvar();
132
133//   for ( VarlistIterator i=order; i.hasItem() ; i++ ){
134//     vf= i.getItem();
135//     nas--;
136//     if ( nas==0 ) break;
137//   }
138//   nas= as.length()+1;
139
140  DEBOUTLN(CERR, "algcd called with f= ", f);
141  DEBOUTLN(CERR, "                  g= ", g);
142  DEBOUTLN(CERR, "                 as= ", as);
143  DEBOUTLN(CERR, "              order= ", order);
144  DEBOUTLN(CERR, "         choosen vf= ", vf);
145
146  // check trivial case:
147  if ( degree(f, order.getLast())==0 || degree(g, order.getLast())==0)
148  {
149    DEBOUTLN(CERR, "algcd Result= ", 1);
150    return CanonicalForm(1);
151  }
152
153  CFList bs; bs.append(f); bs.append(g);
154  PremForm Remembern;
155  CFList cs=charsetnA(as,bs,Remembern,vf);
156  DEBOUTLN(CERR, "CharSetA((as,bs))= ", cs);
157
158//    for ( VarlistIterator i=order; i.hasItem() ; i++ ){
159//      DEBOUTLN(CERR, "vf= ", i.getItem());
160//      DEBOUTLN(CERR, "CharSetA((as,bs))= " , charsetnA(as,bs,Remembern,i.getItem()));
161//    }
162
163  CanonicalForm result;
164  if (cs.length()==nas)
165  {
166    result= cs.getLast();
167    CanonicalForm c=vcontent(result,Variable(1));
168    //CanonicalForm c=result.Lc();
169    result/=c;
170    for(CFListIterator i=as;i.hasItem(); i++ )
171    {
172      if(hasVar(result,i.getItem().mvar()))
173      {
174        c=vcontent(result,Variable(i.getItem().level()+1));
175        result/=c;
176      }
177    }
178  }
179  else result= CanonicalForm(1);
180  DEBOUTLN(CERR, "algcd Result= ", result);
181  return result;
182}
Note: See TracBrowser for help on using the repository browser.