1 | //////////////////////////////////////////////////////////// |
---|
2 | // emacs edit mode for this file is -*- C++ -*- |
---|
3 | //////////////////////////////////////////////////////////// |
---|
4 | /* $Id$ */ |
---|
5 | //////////////////////////////////////////////////////////// |
---|
6 | // FACTORY - Includes |
---|
7 | #include <factory.h> |
---|
8 | // Factor - Includes |
---|
9 | #include <tmpl_inst.h> |
---|
10 | #include <Factor.h> |
---|
11 | #include <helpstuff.h> |
---|
12 | // Charset - Includes |
---|
13 | #include "csutil.h" |
---|
14 | #include "charset.h" |
---|
15 | #include "reorder.h" |
---|
16 | #include "alg_factor.h" |
---|
17 | // some CC's need this: |
---|
18 | #include "algfactor.h" |
---|
19 | |
---|
20 | #ifdef ALGFACTORDEBUG |
---|
21 | # define DEBUGOUTPUT |
---|
22 | #else |
---|
23 | # undef DEBUGOUTPUT |
---|
24 | #endif |
---|
25 | |
---|
26 | #include "debug.h" |
---|
27 | #include "timing.h" |
---|
28 | TIMING_DEFINE_PRINT(newfactoras_time); |
---|
29 | |
---|
30 | int hasVar(const CanonicalForm &f, const Variable &v); |
---|
31 | |
---|
32 | static CFFList |
---|
33 | myminus( const CFFList & Inputlist, const CFFactor & TheFactor){ |
---|
34 | CFFList Outputlist ; |
---|
35 | CFFactor copy; |
---|
36 | |
---|
37 | for ( CFFListIterator i=Inputlist ; i.hasItem() ; i++ ){ |
---|
38 | copy = i.getItem(); |
---|
39 | if ( copy.factor() != TheFactor.factor() ){ |
---|
40 | Outputlist.append( copy ); |
---|
41 | } |
---|
42 | } |
---|
43 | return Outputlist; |
---|
44 | } |
---|
45 | |
---|
46 | static CFFList |
---|
47 | myDifference(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. |
---|
58 | static int |
---|
59 | isquasilinear( 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 | } |
---|
67 | return 1; |
---|
68 | } |
---|
69 | |
---|
70 | #ifdef CHARSETNADEBUG |
---|
71 | # define DEBUGOUTPUT |
---|
72 | #else |
---|
73 | # undef DEBUGOUTPUT |
---|
74 | #endif |
---|
75 | #include "debug.h" |
---|
76 | static CFList |
---|
77 | charsetnA(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 "debug.h" |
---|
126 | // compute the GCD of f and g over the algebraic field having |
---|
127 | // adjoing ascending set as |
---|
128 | CanonicalForm |
---|
129 | algcd(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 | } |
---|