source: git/factory/libfac/charset/algfactor.cc @ 885e76

spielwiese
Last change on this file since 885e76 was 885e76, checked in by Martin Lee <martinlee84@…>, 11 years ago
chg: commented out some unused functions
  • 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
45/* unused functions:
46static CFFList
47myDifference(const CFFList & Inputlist1,const CFFList & Inputlist2){
48  CFFList Outputlist=Inputlist1;
49
50  for ( CFFListIterator i=Inputlist2 ; i.hasItem() ; i++ )
51    Outputlist = myminus(Outputlist, i.getItem() );
52
53  return Outputlist;
54}
55
56
57// return 1 if as is quasilinear; 0 if not.
58static int
59isquasilinear( const CFList & as ){
60  if (as.length() <= 1) { return 1; }
61  else {
62    CFList AS=as;
63    AS.removeFirst(); // we are not interested in the first elem
64    for ( CFListIterator i=AS; i.hasItem(); i++)
65      if ( degree(i.getItem()) > 1 ) return 0;
66  }
67return 1;
68} */
69
70#ifdef CHARSETNADEBUG
71#  define DEBUGOUTPUT
72#else
73#  undef DEBUGOUTPUT
74#endif
75#include <libfac/factor/debug.h>
76static CFList
77charsetnA(const CFList & AS, const CFList &PS, PremForm & Remembern, const Variable & vf ){
78  CFList QS = PS, RS = PS, Cset;
79  int nas= AS.length() +1;
80
81  DEBOUTLN(CERR, "charsetnA: called with ps= ", PS);
82  while ( ! RS.isEmpty() ) {
83    Cset = BasicSet( QS );
84    DEBOUTLN(CERR, "charsetnA: Cset= ", Cset);
85    Cset=Union(Cset,AS);
86    DEBOUTLN(CERR, "charsetnA: Cset= ", Cset);
87    Remembern.FS1 = Union(Remembern.FS1, initalset1(Cset));
88    DEBOUTLN(CERR, "charsetnA: Remembern.FS1= ", Remembern.FS1);
89    DEBOUTLN(CERR, "charsetnA: Remembern.FS2= ", Remembern.FS2);
90    RS = CFList();
91    if ( Cset.length() == nas && degree(Cset.getLast(),vf) > 0 ) {
92      CFList D = Difference( QS, Cset );
93      DEBOUT(CERR, "charsetnA: Difference( ", QS);
94      DEBOUT(CERR, " , ", Cset);
95      DEBOUTLN(CERR, " ) = ", D);
96      for ( CFListIterator i = D; i.hasItem(); ++i ) {
97        CanonicalForm r = Prem( i.getItem(), Cset );
98        DEBOUT(CERR,"charsetnA: Prem(", i.getItem()  );
99        DEBOUT(CERR, ",", Cset);
100        DEBOUTLN(CERR,") = ", r);
101        if ( r != 0 ){
102          //removefactor( r, Remembern );
103            RS=Union(RS,CFList(r));
104        }
105      }
106      if ( ! checkok(RS,Remembern.FS2)) return CFList(CanonicalForm(1));
107      DEBOUTLN(CERR, "charsetnA: RS= ", RS);
108      //QS = Union( QS, RS );
109      QS=Union(AS,RS); QS.append(Cset.getLast());
110      DEBOUTLN(CERR, "charsetnA: QS= Union(QS,RS)= ", QS);
111    }
112    else{ return CFList(CanonicalForm(1)); }
113  }
114  DEBOUTLN(CERR, "charsetnA: Removed factors: ", Remembern.FS2);
115  DEBOUTLN(CERR, "charsetnA: Remembern.FS1: ", Remembern.FS1);
116
117  return Cset;
118}
119
120#ifdef ALGFACTORDEBUG
121#  define DEBUGOUTPUT
122#else
123#  undef DEBUGOUTPUT
124#endif
125#include <libfac/factor/debug.h>
126// compute the GCD of f and g over the algebraic field having
127// adjoing ascending set as
128CanonicalForm
129algcd(const CanonicalForm & F, const CanonicalForm & g, const CFList & as, const Varlist & order){
130  CanonicalForm f=F;
131  int nas= as.length()+1; // the length the new char. set should have!
132  Variable vf=f.mvar();
133
134//   for ( VarlistIterator i=order; i.hasItem() ; i++ ){
135//     vf= i.getItem();
136//     nas--;
137//     if ( nas==0 ) break;
138//   }
139//   nas= as.length()+1;
140
141  DEBOUTLN(CERR, "algcd called with f= ", f);
142  DEBOUTLN(CERR, "                  g= ", g);
143  DEBOUTLN(CERR, "                 as= ", as);
144  DEBOUTLN(CERR, "              order= ", order);
145  DEBOUTLN(CERR, "         choosen vf= ", vf);
146
147  // check trivial case:
148  if ( degree(f, order.getLast())==0 || degree(g, order.getLast())==0)
149  {
150    DEBOUTLN(CERR, "algcd Result= ", 1);
151    return CanonicalForm(1);
152  }
153
154  CFList bs; bs.append(f); bs.append(g);
155  PremForm Remembern;
156  CFList cs=charsetnA(as,bs,Remembern,vf);
157  DEBOUTLN(CERR, "CharSetA((as,bs))= ", cs);
158
159//    for ( VarlistIterator i=order; i.hasItem() ; i++ ){
160//      DEBOUTLN(CERR, "vf= ", i.getItem());
161//      DEBOUTLN(CERR, "CharSetA((as,bs))= " , charsetnA(as,bs,Remembern,i.getItem()));
162//    }
163
164  CanonicalForm result;
165  if (cs.length()==nas)
166  {
167    result= cs.getLast();
168    CanonicalForm c=vcontent(result,Variable(1));
169    //CanonicalForm c=result.Lc();
170    result/=c;
171    for(CFListIterator i=as;i.hasItem(); i++ )
172    {
173      if(hasVar(result,i.getItem().mvar()))
174      {
175        c=vcontent(result,Variable(i.getItem().level()+1));
176        result/=c;
177      }
178    }
179  }
180  else result= CanonicalForm(1);
181  DEBOUTLN(CERR, "algcd Result= ", result);
182  return result;
183}
Note: See TracBrowser for help on using the repository browser.