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