Révision 137 pobysoC-4.0/src/pobyso.c
pobyso.c (revision 137) | ||
---|---|---|
1 | 1 |
/** @file pobyso.c |
2 |
* Name & purpose
|
|
2 |
* Integration of Sollya to C programs
|
|
3 | 3 |
* |
4 | 4 |
* @author S.T. |
5 | 5 |
* @date 2011-10-12 |
6 | 6 |
* |
7 |
* |
|
7 |
* @todo write pobyso_is_monomial function <br> |
|
8 |
* write pobyso_is_free_var_int_poson_power function |
|
8 | 9 |
*/ |
9 |
|
|
10 | 10 |
/******************************************************************************/ |
11 | 11 |
/* Headers, applying the "particular to general" convention.*/ |
12 | 12 |
|
... | ... | |
34 | 34 |
|
35 | 35 |
/* @see pobyso.h#pobyso_autoprint */ |
36 | 36 |
void |
37 |
pobyso_autoprint(sollya_obj_t solObj)
|
|
37 |
pobyso_autoprint(sollya_obj_t objSo)
|
|
38 | 38 |
{ |
39 |
sollya_lib_autoprint(solObj, NULL);
|
|
39 |
sollya_lib_autoprint(objSo, NULL);
|
|
40 | 40 |
} /* End pobyso_autoprint. */ |
41 | 41 |
|
42 | 42 |
/* @see pobyso.h#pobyso_get_verbosity */ |
... | ... | |
52 | 52 |
return verbosity; |
53 | 53 |
} /* End pobyso_get_verbosity. */ |
54 | 54 |
|
55 |
/* @see pobyso.h#pobyso_is_constant_expression*/ |
|
55 |
/** @see pobyso.h#pobyso_is_constant_expression |
|
56 |
* Strategy: rely on sollya_lib_get_constant. It return 1, when the |
|
57 |
* expression is constant. |
|
58 |
*/ |
|
56 | 59 |
int |
57 | 60 |
pobyso_is_constant_expression(sollya_obj_t obj_to_test) |
58 | 61 |
{ |
... | ... | |
63 | 66 |
/* Test argument. */ |
64 | 67 |
if (obj_to_test == NULL) |
65 | 68 |
{ |
66 |
pobyso_error_message("pobyso_parse_string",
|
|
69 |
pobyso_error_message("pobyso_is_constant_expression",
|
|
67 | 70 |
"NULL_POINTER_ARGUMENT", |
68 | 71 |
"The expression is a NULL pointer"); |
69 | 72 |
return 0; |
... | ... | |
77 | 80 |
} |
78 | 81 |
mpfr_init2(dummy,64); |
79 | 82 |
/* Call to previous Sollya function resets verbosity. */ |
83 |
/* Todo: change verbosity suppression strategy with a message call back. */ |
|
80 | 84 |
pobyso_set_verbosity_off(); |
81 | 85 |
test = sollya_lib_get_constant(dummy, obj_to_test); |
82 | 86 |
mpfr_clear(dummy); |
... | ... | |
84 | 88 |
return test; |
85 | 89 |
} /* End pobyso_is_constant_expression. */ |
86 | 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) |
|
102 |
{ |
|
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; |
|
107 |
} |
|
108 |
if (! sollya_lib_obj_is_function(objToTestSo)) |
|
109 |
{ |
|
110 |
return 0; |
|
111 |
} |
|
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. */ |
|
123 |
|
|
124 |
|
|
125 |
/** @see pobyso.h#pobyso_is_monomial. */ |
|
126 |
int |
|
127 |
pobyso_is_int(pobyso_func_exp_t exprSo) |
|
128 |
{ |
|
129 |
mpfr_t float1M; |
|
130 |
mpfr_t float2M; |
|
131 |
mpfr_t tempFloat1M; |
|
132 |
mpfr_t tempFloat2M; |
|
133 |
mpfr_prec_t prec; |
|
134 |
int64_t asInt; |
|
135 |
sollya_obj_t newConstantSo = NULL; |
|
136 |
/* Arguments check. */ |
|
137 |
if (exprSo == NULL) |
|
138 |
{ |
|
139 |
pobyso_error_message("pobyso_is_free_var_posze_int_power", |
|
140 |
"NULL_POINTER_ARGUMENT", |
|
141 |
"The expression is a NULL pointer"); |
|
142 |
return 0; |
|
143 |
} |
|
144 |
//fprintf(stdout, "Not NULL.\n"); pobyso_autoprint(exprSo); |
|
145 |
if (! pobyso_is_constant_expression(exprSo)) return 0; |
|
146 |
if (! sollya_lib_get_constant_as_int64(&asInt, exprSo)) return 0; |
|
147 |
if (asInt == INT64_MIN || asInt == INT64_MAX) return 0; |
|
148 |
/* Some constant integer expression can't have their precision computed |
|
149 |
* (e.g. cos(pi). */ |
|
150 |
if (! sollya_lib_get_prec_of_constant(&prec, exprSo)) |
|
151 |
{ |
|
152 |
mpfr_init2(tempFloat1M, 165); |
|
153 |
mpfr_init2(tempFloat2M, 165); |
|
154 |
mpfr_abs(tempFloat1M, tempFloat1M, MPFR_RNDN); |
|
155 |
mpfr_log2(tempFloat2M, tempFloat1M, MPFR_RNDU); |
|
156 |
mpfr_rint_ceil(tempFloat1M, tempFloat2M, MPFR_RNDU); |
|
157 |
prec = mpfr_get_si(tempFloat1M, MPFR_RNDN) + 10; |
|
158 |
if (prec < 1024) prec = 1024; |
|
159 |
mpfr_clear(tempFloat1M); |
|
160 |
mpfr_clear(tempFloat2M); |
|
161 |
mpfr_init2(float1M, prec); |
|
162 |
if (!sollya_lib_get_constant(float1M, exprSo)) |
|
163 |
{ |
|
164 |
mpfr_clear(float1M); |
|
165 |
return 0; |
|
166 |
} |
|
167 |
} |
|
168 |
else /* Precision could be given. */ |
|
169 |
{ |
|
170 |
mpfr_init2(float1M, prec); |
|
171 |
if (! sollya_lib_get_constant(float1M, exprSo)) |
|
172 |
{ |
|
173 |
mpfr_clear(float1M); |
|
174 |
return 0; |
|
175 |
} |
|
176 |
} |
|
177 |
if (mpfr_nan_p(float1M) || mpfr_inf_p(float1M)) |
|
178 |
{ |
|
179 |
mpfr_clear(float1M); |
|
180 |
return 0; |
|
181 |
} |
|
182 |
if ((newConstantSo = sollya_lib_constant_from_int64(asInt)) == NULL) |
|
183 |
{ |
|
184 |
mpfr_clear(float1M); |
|
185 |
return 0; |
|
186 |
} |
|
187 |
sollya_lib_get_prec_of_constant(&prec, newConstantSo); |
|
188 |
mpfr_init2(float2M, prec); |
|
189 |
sollya_lib_get_constant(float2M, newConstantSo); |
|
190 |
if (mpfr_cmp(float1M, float2M) == 0) |
|
191 |
{ |
|
192 |
mpfr_clear(float1M); |
|
193 |
mpfr_clear(float2M); |
|
194 |
sollya_lib_clear_obj(newConstantSo); |
|
195 |
return 1; |
|
196 |
} |
|
197 |
else |
|
198 |
{ |
|
199 |
pobyso_autoprint(exprSo); |
|
200 |
pobyso_autoprint(newConstantSo); |
|
201 |
mpfr_clear(float1M); |
|
202 |
mpfr_clear(float2M); |
|
203 |
sollya_lib_clear_obj(newConstantSo); |
|
204 |
return 0; |
|
205 |
} |
|
206 |
} /* End pobyso_is_int. */ |
|
207 |
|
|
208 |
/** @see pobyso.h#pobyso_is_monomial. |
|
209 |
* Strategy: check that the object is a functional expression and |
|
210 |
* if so check that it is made of cte * free_var ^ some_power where : |
|
211 |
* - cte is a constant expression (a per pobyso_is_constant_experession; |
|
212 |
* - some_power is a positive or null power. t*/ |
|
213 |
int |
|
214 |
pobyso_is_monomial(sollya_obj_t objSo) |
|
215 |
{ |
|
216 |
return 0; |
|
217 |
} /* End pobyso_is_monomial. */ |
|
218 |
|
|
87 | 219 |
/** @see pobyso.h#pobyso_new_monomial. */ |
88 | 220 |
pobyso_func_exp_t |
89 | 221 |
pobyso_new_monomial(pobyso_func_exp_t coefficientSo, long degree) |
Formats disponibles : Unified diff