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