Révision 237 pobysoPythonSage/src/pobyso.py
pobyso.py (revision 237) | ||
---|---|---|
132 | 132 |
|
133 | 133 |
def pobyso_build_end_elliptic_list_so_so(*args): |
134 | 134 |
""" |
135 |
From argumrny Sollya objects, create a Sollya end elliptic list.
|
|
136 |
Elements of the list are "eaten" (should not be cleared individualy, |
|
135 |
From Sollya argument objects, create a Sollya end elliptic list.
|
|
136 |
Elements of the list are "eaten" (should not be cleared individually,
|
|
137 | 137 |
are cleared when the list is cleared). |
138 | 138 |
""" |
139 | 139 |
if len(args) == 0: |
... | ... | |
153 | 153 |
# End pobyso_build_end_elliptic_list_so_so |
154 | 154 |
|
155 | 155 |
def pobyso_build_function_sub_so_so(exp1So, exp2So): |
156 |
return(sollya_lib_build_function_sub(exp1So, exp2So))
|
|
156 |
return sollya_lib_build_function_sub(exp1So, exp2So)
|
|
157 | 157 |
|
158 |
def pobyso_build_list_of_ints_sa_so(*args): |
|
159 |
""" |
|
160 |
Build a Sollya list from Sage integral arguments. |
|
161 |
""" |
|
162 |
if len(args) == 0: |
|
163 |
return pobyso_build_list_so_so() |
|
164 |
## Make a Sage list of integral constants. |
|
165 |
intsList = [] |
|
166 |
for intElem in args: |
|
167 |
intsList.append(pobyso_constant_from_int_sa_so(intElem)) |
|
168 |
return pobyso_build_list_so_so(*intsList) |
|
169 |
|
|
170 |
def pobyso_build_list_so_so(*args): |
|
171 |
""" |
|
172 |
Make a Sollya list out of Sollya objects passed as arguments. |
|
173 |
If one wants to call it with a list argument, should prepend a "*" |
|
174 |
before the list variable name. |
|
175 |
Elements of the list are "eaten" (should not be cleared individually, |
|
176 |
are cleared when the list is cleared). |
|
177 |
""" |
|
178 |
if len(args) == 0: |
|
179 |
## Called with an empty list produced "error". |
|
180 |
return sollya_lib_build_list(None) |
|
181 |
index = 0 |
|
182 |
## Append the Sollya elements one by one. |
|
183 |
for elementSo in args: |
|
184 |
if index == 0: |
|
185 |
listSo = sollya_lib_build_list(elementSo, None) |
|
186 |
else: |
|
187 |
listSo = sollya_lib_append(listSo, elementSo) |
|
188 |
index += 1 |
|
189 |
return listSo |
|
190 |
# End pobyso_build list_so_so |
|
191 |
|
|
192 |
|
|
158 | 193 |
def pobyso_change_var_in_function_so_so(funcSo, chvarExpSo): |
159 | 194 |
""" |
160 | 195 |
Variable change in a function. |
... | ... | |
167 | 202 |
return(resultSo) |
168 | 203 |
# End pobyso_chebyshevform_so_so. |
169 | 204 |
|
205 |
def pobyso_clear_obj(objSo): |
|
206 |
""" |
|
207 |
Free a Sollya object's memory. |
|
208 |
Very thin wrapper around sollya_lib_clear_obj(). |
|
209 |
""" |
|
210 |
sollya_lib_clear_obj(objSo) |
|
211 |
# End pobyso_clear_obj. |
|
212 |
|
|
170 | 213 |
def pobyso_clear_taylorform_sa_so(taylorFormSaSo): |
171 | 214 |
""" |
172 | 215 |
This method is necessary to correctly clean up the memory from Taylor forms. |
... | ... | |
174 | 217 |
For no clearly understood reason, sollya_lib_clear_object_list crashed |
175 | 218 |
when applied to the object list. |
176 | 219 |
Here, we decompose it into Sage list of Sollya objects references and we |
177 |
clear them one by one.
|
|
220 |
clear them one at a time.
|
|
178 | 221 |
""" |
179 | 222 |
sollya_lib_clear_obj(taylorFormSaSo[0]) |
180 | 223 |
(coefficientsErrorsListSaSo, numElementsSa, isEndEllipticSa) = \ |
... | ... | |
187 | 230 |
|
188 | 231 |
def pobyso_cmp(rnArgSa, cteSo): |
189 | 232 |
""" |
233 |
Deprecated, use pobyso_cmp_sa_so_sa instead. |
|
234 |
""" |
|
235 |
print "Deprecated, use pobyso_cmp_sa_so_sa instead." |
|
236 |
return pobyso_cmp_sa_so_sa(rnArgSa, cteSo) |
|
237 |
# End pobyso_cmp |
|
238 |
|
|
239 |
def pobyso_cmp_sa_so_sa(rnArgSa, cteSo): |
|
240 |
""" |
|
190 | 241 |
Compare the MPFR value a RealNumber with that of a Sollya constant. |
191 | 242 |
|
192 | 243 |
Get the value of the Sollya constant into a RealNumber and compare |
... | ... | |
203 | 254 |
rnLocalSa = RRRR(0) |
204 | 255 |
sollya_lib_get_constant(get_rn_value(rnLocalSa), cteSo) |
205 | 256 |
# |
206 |
## Compare the Sage RealNumber version of the Sollya constant with rnArg. |
|
207 |
return(cmp_rn_value(rnArgSa, rnLocal)) |
|
208 |
# End pobyso_smp |
|
257 |
## Compare the Sage RealNumber version of the Sollya constant with rnArg |
|
258 |
# through a direct comparison of underlying MPFR numbers. |
|
259 |
return cmp_rn_value(rnArgSa, rnLocal) |
|
260 |
# End pobyso_smp_sa_so_sa |
|
209 | 261 |
|
210 | 262 |
def pobyso_compute_pos_function_abs_val_bounds_sa_sa(funcSa, lowerBoundSa, \ |
211 | 263 |
upperBoundSa): |
... | ... | |
361 | 413 |
""" |
362 | 414 |
return sollya_lib_evaluate(funcSo, argumentSo) |
363 | 415 |
# End pobyso_evaluate_so_so. |
416 |
|
|
364 | 417 |
def pobyso_dirty_find_zeros_so_so(funcSo, rangeSo): |
365 | 418 |
""" |
366 | 419 |
Thin wrapper over sollya_lib_dirtyfindzeros() |
... | ... | |
368 | 421 |
return sollya_lib_dirtyfindzeros(funcSo, rangeSo) |
369 | 422 |
# End pobys_dirty_find_zeros |
370 | 423 |
|
424 |
def pobyso_dirty_inf_norm_so_so(funcSo, rangeSo, preSo=None): |
|
425 |
""" |
|
426 |
Thin wrapper around sollya_dirtyinfnorm(). |
|
427 |
""" |
|
428 |
# TODO: manage the precision change. |
|
429 |
|
|
430 |
return sollya_lib_dirtyinfnorm(funcSo, rangeSo) |
|
431 |
# End pobyso_dirty_inf_norm_so_so |
|
432 |
|
|
371 | 433 |
def pobyso_float_list_so_sa(listSo): |
372 | 434 |
""" |
373 | 435 |
Return a Sollya list of floating-point as a Sage list of |
... | ... | |
1134 | 1196 |
|
1135 | 1197 |
def pobyso_lib_close(): |
1136 | 1198 |
sollya_lib_close(None) |
1137 |
|
|
1199 |
|
|
1138 | 1200 |
def pobyso_name_free_variable(freeVariableNameSa): |
1139 | 1201 |
""" Legacy function. See pobyso_name_free_variable_sa_so. """ |
1140 | 1202 |
pobyso_name_free_variable_sa_so(freeVariableNameSa) |
... | ... | |
1570 | 1632 |
return(sollya_lib_remez(funcSo, degreeSo, rangeSo, weightSo, qualitySo, None)) |
1571 | 1633 |
# End pobyso_remez_canonical_so_so. |
1572 | 1634 |
|
1635 |
def pobyso_remez_exponents_list_sa_so(func, \ |
|
1636 |
exponentsList, \ |
|
1637 |
lowerBound, \ |
|
1638 |
upperBound, \ |
|
1639 |
weight = None, \ |
|
1640 |
quality = None): |
|
1641 |
""" |
|
1642 |
All arguments are Sage/Python. |
|
1643 |
The functions (func and weight) must be passed as expressions or strings. |
|
1644 |
Otherwise the function fails. |
|
1645 |
The return value is a pointer to a Sollya function. |
|
1646 |
lowerBound and upperBound mus be reals. |
|
1647 |
""" |
|
1648 |
var('zorglub') # Dummy variable name for type check only. Type of |
|
1649 |
# zorglub is "symbolic expression". |
|
1650 |
currentVariableNameSa = None |
|
1651 |
# The func argument can be of different types (string, |
|
1652 |
# symbolic expression...) |
|
1653 |
if parent(func) == parent("string"): |
|
1654 |
localFuncSa = sage_eval(func,globals()) |
|
1655 |
if len(localFuncSa.variables()) > 0: |
|
1656 |
currentVariableNameSa = localFuncSa.variables()[0] |
|
1657 |
sollya_lib_name_free_variable(str(currentVariableNameSa)) |
|
1658 |
functionSo = \ |
|
1659 |
sollya_lib_parse_string(localFuncSa._assume_str().replace('_SAGE_VAR_', '')) |
|
1660 |
# Expression test. |
|
1661 |
elif type(func) == type(zorglub): |
|
1662 |
# Until we are able to translate Sage expressions into Sollya |
|
1663 |
# expressions : parse the string version. |
|
1664 |
if len(func.variables()) > 0: |
|
1665 |
currentVariableNameSa = func.variables()[0] |
|
1666 |
sollya_lib_name_free_variable(str(currentVariableNameSa)) |
|
1667 |
functionSo = \ |
|
1668 |
sollya_lib_parse_string(func._assume_str().replace('_SAGE_VAR_', '')) |
|
1669 |
else: |
|
1670 |
return(None) |
|
1671 |
## Deal with the weight, much in the same way as with the function. |
|
1672 |
if weight is None: # No weight given -> 1. |
|
1673 |
weightSo = pobyso_constant_1_sa_so() |
|
1674 |
elif parent(weight) == parent("string"): # Weight given as string: parse it. |
|
1675 |
weightSo = sollya_lib_parse_string(func) |
|
1676 |
elif type(weight) == type(zorglub): # Weight given as symbolice expression. |
|
1677 |
functionSo = \ |
|
1678 |
sollya_lib_parse_string(weight._assume_str().replace('_SAGE_VAR_', '',100)) |
|
1679 |
else: |
|
1680 |
return(None) |
|
1681 |
rangeSo = pobyso_bounds_to_range_sa_so(lowerBound, upperBound) |
|
1682 |
if not quality is None: |
|
1683 |
qualitySo= pobyso_constant_sa_so(quality) |
|
1684 |
else: |
|
1685 |
qualitySo = None |
|
1686 |
# |
|
1687 |
## Tranform the Sage list of exponents into a Sollya list. |
|
1688 |
exponentsListSo = pobyso_build_list_of_ints_sa_so(*exponentsList) |
|
1689 |
remezPolySo = sollya_lib_remez(functionSo, \ |
|
1690 |
exponentsListSo, \ |
|
1691 |
rangeSo, \ |
|
1692 |
weightSo, \ |
|
1693 |
qualitySo, \ |
|
1694 |
None) |
|
1695 |
sollya_lib_clear_obj(functionSo) |
|
1696 |
sollya_lib_clear_obj(exponentsListSo) |
|
1697 |
sollya_lib_clear_obj(rangeSo) |
|
1698 |
sollya_lib_clear_obj(weightSo) |
|
1699 |
if not qualitySo is None: |
|
1700 |
sollya_lib_clear_obj(qualitySo) |
|
1701 |
return(remezPolySo) |
|
1702 |
# End pobyso_remez_exponentsList_sa_so |
|
1703 |
|
|
1704 |
|
|
1573 | 1705 |
def pobyso_round_coefficients_progressive_so_so(polySo, |
1574 | 1706 |
funcSo, |
1575 | 1707 |
precSo, |
... | ... | |
1743 | 1875 |
errorTypeIsNone = False |
1744 | 1876 |
# |
1745 | 1877 |
if accuracySo is None: |
1746 |
# Notice the **: we are in Pythonland! |
|
1878 |
# Notice the **: we are in Pythonland here!
|
|
1747 | 1879 |
accuracySo = pobyso_constant_sa_so(RR(2**(-40))) |
1748 | 1880 |
accuracyIsNone = True |
1749 | 1881 |
else: |
Formats disponibles : Unified diff