1 #include "def.h"
2 #include "macro.h"
3
4 INT tep_integer__faktor();
5 INT mpp_hashtable_hashtable_();
6 INT t_loop_partition();
7 OP find_tep_integer();
8 INT t_productexponent();
9
10
tep_partition__faktor_pre040202(a,b,f)11 INT tep_partition__faktor_pre040202(a,b,f) OP a,b,f;
12 {
13 INT erg = OK;
14 CTO(PARTITION,"tep_partition__faktor(1)",a);
15 CTTO(HASHTABLE,POWSYM,"tep_partition__faktor(2)",b);
16 if (S_PA_LI(a) == 0) {
17 erg += tep_integer__faktor(cons_null,b,f);
18 goto ende;
19 }
20 else if (S_PA_LI(a) == 1) {
21 erg += tep_integer__faktor(S_PA_I(a,0),b,f);
22 goto ende;
23 }
24 else {
25 /* erg += t_splitpart(a,b,f,tep_partition__faktor,mpp_hashtable_hashtable_); */
26 erg += t_loop_partition(a,b,f,tep_integer__faktor,mult_powsym_powsym, mult_apply_powsym_powsym);
27 goto ende;
28 }
29 ende:
30 ENDR("tpe_partition__faktor");
31 }
32
tep_partition__faktor(a,b,f)33 INT tep_partition__faktor(a,b,f) OP a,b,f;
34 {
35 INT erg = OK;
36 CTO(PARTITION,"tep_partition__faktor(1)",a);
37 CTTO(HASHTABLE,POWSYM,"tep_partition__faktor(2)",b);
38 if (S_PA_LI(a) == 0) {
39 erg += tep_integer__faktor(cons_null,b,f);
40 goto ende;
41 }
42 else if (S_PA_LI(a) == 1) {
43 erg += tep_integer__faktor(S_PA_I(a,0),b,f);
44 goto ende;
45 }
46 else {
47 erg += t_productexponent(a,b,f,tep_integer__faktor,find_tep_integer);
48 goto ende;
49 }
50 ende:
51 ENDR("tpe_partition__faktor");
52 }
53
54
55
tep_elmsym__faktor(a,b,f)56 INT tep_elmsym__faktor(a,b,f) OP a,b,f;
57 {
58 INT erg = OK;
59 CTTO(HASHTABLE,ELMSYM,"tep_elmsym__faktor(1)",a);
60 CTTO(HASHTABLE,POWSYM,"tep_elmsym__faktor(2)",b);
61 T_FORALL_MONOMIALS_IN_A(a,b,f,tep_partition__faktor);
62 ENDR("tep_elmsym__faktor");
63 }
64
65
tep_hashtable__faktor(a,b,f)66 INT tep_hashtable__faktor(a,b,f) OP a,b,f;
67 {
68 INT erg = OK;
69 CTO(HASHTABLE,"tep_hashtable__faktor(1)",a);
70 CTTO(HASHTABLE,POWSYM,"tep_hashtable__faktor(2)",b);
71 T_FORALL_MONOMIALS_IN_A(a,b,f,tep_partition__faktor);
72 ENDR("tep_hashtable__faktor");
73 }
74
75
tep___faktor(a,b,f)76 INT tep___faktor(a,b,f) OP a,b,f;
77 {
78 INT erg = OK;
79 CTTTTO(INTEGER,HASHTABLE,PARTITION,ELMSYM,"tep___faktor(1)",a);
80 CTTO(HASHTABLE,POWSYM,"tep___faktor(2)",b);
81
82 if (S_O_K(a) == INTEGER)
83 {
84 tep_integer__faktor(a,b,f);
85 goto ende;
86 }
87 else if (S_O_K(a) == PARTITION)
88 {
89 tep_partition__faktor(a,b,f);
90 goto ende;
91 }
92 else if (S_O_K(a) == HASHTABLE)
93 {
94 tep_hashtable__faktor(a,b,f);
95 goto ende;
96 }
97 else if (S_O_K(a) == ELMSYM)
98 {
99 tep_elmsym__faktor(a,b,f);
100 goto ende;
101 }
102 ende:
103 ENDR("tep___faktor");
104 }
105
106 static OP tep_sp=NULL;
107
tep_ende()108 INT tep_ende()
109 {
110 INT erg = OK;
111 if (tep_sp != NULL)
112 {
113 FREEALL(tep_sp);
114 }
115 tep_sp = NULL;
116 ENDR("tep_ende");
117 }
118
find_tep_integer(a)119 OP find_tep_integer(a) OP a;
120 /* AK 040202 */
121 {
122 INT erg = OK;
123 CTO(INTEGER,"find_tep_integer(1)",a);
124 SYMCHECK((S_I_I(a) < 0), "find_tep_integer:parameter < 0");
125
126 if (
127 (tep_sp == NULL)
128 ||
129 (S_I_I(a) >= S_V_LI(tep_sp))
130 ||
131 (EMPTYP(S_V_I(tep_sp,S_I_I(a))))
132 )
133 {
134 OP c;
135 NEW_HASHTABLE(c);
136 erg += tep_integer__faktor(a,c,cons_eins);
137 FREEALL(c);
138 }
139 return S_V_I(tep_sp,S_I_I(a));
140
141 ENDO("find_tep_integer");
142 }
143
tep_integer__faktor(a,b,f)144 INT tep_integer__faktor(a,b,f) OP a,b,f;
145 {
146 INT erg = OK;
147 CTO(INTEGER,"tep_integer__faktor(1)",a);
148 CTTO(HASHTABLE,POWSYM,"tep_integer__faktor(2)",b);
149 SYMCHECK((S_I_I(a) < 0), "tep_integer__faktor:parameter < 0");
150
151 /* first check on the stored result */
152 if (tep_sp == NULL) NEW_VECTOR(tep_sp,100);
153 if (S_I_I(a) >= S_V_LI(tep_sp))
154 erg += inc_vector_co(tep_sp, S_I_I(a) - S_V_LI(tep_sp)+5);
155 if (not EMPTYP(S_V_I(tep_sp, S_I_I(a) ) ) )
156 {
157 OP m,c;
158 FORALL(c,S_V_I(tep_sp, S_I_I(a)), {
159 m = CALLOCOBJECT();
160 erg += b_sk_mo(CALLOCOBJECT(),CALLOCOBJECT(),m);
161 MULT(S_MO_K(c), f, S_MO_K(m));
162 erg += copy_partition(S_MO_S(c),S_MO_S(m));
163 INSERT_POWSYMMONOM_(m,b);
164 });
165 goto ende;
166 }
167
168 /* now we know */
169 /* the result is not stored */
170
171 if (S_I_I(a) == 0) {
172 OP m;
173 m = CALLOCOBJECT();
174 b_sk_mo(CALLOCOBJECT(),CALLOCOBJECT(),m);
175 COPY(f,S_MO_K(m));
176 erg += first_partition(cons_null,S_MO_S(m));
177 INSERT_POWSYMMONOM_(m,b);
178
179 init_size_hashtable(S_V_I(tep_sp,0),3);
180 m = CALLOCOBJECT();
181 b_sk_mo(CALLOCOBJECT(),CALLOCOBJECT(),m);
182 M_I_I(1,S_MO_K(m));
183 erg += first_partition(cons_null,S_MO_S(m));
184 INSERT_POWSYMMONOM_(m,S_V_I(tep_sp,0));
185
186 goto ende;
187 }
188 else {
189 OP c,coeff,ergebnis,sp;
190 OP bb;
191
192
193 c=CALLOCOBJECT();
194 coeff=CALLOCOBJECT();
195 ergebnis=CALLOCOBJECT();
196 sp=CALLOCOBJECT();
197 bb=CALLOCOBJECT();
198 erg += init(HASHTABLE,bb);
199 erg += first_partition(a,c);
200 do {
201 OP d;
202 INT i;
203 m_i_i(1,sp);
204 m_i_i(1,ergebnis);
205 d = CALLOCOBJECT();
206 b_sk_mo(CALLOCOBJECT(),CALLOCOBJECT(),d);
207 COPY(c,S_MO_S(d));
208
209 /* compute coeff */
210 for (i=(INT)0; i<S_PA_LI(c);i++)
211 {
212 if (i>(INT)0)
213 {
214 if (S_PA_II(c,i) == S_PA_II(c,(i-1L)))
215 {
216 INC_INTEGER(sp);
217 MULT_APPLY_INTEGER(sp,ergebnis);
218 }
219 else M_I_I(1L,sp);
220 };
221 MULT_APPLY_INTEGER(S_PA_I(c,i),ergebnis);
222 };
223 /* in ergebnis ist der coeff, es muss durch ihn geteilt werden */
224 erg += m_ou_b(cons_eins,ergebnis,S_MO_K(d));
225 C_B_I(S_MO_K(d),GEKUERZT);
226 if ( (S_I_I(a) - S_PA_LI(c)) %2 == 1 )
227 M_I_I(-1,S_B_O(S_MO_K(d)));
228 insert_scalar_hashtable(d,bb,NULL,eq_monomsymfunc,hash_monompartition);
229
230 } while(next_apply(c));
231
232 FREEALL(c);
233 FREEALL(coeff);
234 FREEALL(ergebnis);
235 FREEALL(sp);
236
237 COPY(bb,S_V_I(tep_sp, S_I_I(a) ) );
238 MULT_APPLY(f,bb);
239
240 if (S_O_K(b) == POWSYM)
241 INSERT_LIST(bb,b,add_koeff,comp_monompowsym);
242 else
243 INSERT_HASHTABLE(bb,b,add_koeff,eq_monomsymfunc,hash_monompartition);
244 }
245 ende:
246 ENDR("tep_integer__faktor");
247 }
248
t_ELMSYM_POWSYM(a,b)249 INT t_ELMSYM_POWSYM(a,b) OP a,b;
250 /* AK 190901 */
251 {
252 INT erg = OK;
253 INT t=0;
254 CTTTTO(INTEGER,HASHTABLE,PARTITION,ELMSYM,"t_ELMSYM_POWSYM(1)",a);
255 TCE2(a,b,t_ELMSYM_POWSYM,POWSYM);
256
257 if (S_O_K(b) == EMPTY) {
258 init_hashtable(b); t=1;
259 }
260 tep___faktor(a,b,cons_eins);
261 if (t==1) t_HASHTABLE_POWSYM(b,b);
262 ENDR("t_ELMSYM_POWSYM");
263 }
264