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