Statistiques
| Révision :

root / pobysoPythonSage / src / sollya_lib.sage @ 85

Historique | Voir | Annoter | Télécharger (6,75 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 5 storres
    sollya=CDLL("/warehouse/storres/root/lib/libsollya.so")
7 5 storres
except :
8 5 storres
    print "\nCould not find nor load the Sollya library.\n"
9 5 storres
    sys.exit(1)
10 35 storres
#
11 5 storres
try:
12 5 storres
    # Export the functions with their name in the library (so we can
13 5 storres
    # use them without the "sollya." prefix).
14 5 storres
        sollya_lib_absolute = sollya.sollya_lib_absolute
15 5 storres
        sollya_lib_autoprint = sollya.sollya_lib_autoprint
16 55 storres
        sollya_lib_build_function_add = sollya.sollya_lib_build_function_add
17 55 storres
        sollya_lib_build_function_div = sollya.sollya_lib_build_function_div
18 5 storres
        sollya_lib_build_function_exp = sollya.sollya_lib_build_function_exp
19 55 storres
        sollya_lib_build_function_free_variable = \
20 55 storres
            sollya.sollya_lib_build_function_free_variable
21 55 storres
        sollya_lib_build_function_mul = sollya.sollya_lib_build_function_mul
22 55 storres
        sollya_lib_build_function_pow = sollya.sollya_lib_build_function_pow
23 54 storres
        sollya_lib_build_function_sub = sollya.sollya_lib_build_function_sub
24 55 storres
        sollya_lib_chebyshevform = sollya.sollya_lib_chebyshevform
25 5 storres
        sollya_lib_clear_obj = sollya.sollya_lib_clear_obj
26 5 storres
        sollya_lib_clear_object_list = sollya.sollya_lib_clear_object_list
27 5 storres
        sollya_lib_close = sollya.sollya_lib_close
28 5 storres
        sollya_lib_constant = sollya.sollya_lib_constant
29 5 storres
        sollya_lib_constant_from_int = sollya.sollya_lib_constant_from_int
30 5 storres
        sollya_lib_constant_from_int64 = sollya.sollya_lib_constant_from_int64
31 5 storres
        sollya_lib_constant_from_uint64 = \
32 5 storres
            sollya.sollya_lib_constant_from_uint64
33 55 storres
        sollya_lib_copy_obj = sollya.sollya_lib_copy_obj
34 5 storres
        sollya_lib_cos = sollya.sollya_lib_cos
35 5 storres
        sollya_lib_evaluate = sollya.sollya_lib_evaluate
36 5 storres
        sollya_lib_get_canonical = sollya.sollya_lib_get_canonical
37 5 storres
        sollya_lib_get_constant = sollya.sollya_lib_get_constant
38 5 storres
        sollya_lib_get_constant_as_int = \
39 5 storres
            sollya.sollya_lib_get_constant_as_int
40 5 storres
        sollya_lib_get_constant_as_uint64 = \
41 5 storres
            sollya.sollya_lib_get_constant_as_uint64
42 5 storres
        sollya_lib_get_free_variable_name = \
43 5 storres
        sollya.sollya_lib_get_free_variable_name
44 5 storres
        sollya_lib_get_function_arity = sollya.sollya_lib_get_function_arity
45 5 storres
        sollya_lib_get_head_function = sollya.sollya_lib_get_head_function
46 53 storres
        sollya_lib_get_interval_from_range = \
47 53 storres
            sollya.sollya_lib_get_interval_from_range
48 5 storres
        sollya_lib_get_list_elements = sollya.sollya_lib_get_list_elements
49 5 storres
        sollya_lib_get_object_list_head = \
50 5 storres
            sollya.sollya_lib_get_object_list_head
51 5 storres
        sollya_lib_get_object_list_tail = \
52 5 storres
            sollya.sollya_lib_get_object_list_tail
53 5 storres
        sollya_lib_get_prec = sollya.sollya_lib_get_prec
54 5 storres
        sollya_lib_get_prec_of_constant = sollya.sollya_lib_get_prec_of_constant
55 53 storres
        sollya_lib_get_prec_of_range = sollya.sollya_lib_get_prec_of_range
56 5 storres
        sollya_lib_get_subfunctions = sollya.sollya_lib_get_subfunctions
57 5 storres
        sollya_lib_head = sollya.sollya_lib_head
58 56 storres
        sollya_lib_inf = sollya.sollya_lib_inf
59 53 storres
        sollya_lib_infnorm = sollya.sollya_lib_infnorm
60 37 storres
        sollya_lib_init= sollya.sollya_lib_init
61 5 storres
        sollya_lib_is_absolute = sollya.sollya_lib_is_absolute
62 85 storres
        sollya_lib_is_off = sollya.sollya_lib_is_off
63 85 storres
        sollya_lib_is_on = sollya.sollya_lib_is_on
64 55 storres
        sollya_lib_mid = sollya.sollya_lib_mid
65 37 storres
        sollya_lib_name_free_variable = \
66 37 storres
            sollya.sollya_lib_name_free_variable
67 5 storres
        sollya_lib_obj_is_function = sollya.sollya_lib_obj_is_function
68 5 storres
        sollya_lib_obj_is_list = sollya.sollya_lib_obj_is_list
69 37 storres
        sollya_lib_obj_is_error = sollya.sollya_lib_obj_is_error
70 5 storres
        sollya_lib_obj_is_range = sollya.sollya_lib_obj_is_range
71 5 storres
        sollya_lib_obj_is_structure = sollya.sollya_lib_obj_is_structure
72 5 storres
        sollya_lib_off = sollya.sollya_lib_off
73 5 storres
        sollya_lib_on = sollya.sollya_lib_on
74 5 storres
        sollya_lib_parse_string = sollya.sollya_lib_parse_string
75 5 storres
        sollya_lib_range = sollya.sollya_lib_range
76 5 storres
        sollya_lib_relative = sollya.sollya_lib_relative
77 5 storres
        sollya_lib_remez = sollya.sollya_lib_remez
78 5 storres
        sollya_lib_set_canonical = sollya.sollya_lib_set_canonical
79 5 storres
        sollya_lib_set_prec = sollya.sollya_lib_set_prec
80 56 storres
        sollya_lib_sup = sollya.sollya_lib_sup
81 54 storres
        sollya_lib_supnorm = sollya.sollya_lib_supnorm
82 35 storres
        sollya_lib_tail = sollya.sollya_lib_tail
83 5 storres
        sollya_lib_taylor = sollya.sollya_lib_taylor
84 5 storres
        sollya_lib_taylorform = sollya.sollya_lib_taylorform
85 5 storres
except :
86 5 storres
    print "\nCould not rename one of the functions.\n"
87 5 storres
    sys.exit(1)
88 5 storres
89 5 storres
# Set the return type of several functions (those that have a return
90 5 storres
# type different from c_int or void). We consider the all the functions
91 5 storres
# returning a sollya_obj_t as returning an int.
92 5 storres
try:
93 5 storres
    sollya_lib_get_free_variable_name.restype = c_char_p
94 5 storres
except :
95 5 storres
    print "\nOne of the Python-Sollya return type setting command has \
96 5 storres
          failed.\n"
97 5 storres
    sys.exit(1)
98 5 storres
#
99 5 storres
# Set the argument type of several functions.
100 5 storres
#
101 5 storres
try:
102 5 storres
    sollya_lib_get_constant_as_int.argtypes  = [POINTER(c_int), c_int]
103 5 storres
    sollya_lib_get_function_arity.argtypes   = [POINTER(c_int), c_int]
104 5 storres
    sollya_lib_get_head_function.argtypes    = [POINTER(c_int), c_int]
105 53 storres
    sollya_lib_get_list_elements.argtypes    = [POINTER(POINTER(c_longlong)), \
106 53 storres
                                                POINTER(c_int),\
107 5 storres
                                                POINTER(c_int), c_int]
108 5 storres
    sollya_lib_get_prec_of_constant.argtypes = [POINTER(c_int), c_int]
109 53 storres
    sollya_lib_get_prec_of_range.argtypes    = [POINTER(c_int), c_int]
110 5 storres
    sollya_lib_get_subfunctions.argtypes     = [c_int, POINTER(c_int), \
111 53 storres
            POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), \
112 53 storres
            POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), \
113 53 storres
            POINTER(c_int), POINTER(c_int)]
114 37 storres
    sollya_lib_name_free_variable.argtypes   = [POINTER(c_char)]
115 5 storres
except :
116 38 storres
    print "\nOne of the Python-Sollya argument type setting command has \
117 5 storres
          failed.\n"
118 5 storres
    sys.exit(1)
119 5 storres
#
120 5 storres
# Give it a try!
121 5 storres
#
122 35 storres
sollya
123 35 storres
sollya.sollya_lib_init(None)
124 56 storres
print "\nSuperficial Sollya library check..."
125 5 storres
print sollya.sollya_lib_get_free_variable_name()
126 5 storres
sollyaExp = sollya_lib_parse_string("exp(x)")
127 5 storres
retc = sollya_lib_autoprint(sollyaExp, None)
128 5 storres
arg = sollya_lib_constant_from_int(int(1))
129 5 storres
print "Type of sollya_obj_t: ",type(arg), "Value: ", arg
130 5 storres
res = sollya_lib_evaluate(sollyaExp, arg)
131 5 storres
retc = sollya_lib_autoprint(res, None)
132 5 storres
retc = sollya_lib_get_prec(None)
133 5 storres
a = c_int(0)
134 5 storres
sollya_lib_get_constant_as_int(byref(a), retc)
135 5 storres
print "Precision : ", a.value
136 5 storres
print "Address of a.value ", addressof(a)
137 56 storres
print "...Sollya library check done."
138 35 storres
#
139 35 storres
#
140 35 storres
#
141 5 storres
#b = RealNumber()
142 5 storres
#print cast(retc, POINTER(c_int)).contents
143 5 storres
#retc = cast(retc, POINTER(c_int)).contents
144 5 storres
#arg = sollya_lib_constant_from_int(int(retc))
145 5 storres
#retc = sollya_lib_autoprint(arg, None)
146 5 storres
#sollya_lib_set_prec(c_int(100))