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