Révision 138 pobysoC-4.0/src/pobyso.c
pobyso.c (revision 138) | ||
---|---|---|
83 | 83 |
/* Todo: change verbosity suppression strategy with a message call back. */ |
84 | 84 |
pobyso_set_verbosity_off(); |
85 | 85 |
test = sollya_lib_get_constant(dummy, obj_to_test); |
86 |
mpfr_clear(dummy); |
|
87 | 86 |
pobyso_set_verbosity_to(initial_verbosity_level); |
88 |
return test; |
|
89 |
} /* End pobyso_is_constant_expression. */ |
|
90 |
|
|
91 |
/** @see pobyso.h#pobyso_is_free_var_int_poson_power. */ |
|
92 |
int |
|
93 |
pobyso_is_free_var_posze_int_power(sollya_obj_t objToTestSo) |
|
94 |
{ |
|
95 |
int arity; |
|
96 |
sollya_base_function_t headTypeSo; |
|
97 |
sollya_obj_t sub1So = NULL; |
|
98 |
sollya_obj_t sub2So = NULL; |
|
99 |
|
|
100 |
/* Argument check. */ |
|
101 |
if (objToTestSo == NULL) |
|
87 |
if (test) |
|
102 | 88 |
{ |
103 |
pobyso_error_message("pobyso_is_free_var_int_poson_power", |
|
104 |
"NULL_POINTER_ARGUMENT", |
|
105 |
"The expression is a NULL pointer"); |
|
106 |
return 0; |
|
89 |
if(mpfr_number_p(dummy)) |
|
90 |
{ |
|
91 |
mpfr_clear(dummy); |
|
92 |
return test; |
|
93 |
} |
|
94 |
else |
|
95 |
{ |
|
96 |
mpfr_clear(dummy); |
|
97 |
return 0; |
|
98 |
} |
|
107 | 99 |
} |
108 |
if (! sollya_lib_obj_is_function(objToTestSo))
|
|
100 |
else
|
|
109 | 101 |
{ |
110 | 102 |
return 0; |
111 | 103 |
} |
112 |
if (!sollya_lib_get_head_function(&headTypeSo, objToTestSo)) return 0; |
|
113 |
if (! sollya_lib_get_subfunctions(objToTestSo, |
|
114 |
&arity, |
|
115 |
&sub1So, |
|
116 |
&sub2So, |
|
117 |
NULL)) return 0; |
|
118 |
/* Power function: arity == 2. */ |
|
119 |
if (arity != 2) return 0; |
|
120 |
if (! pobyso_is_constant_expression(sub1So)) return 0; |
|
121 |
return 1; |
|
122 |
} /* End pobyso_is_free_var_posze_int_power. */ |
|
104 |
} /* End pobyso_is_constant_expression. */ |
|
123 | 105 |
|
124 |
|
|
125 | 106 |
/** @see pobyso.h#pobyso_is_monomial. */ |
126 | 107 |
int |
127 | 108 |
pobyso_is_int(pobyso_func_exp_t exprSo) |
... | ... | |
196 | 177 |
} |
197 | 178 |
else |
198 | 179 |
{ |
199 |
pobyso_autoprint(exprSo); |
|
200 |
pobyso_autoprint(newConstantSo); |
|
201 | 180 |
mpfr_clear(float1M); |
202 | 181 |
mpfr_clear(float2M); |
203 | 182 |
sollya_lib_clear_obj(newConstantSo); |
... | ... | |
213 | 192 |
int |
214 | 193 |
pobyso_is_monomial(sollya_obj_t objSo) |
215 | 194 |
{ |
195 |
int arity; |
|
196 |
sollya_obj_t subFun1So = NULL; |
|
197 |
sollya_obj_t subFun2So = NULL; |
|
198 |
sollya_obj_t subFun3So = NULL; |
|
199 |
sollya_base_function_t head = 0; |
|
200 |
long int exponent = 0; |
|
201 |
long int exprIntValue = 0; |
|
202 |
|
|
203 |
/* Arguments check. */ |
|
204 |
if (objSo == NULL) |
|
205 |
{ |
|
206 |
pobyso_error_message("pobyso_is_monomial", |
|
207 |
"NULL_POINTER_ARGUMENT", |
|
208 |
"The expression is a NULL pointer"); |
|
209 |
return 0; |
|
210 |
} |
|
211 |
/* The object must be a function. */ |
|
212 |
if (! sollya_lib_obj_is_function(objSo)) return 0; |
|
213 |
/* Check if it is the 1 constant. */ |
|
214 |
if (pobyso_is_int(objSo)) |
|
215 |
{ |
|
216 |
if (! sollya_lib_get_constant_as_int64(&exprIntValue, objSo)) |
|
217 |
{ |
|
218 |
return 0; |
|
219 |
} |
|
220 |
else |
|
221 |
{ |
|
222 |
if (exprIntValue == 1) return 1; |
|
223 |
else return 0; |
|
224 |
} |
|
225 |
} |
|
226 |
if (! sollya_lib_decompose_function(objSo, |
|
227 |
&head, |
|
228 |
&arity, |
|
229 |
&subFun1So, |
|
230 |
&subFun2So, |
|
231 |
NULL)) return 0; |
|
232 |
if (arity > 2) |
|
233 |
{ |
|
234 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
235 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
236 |
return 0; |
|
237 |
} |
|
238 |
/* Arity == 1 must be free variable by itself. */ |
|
239 |
if (arity == 1 && head == SOLLYA_BASE_FUNC_FREE_VARIABLE) |
|
240 |
{ |
|
241 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
242 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
243 |
return 1; |
|
244 |
} |
|
245 |
else |
|
246 |
{ |
|
247 |
/* Another expression. Must be: free variable ^ poze integer. */ |
|
248 |
if (arity == 2) |
|
249 |
{ |
|
250 |
if (head != SOLLYA_BASE_FUNC_POW) |
|
251 |
{ |
|
252 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
253 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
254 |
return 0; |
|
255 |
} |
|
256 |
if (! pobyso_is_int(subFun2So)) |
|
257 |
{ |
|
258 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
259 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
260 |
return 0; |
|
261 |
} |
|
262 |
if (! sollya_lib_get_constant_as_int64(&exponent, subFun2So)) |
|
263 |
{ |
|
264 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
265 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
266 |
return 0; |
|
267 |
} |
|
268 |
if (exponent < 0) |
|
269 |
{ |
|
270 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
271 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
272 |
return 0; |
|
273 |
} |
|
274 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
275 |
/* Check that the first subfunction is the free variable. */ |
|
276 |
if (! sollya_lib_decompose_function(subFun1So, |
|
277 |
&head, |
|
278 |
&arity, |
|
279 |
&subFun2So, |
|
280 |
&subFun3So, |
|
281 |
NULL)) |
|
282 |
{ |
|
283 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
284 |
return 0; |
|
285 |
} |
|
286 |
if (arity == 1 && head == SOLLYA_BASE_FUNC_FREE_VARIABLE) |
|
287 |
{ |
|
288 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
289 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
290 |
if (subFun3So != NULL) sollya_lib_clear_obj(subFun3So); |
|
291 |
return 1; |
|
292 |
} |
|
293 |
else |
|
294 |
{ |
|
295 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
296 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
297 |
return 0; |
|
298 |
} |
|
299 |
} /* End if arity == 2. */ |
|
300 |
} /* End else if arity == 1. */ |
|
216 | 301 |
return 0; |
217 | 302 |
} /* End pobyso_is_monomial. */ |
218 | 303 |
|
304 |
/** @see pobyso.h#pobyso_is_polynomial_term. |
|
305 |
* Strategy: check that the object is a functional expression and |
|
306 |
* if so check that it is made of cte * monomial. |
|
307 |
*/ |
|
308 |
int |
|
309 |
pobyso_is_polynomial_term(sollya_obj_t objSo) |
|
310 |
{ |
|
311 |
int arity; |
|
312 |
sollya_obj_t subFun1So = NULL; |
|
313 |
sollya_obj_t subFun2So = NULL; |
|
314 |
sollya_base_function_t head = 0; |
|
315 |
|
|
316 |
/* Arguments check. */ |
|
317 |
if (objSo == NULL) |
|
318 |
{ |
|
319 |
pobyso_error_message("pobyso_is_polynomial_term", |
|
320 |
"NULL_POINTER_ARGUMENT", |
|
321 |
"The expression is a NULL pointer"); |
|
322 |
return 0; |
|
323 |
} |
|
324 |
/* The object must be a function. */ |
|
325 |
if (! sollya_lib_obj_is_function(objSo)) return 0; |
|
326 |
/* A constant expression is degree 0 polynomial term. */ |
|
327 |
if (pobyso_is_constant_expression(objSo)) return 1; |
|
328 |
/* A monomial is a polynomial term. */ |
|
329 |
if (pobyso_is_monomial(objSo)) return 1; |
|
330 |
/* Decompose the functional expression and study the elements. */ |
|
331 |
if (! sollya_lib_decompose_function(objSo, |
|
332 |
&head, |
|
333 |
&arity, |
|
334 |
&subFun1So, |
|
335 |
&subFun2So, |
|
336 |
NULL)) return 0; |
|
337 |
/* Monomial case has been dealt with abobe. */ |
|
338 |
if (arity != 2) |
|
339 |
{ |
|
340 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
341 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
342 |
return 0; |
|
343 |
} |
|
344 |
/* The expression must be: cte * monomial or monomial * cte. */ |
|
345 |
if (head != SOLLYA_BASE_FUNC_MUL) |
|
346 |
{ |
|
347 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
348 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
349 |
return 0; |
|
350 |
} |
|
351 |
if (! pobyso_is_monomial(subFun2So)) |
|
352 |
{ |
|
353 |
if (! pobyso_is_constant_expression(subFun2So) || |
|
354 |
! pobyso_is_monomial(subFun1So)) |
|
355 |
{ |
|
356 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
357 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
358 |
return 0; |
|
359 |
} |
|
360 |
} |
|
361 |
else |
|
362 |
{ |
|
363 |
if (! pobyso_is_constant_expression(subFun1So)) |
|
364 |
{ |
|
365 |
if (subFun1So != NULL) sollya_lib_clear_obj(subFun1So); |
|
366 |
if (subFun2So != NULL) sollya_lib_clear_obj(subFun2So); |
|
367 |
return 0; |
|
368 |
} |
|
369 |
} |
|
370 |
return 1; |
|
371 |
} /* End pobyso_is_polynomial_term. */ |
|
219 | 372 |
/** @see pobyso.h#pobyso_new_monomial. */ |
220 | 373 |
pobyso_func_exp_t |
221 | 374 |
pobyso_new_monomial(pobyso_func_exp_t coefficientSo, long degree) |
Formats disponibles : Unified diff