root / pobysoPythonSage / src / sollya_lib.sage
Historique | Voir | Annoter | Télécharger (10,89 ko)
1 | 5 | storres | import sys |
---|---|---|---|
2 | 5 | storres | from ctypes import * |
3 | 285 | storres | ## Commented out the below import since it apparently break the creation |
4 | 285 | storres | # of RealField elements from literals. |
5 | 285 | storres | #from sage.rings.real_mpfr import * |
6 | 35 | storres | # |
7 | 255 | storres | ## Load the Sollya library. |
8 | 5 | storres | try: |
9 | 263 | storres | sollya=CDLL("/usr/local/lib/libsollya.so") |
10 | 5 | storres | except : |
11 | 5 | storres | print "\nCould not find nor load the Sollya library.\n" |
12 | 5 | storres | sys.exit(1) |
13 | 35 | storres | # |
14 | 5 | storres | try: |
15 | 5 | storres | # Export the functions with their name in the library (so we can |
16 | 285 | storres | # call them without the "sollya." prefix). |
17 | 201 | storres | sollya_lib_add = sollya.sollya_lib_add |
18 | 181 | storres | sollya_lib_abs = sollya.sollya_lib_abs |
19 | 5 | storres | sollya_lib_absolute = sollya.sollya_lib_absolute |
20 | 215 | storres | sollya_lib_append = sollya.sollya_lib_append |
21 | 5 | storres | sollya_lib_autoprint = sollya.sollya_lib_autoprint |
22 | 215 | storres | sollya_lib_build_end_elliptic_list = \ |
23 | 215 | storres | sollya.sollya_lib_build_end_elliptic_list |
24 | 226 | storres | sollya_lib_build_function_abs = sollya.sollya_lib_build_function_abs |
25 | 55 | storres | sollya_lib_build_function_add = sollya.sollya_lib_build_function_add |
26 | 55 | storres | sollya_lib_build_function_div = sollya.sollya_lib_build_function_div |
27 | 5 | storres | sollya_lib_build_function_exp = sollya.sollya_lib_build_function_exp |
28 | 55 | storres | sollya_lib_build_function_free_variable = \ |
29 | 55 | storres | sollya.sollya_lib_build_function_free_variable |
30 | 55 | storres | sollya_lib_build_function_mul = sollya.sollya_lib_build_function_mul |
31 | 55 | storres | sollya_lib_build_function_pow = sollya.sollya_lib_build_function_pow |
32 | 54 | storres | sollya_lib_build_function_sub = sollya.sollya_lib_build_function_sub |
33 | 237 | storres | sollya_lib_build_list = sollya.sollya_lib_build_list |
34 | 55 | storres | sollya_lib_chebyshevform = sollya.sollya_lib_chebyshevform |
35 | 5 | storres | sollya_lib_clear_obj = sollya.sollya_lib_clear_obj |
36 | 5 | storres | sollya_lib_clear_object_list = sollya.sollya_lib_clear_object_list |
37 | 5 | storres | sollya_lib_close = sollya.sollya_lib_close |
38 | 217 | storres | sollya_lib_coeff = sollya.sollya_lib_coeff |
39 | 5 | storres | sollya_lib_constant = sollya.sollya_lib_constant |
40 | 5 | storres | sollya_lib_constant_from_int = sollya.sollya_lib_constant_from_int |
41 | 5 | storres | sollya_lib_constant_from_int64 = sollya.sollya_lib_constant_from_int64 |
42 | 201 | storres | sollya_lib_constant_from_mpq = sollya.sollya_lib_constant_from_mpq |
43 | 201 | storres | sollya_lib_constant_from_mpz = sollya.sollya_lib_constant_from_mpz |
44 | 5 | storres | sollya_lib_constant_from_uint64 = \ |
45 | 5 | storres | sollya.sollya_lib_constant_from_uint64 |
46 | 55 | storres | sollya_lib_copy_obj = sollya.sollya_lib_copy_obj |
47 | 5 | storres | sollya_lib_cos = sollya.sollya_lib_cos |
48 | 217 | storres | sollya_lib_degree = sollya.sollya_lib_degree |
49 | 241 | storres | sollya_lib_diff = sollya.sollya_lib_diff |
50 | 235 | storres | sollya_lib_dirtyfindzeros = \ |
51 | 235 | storres | sollya.sollya_lib_dirtyfindzeros |
52 | 218 | storres | sollya_lib_dirtyinfnorm = sollya.sollya_lib_dirtyinfnorm |
53 | 215 | storres | sollya_lib_end_elliptic_list= \ |
54 | 215 | storres | sollya.sollya_lib_end_elliptic_list |
55 | 155 | storres | sollya_lib_error=sollya.sollya_lib_error |
56 | 5 | storres | sollya_lib_evaluate = sollya.sollya_lib_evaluate |
57 | 261 | storres | sollya_lib_findzeros = sollya.sollya_lib_findzeros |
58 | 117 | storres | sollya_lib_free = sollya.sollya_lib_free |
59 | 5 | storres | sollya_lib_get_canonical = sollya.sollya_lib_get_canonical |
60 | 5 | storres | sollya_lib_get_constant = sollya.sollya_lib_get_constant |
61 | 5 | storres | sollya_lib_get_constant_as_int = \ |
62 | 5 | storres | sollya.sollya_lib_get_constant_as_int |
63 | 201 | storres | sollya_lib_get_constant_as_int64 = \ |
64 | 201 | storres | sollya.sollya_lib_get_constant_as_int64 |
65 | 5 | storres | sollya_lib_get_constant_as_uint64 = \ |
66 | 5 | storres | sollya.sollya_lib_get_constant_as_uint64 |
67 | 5 | storres | sollya_lib_get_free_variable_name = \ |
68 | 5 | storres | sollya.sollya_lib_get_free_variable_name |
69 | 5 | storres | sollya_lib_get_function_arity = sollya.sollya_lib_get_function_arity |
70 | 5 | storres | sollya_lib_get_head_function = sollya.sollya_lib_get_head_function |
71 | 53 | storres | sollya_lib_get_interval_from_range = \ |
72 | 53 | storres | sollya.sollya_lib_get_interval_from_range |
73 | 5 | storres | sollya_lib_get_list_elements = sollya.sollya_lib_get_list_elements |
74 | 5 | storres | sollya_lib_get_object_list_head = \ |
75 | 5 | storres | sollya.sollya_lib_get_object_list_head |
76 | 5 | storres | sollya_lib_get_object_list_tail = \ |
77 | 5 | storres | sollya.sollya_lib_get_object_list_tail |
78 | 5 | storres | sollya_lib_get_prec = sollya.sollya_lib_get_prec |
79 | 5 | storres | sollya_lib_get_prec_of_constant = sollya.sollya_lib_get_prec_of_constant |
80 | 53 | storres | sollya_lib_get_prec_of_range = sollya.sollya_lib_get_prec_of_range |
81 | 5 | storres | sollya_lib_get_subfunctions = sollya.sollya_lib_get_subfunctions |
82 | 153 | storres | sollya_lib_guessdegree = sollya.sollya_lib_guessdegree |
83 | 5 | storres | sollya_lib_head = sollya.sollya_lib_head |
84 | 56 | storres | sollya_lib_inf = sollya.sollya_lib_inf |
85 | 53 | storres | sollya_lib_infnorm = sollya.sollya_lib_infnorm |
86 | 37 | storres | sollya_lib_init= sollya.sollya_lib_init |
87 | 5 | storres | sollya_lib_is_absolute = sollya.sollya_lib_is_absolute |
88 | 116 | storres | sollya_lib_is_empty_object_list = \ |
89 | 116 | storres | sollya.sollya_lib_is_empty_object_list |
90 | 281 | storres | sollya_lib_obj_is_function = sollya.sollya_lib_obj_is_function |
91 | 85 | storres | sollya_lib_is_off = sollya.sollya_lib_is_off |
92 | 85 | storres | sollya_lib_is_on = sollya.sollya_lib_is_on |
93 | 226 | storres | sollya_lib_obj_is_range = sollya.sollya_lib_obj_is_range |
94 | 226 | storres | sollya_lib_max = sollya.sollya_lib_max |
95 | 55 | storres | sollya_lib_mid = sollya.sollya_lib_mid |
96 | 37 | storres | sollya_lib_name_free_variable = \ |
97 | 37 | storres | sollya.sollya_lib_name_free_variable |
98 | 5 | storres | sollya_lib_obj_is_function = sollya.sollya_lib_obj_is_function |
99 | 281 | storres | sollya_lib_obj_is_range = sollya.sollya_lib_obj_is_range |
100 | 281 | storres | sollya_lib_obj_is_string = sollya.sollya_lib_obj_is_string |
101 | 5 | storres | sollya_lib_obj_is_list = sollya.sollya_lib_obj_is_list |
102 | 37 | storres | sollya_lib_obj_is_error = sollya.sollya_lib_obj_is_error |
103 | 5 | storres | sollya_lib_obj_is_range = sollya.sollya_lib_obj_is_range |
104 | 5 | storres | sollya_lib_obj_is_structure = sollya.sollya_lib_obj_is_structure |
105 | 5 | storres | sollya_lib_off = sollya.sollya_lib_off |
106 | 5 | storres | sollya_lib_on = sollya.sollya_lib_on |
107 | 226 | storres | sollya_lib_max = sollya.sollya_lib_max |
108 | 5 | storres | sollya_lib_parse_string = sollya.sollya_lib_parse_string |
109 | 201 | storres | sollya_lib_precision = sollya.sollya_lib_precision |
110 | 215 | storres | sollya_lib_prepend = sollya.sollya_lib_prepend |
111 | 5 | storres | sollya_lib_range = sollya.sollya_lib_range |
112 | 162 | storres | sollya_lib_range_from_bounds = sollya.sollya_lib_range_from_bounds |
113 | 162 | storres | sollya_lib_range_from_interval = \ |
114 | 162 | storres | sollya.sollya_lib_range_from_interval |
115 | 5 | storres | sollya_lib_relative = sollya.sollya_lib_relative |
116 | 5 | storres | sollya_lib_remez = sollya.sollya_lib_remez |
117 | 215 | storres | sollya_lib_roundcoefficients = \ |
118 | 215 | storres | sollya.sollya_lib_roundcoefficients |
119 | 5 | storres | sollya_lib_set_canonical = sollya.sollya_lib_set_canonical |
120 | 5 | storres | sollya_lib_set_prec = sollya.sollya_lib_set_prec |
121 | 217 | storres | sollya_lib_sub = sollya.sollya_lib_sub |
122 | 56 | storres | sollya_lib_sup = sollya.sollya_lib_sup |
123 | 54 | storres | sollya_lib_supnorm = sollya.sollya_lib_supnorm |
124 | 35 | storres | sollya_lib_tail = sollya.sollya_lib_tail |
125 | 5 | storres | sollya_lib_taylor = sollya.sollya_lib_taylor |
126 | 5 | storres | sollya_lib_taylorform = sollya.sollya_lib_taylorform |
127 | 5 | storres | except : |
128 | 5 | storres | print "\nCould not rename one of the functions.\n" |
129 | 5 | storres | sys.exit(1) |
130 | 5 | storres | |
131 | 5 | storres | # Set the return type of several functions (those that have a return |
132 | 5 | storres | # type different from c_int or void). We consider the all the functions |
133 | 5 | storres | # returning a sollya_obj_t as returning an int. |
134 | 5 | storres | try: |
135 | 286 | storres | sollya_lib_chebyshevform.restype = c_ulong |
136 | 286 | storres | sollya_lib_constant.restype = c_ulong |
137 | 286 | storres | sollya_lib_guessdegree.restype = c_ulong |
138 | 286 | storres | sollya_lib_get_free_variable_name.restype = c_char_p |
139 | 286 | storres | sollya_lib_infnorm.restypes = c_ulong |
140 | 286 | storres | sollya_lib_parse_string.restype = c_long |
141 | 286 | storres | sollya_lib_range.restype = c_ulong |
142 | 286 | storres | sollya_lib_range_from_bounds.restype = c_ulong |
143 | 286 | storres | sollya_lib_range_from_interval.restype = c_ulong |
144 | 5 | storres | except : |
145 | 246 | storres | sys.stderr.write("\nOne of the Python-Sollya return type setting command \n") |
146 | 246 | storres | sys.stderr.write("has failed.\n\n") |
147 | 5 | storres | sys.exit(1) |
148 | 5 | storres | # |
149 | 201 | storres | # Set the argument type of several functions. Default arguments are int. |
150 | 5 | storres | # |
151 | 5 | storres | try: |
152 | 201 | storres | sollya_lib_add.argtypes = [c_ulong, c_ulong] |
153 | 215 | storres | sollya_lib_append.argstypes = [c_ulong, c_ulong] |
154 | 218 | storres | #sollya_lib_autoprint.argtypes = [c_ulong] |
155 | 201 | storres | sollya_lib_build_function_add.argtypes = [c_int, c_int] |
156 | 285 | storres | sollya_lib_chebyshevform.argtypes = [c_ulong, c_ulong] |
157 | 162 | storres | sollya_lib_constant.argtypes = [c_ulong] |
158 | 201 | storres | sollya_lib_constant_from_int64.argtypes = [c_long] |
159 | 201 | storres | sollya_lib_constant_from_mpq.argtypes = [c_ulong] |
160 | 218 | storres | sollya_lib_dirtyinfnorm.argstypes = [c_ulong, c_ulong] |
161 | 215 | storres | sollya_lib_end_elliptic_list.argtypes = [c_ulong, c_int] |
162 | 162 | storres | sollya_lib_get_constant.argtypes = [c_ulong, c_ulong] |
163 | 5 | storres | sollya_lib_get_constant_as_int.argtypes = [POINTER(c_int), c_int] |
164 | 201 | storres | sollya_lib_get_constant_as_int64.argtypes= [POINTER(c_long), c_int] |
165 | 5 | storres | sollya_lib_get_function_arity.argtypes = [POINTER(c_int), c_int] |
166 | 218 | storres | sollya_lib_get_head_function.argtypes = [POINTER(c_int), c_ulong] |
167 | 162 | storres | sollya_lib_get_interval_from_range.argtypes = [c_ulong, c_ulong] |
168 | 53 | storres | sollya_lib_get_list_elements.argtypes = [POINTER(POINTER(c_longlong)), \ |
169 | 53 | storres | POINTER(c_int),\ |
170 | 5 | storres | POINTER(c_int), c_int] |
171 | 218 | storres | sollya_lib_get_prec_of_constant.argtypes = [POINTER(c_int), c_ulong] |
172 | 53 | storres | sollya_lib_get_prec_of_range.argtypes = [POINTER(c_int), c_int] |
173 | 5 | storres | sollya_lib_get_subfunctions.argtypes = [c_int, POINTER(c_int), \ |
174 | 53 | storres | POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), \ |
175 | 53 | storres | POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), \ |
176 | 53 | storres | POINTER(c_int), POINTER(c_int)] |
177 | 162 | storres | sollya_lib_guessdegree.argtypes = [c_ulong, c_ulong, c_ulong, \ |
178 | 162 | storres | c_ulong, c_ulong] |
179 | 37 | storres | sollya_lib_name_free_variable.argtypes = [POINTER(c_char)] |
180 | 215 | storres | sollya_lib_prepend.argstypes = [c_ulong, c_ulong] |
181 | 162 | storres | sollya_lib_range.argtypes = [c_ulong, c_ulong] |
182 | 162 | storres | sollya_lib_range_from_bounds.argtypes = [c_ulong, c_ulong] |
183 | 162 | storres | sollya_lib_range_from_interval.argtypes = [c_ulong] |
184 | 283 | storres | sollya_lib_supnorm.argtypes = \ |
185 | 283 | storres | [c_ulong, c_ulong, c_ulong, c_ulong, c_ulong] |
186 | 283 | storres | sollya_lib_supnorm.restype = c_ulong |
187 | 5 | storres | except : |
188 | 286 | storres | sys.stderr.write("\nOne of the Python-Sollya arguments type setting command \n") |
189 | 246 | storres | sys.stderr.write("has failed.\n\n") |
190 | 5 | storres | sys.exit(1) |
191 | 5 | storres | # |
192 | 5 | storres | # Give it a try! |
193 | 5 | storres | # |
194 | 35 | storres | sollya |
195 | 35 | storres | sollya.sollya_lib_init(None) |
196 | 246 | storres | sys.stderr.write("\nSuperficial Sollya library check...\n") |
197 | 230 | storres | |
198 | 230 | storres | #print sollya.sollya_lib_get_free_variable_name() |
199 | 5 | storres | sollyaExp = sollya_lib_parse_string("exp(x)") |
200 | 230 | storres | #retc = sollya_lib_autoprint(sollyaExp, None) |
201 | 5 | storres | arg = sollya_lib_constant_from_int(int(1)) |
202 | 230 | storres | #print "Type of sollya_obj_t: ",type(arg), "Value: ", arg |
203 | 5 | storres | res = sollya_lib_evaluate(sollyaExp, arg) |
204 | 230 | storres | #retc = sollya_lib_autoprint(res, None) |
205 | 5 | storres | retc = sollya_lib_get_prec(None) |
206 | 5 | storres | a = c_int(0) |
207 | 5 | storres | sollya_lib_get_constant_as_int(byref(a), retc) |
208 | 230 | storres | b = a.value |
209 | 230 | storres | #print "Precision : ", a.value |
210 | 230 | storres | #print "Address of a.value ", addressof(a) |
211 | 230 | storres | #sollya_lib_close(None) |
212 | 246 | storres | sys.stderr.write("\t...Sollya library check done.\n") |
213 | 35 | storres | # |
214 | 35 | storres | # |
215 | 35 | storres | # |
216 | 5 | storres | #b = RealNumber() |
217 | 5 | storres | #print cast(retc, POINTER(c_int)).contents |
218 | 5 | storres | #retc = cast(retc, POINTER(c_int)).contents |
219 | 5 | storres | #arg = sollya_lib_constant_from_int(int(retc)) |
220 | 5 | storres | #retc = sollya_lib_autoprint(arg, None) |
221 | 91 | storres | #sollya_lib_set_prec(c_int(100)) |