1 | //////////////////////////////////////////////////////////// |
---|
2 | // emacs edit mode for this file is -*- C++ -*- |
---|
3 | //////////////////////////////////////////////////////////// |
---|
4 | // FACTORY - Includes |
---|
5 | #include <factory.h> |
---|
6 | // Factor - Includes |
---|
7 | #include "tmpl_inst.h" |
---|
8 | // some CC's need this: |
---|
9 | #include "helpstuff.h" |
---|
10 | |
---|
11 | bool |
---|
12 | mydivremt ( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b ) |
---|
13 | { |
---|
14 | bool retvalue; |
---|
15 | CanonicalForm aa,bb; |
---|
16 | retvalue = divremt(f,g,a,bb); |
---|
17 | aa= f-g*a; |
---|
18 | if ( aa==bb ) { b=bb; } |
---|
19 | else { b=aa; } |
---|
20 | return retvalue; |
---|
21 | } |
---|
22 | |
---|
23 | // Now some procedures used in SqrFree and in Factor |
---|
24 | /////////////////////////////////////////////////////////////// |
---|
25 | /////////////////////////////////////////////////////////////// |
---|
26 | // We have to include a version of <CFFList>.append(CFFactor)// |
---|
27 | // and Union( CFFList, CFFList) // |
---|
28 | // because we have to look for multiplicities in SqrFree. // |
---|
29 | // e.g.: SqrFree( f^3 ) with char <> 3 // |
---|
30 | /////////////////////////////////////////////////////////////// |
---|
31 | CFFList |
---|
32 | myappend( const CFFList & Inputlist, const CFFactor & TheFactor) |
---|
33 | { |
---|
34 | CFFList Outputlist ; |
---|
35 | CFFactor copy; |
---|
36 | CFFListIterator i; |
---|
37 | int exp=0; |
---|
38 | |
---|
39 | for ( i=Inputlist ; i.hasItem() ; i++ ) |
---|
40 | { |
---|
41 | copy = i.getItem(); |
---|
42 | if ( copy.factor() == TheFactor.factor() ) |
---|
43 | exp += copy.exp(); |
---|
44 | else |
---|
45 | Outputlist.append(copy); |
---|
46 | } |
---|
47 | Outputlist.append( CFFactor(TheFactor.factor(), exp + TheFactor.exp())); |
---|
48 | return Outputlist; |
---|
49 | } |
---|
50 | |
---|
51 | CFFList |
---|
52 | myUnion(const CFFList & Inputlist1,const CFFList & Inputlist2) |
---|
53 | { |
---|
54 | CFFList Outputlist; |
---|
55 | CFFListIterator i; |
---|
56 | |
---|
57 | for ( i=Inputlist1 ; i.hasItem() ; i++ ) |
---|
58 | Outputlist = myappend(Outputlist, i.getItem() ); |
---|
59 | for ( i=Inputlist2 ; i.hasItem() ; i++ ) |
---|
60 | Outputlist = myappend(Outputlist, i.getItem() ); |
---|
61 | |
---|
62 | return Outputlist; |
---|
63 | } |
---|
64 | |
---|
65 | int |
---|
66 | Powerup( const int base , const int exp) |
---|
67 | { |
---|
68 | int retvalue=1; |
---|
69 | if ( exp == 0 ) return retvalue ; |
---|
70 | else for ( int i=1 ; i <= exp; i++ ) retvalue *= base ; |
---|
71 | |
---|
72 | return retvalue; |
---|
73 | } |
---|
74 | |
---|
75 | // Now some procedures used in MVMultiHensel and in Truefactors |
---|
76 | /////////////////////////////////////////////////////////////// |
---|
77 | |
---|
78 | /////////////////////////////////////////////////////////////// |
---|
79 | // mod_power: Return f mod I^k, where I is now the ideal // |
---|
80 | // {x_1, .. x_(level(f)-1)}. Computation mod I^k is simply // |
---|
81 | // done by dropping all the terms of degree >= k in // |
---|
82 | // x_1, .. x_(level(f)-1); e.g. x_1*x_2 == 0 mod I^2 . // |
---|
83 | // modpower: the real work is done here; called by mod_power // |
---|
84 | /////////////////////////////////////////////////////////////// |
---|
85 | static void |
---|
86 | modpower( const CanonicalForm & f, int k , int td, |
---|
87 | const CanonicalForm & t, CanonicalForm & result) |
---|
88 | { |
---|
89 | |
---|
90 | if ( td >= k ) return; |
---|
91 | if ( getNumVars(f) == 0 ) result += f*t; |
---|
92 | else{ |
---|
93 | Variable x(level(f)); |
---|
94 | for ( CFIterator i=f; i.hasTerms(); i++) |
---|
95 | modpower(i.coeff(),k,td+i.exp(),t*power(x,i.exp()),result); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | CanonicalForm |
---|
100 | mod_power( const CanonicalForm & f, int k, int levelU) |
---|
101 | { |
---|
102 | CanonicalForm result,dummy; |
---|
103 | Variable x(levelU); |
---|
104 | |
---|
105 | if ( levelU > level(f) ) |
---|
106 | modpower(f,k,0,1,result); |
---|
107 | else |
---|
108 | { |
---|
109 | for ( CFIterator i=f; i.hasTerms(); i++) |
---|
110 | { |
---|
111 | dummy = 0; |
---|
112 | modpower(i.coeff(),k,0,1,dummy); |
---|
113 | result += dummy * power(x,i.exp()); |
---|
114 | // the following works, but is slower |
---|
115 | // int degf=degree(f); |
---|
116 | // for ( int i=0; i<=degf;i++){ |
---|
117 | // result+= mod_power(f[i],k,levelU)*power(x,i); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | return result; |
---|
122 | } |
---|
123 | |
---|
124 | /////////////////////////////////////////////////////////////// |
---|
125 | // Return the deg of F in the Variables x_1,..,x_(levelF-1) // |
---|
126 | /////////////////////////////////////////////////////////////// |
---|
127 | int |
---|
128 | subvardegree( const CanonicalForm & F, int levelF ) |
---|
129 | { |
---|
130 | int n=0,m=degree(F,levelF),newn=0; |
---|
131 | |
---|
132 | for ( int k=0; k<=m; k++ ) |
---|
133 | { |
---|
134 | newn = totaldegree( F[k] ); |
---|
135 | if ( newn > n ) n=newn; |
---|
136 | } |
---|
137 | return n; |
---|
138 | } |
---|
139 | |
---|
140 | /////////////////////////////////////////////////////////////// |
---|
141 | // Change poly: x_i <- x_i +- a_i for i= 1,..,level(f)-1 // |
---|
142 | /////////////////////////////////////////////////////////////// |
---|
143 | CanonicalForm |
---|
144 | change_poly( const CanonicalForm & f , const SFormList & Substitutionlist ,int directionback ) |
---|
145 | { |
---|
146 | CanonicalForm F=f,g,k; |
---|
147 | int level_i; |
---|
148 | // Variable x; |
---|
149 | |
---|
150 | for ( SFormListIterator i=Substitutionlist; i.hasItem(); i++) |
---|
151 | { |
---|
152 | // now we can access: i.getItem().factor() -> level(~) gives x_i |
---|
153 | // i.getItem().exp() -> gives a_i |
---|
154 | // ==> g = x_i ; k = a_i |
---|
155 | level_i=level(i.getItem().factor()); |
---|
156 | g = power( |
---|
157 | Variable(level_i),1 |
---|
158 | ); |
---|
159 | k= i.getItem().exp(); |
---|
160 | if ( directionback ) |
---|
161 | { |
---|
162 | if ( degree(F, level_i) != 0 ) |
---|
163 | F=F(g-k, level_i /*level(i.getItem().factor())*/); // x_i <-- x_i - a_i |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | if ( degree(F, level_i) != 0 ) |
---|
168 | F=F(g+k, level_i /*level(i.getItem().factor())*/); // x_i <-- x_i +a_i |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | return F; |
---|
173 | } |
---|