Statistiques
| Révision :

root / pobysoPythonSage / src / sollya_lib.sage @ 9

Historique | Voir | Annoter | Télécharger (5,1 ko)

1 5 storres
import sys
2 5 storres
from ctypes import *
3 5 storres
from sage.rings.real_mpfr import *
4 5 storres
try:
5 5 storres
    sollya=CDLL("/warehouse/storres/root/lib/libsollya.so")
6 5 storres
except :
7 5 storres
    print "\nCould not find nor load the Sollya library.\n"
8 5 storres
    sys.exit(1)
9 5 storres
10 5 storres
sollya
11 5 storres
sollya.sollya_lib_init(None)
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 5 storres
        sollya_lib_absolute = sollya.sollya_lib_absolute
16 5 storres
        sollya_lib_autoprint = sollya.sollya_lib_autoprint
17 5 storres
        sollya_lib_build_function_exp = sollya.sollya_lib_build_function_exp
18 5 storres
        sollya_lib_clear_obj = sollya.sollya_lib_clear_obj
19 5 storres
        sollya_lib_clear_object_list = sollya.sollya_lib_clear_object_list
20 5 storres
        sollya_lib_close = sollya.sollya_lib_close
21 5 storres
        sollya_lib_constant = sollya.sollya_lib_constant
22 5 storres
        sollya_lib_constant_from_int = sollya.sollya_lib_constant_from_int
23 5 storres
        sollya_lib_constant_from_int64 = sollya.sollya_lib_constant_from_int64
24 5 storres
        sollya_lib_constant_from_uint64 = \
25 5 storres
            sollya.sollya_lib_constant_from_uint64
26 5 storres
        sollya_lib_cos = sollya.sollya_lib_cos
27 5 storres
        sollya_lib_evaluate = sollya.sollya_lib_evaluate
28 5 storres
        sollya_lib_get_canonical = sollya.sollya_lib_get_canonical
29 5 storres
        sollya_lib_get_constant = sollya.sollya_lib_get_constant
30 5 storres
        sollya_lib_get_constant_as_int = \
31 5 storres
            sollya.sollya_lib_get_constant_as_int
32 5 storres
        sollya_lib_get_constant_as_uint64 = \
33 5 storres
            sollya.sollya_lib_get_constant_as_uint64
34 5 storres
        sollya_lib_get_free_variable_name = \
35 5 storres
        sollya.sollya_lib_get_free_variable_name
36 5 storres
        sollya_lib_get_function_arity = sollya.sollya_lib_get_function_arity
37 5 storres
        sollya_lib_get_head_function = sollya.sollya_lib_get_head_function
38 5 storres
        sollya_lib_get_list_elements = sollya.sollya_lib_get_list_elements
39 5 storres
        sollya_lib_get_object_list_head = \
40 5 storres
            sollya.sollya_lib_get_object_list_head
41 5 storres
        sollya_lib_get_object_list_tail = \
42 5 storres
            sollya.sollya_lib_get_object_list_tail
43 5 storres
        sollya_lib_get_prec = sollya.sollya_lib_get_prec
44 5 storres
        sollya_lib_get_prec_of_constant = sollya.sollya_lib_get_prec_of_constant
45 5 storres
        sollya_lib_get_subfunctions = sollya.sollya_lib_get_subfunctions
46 5 storres
        sollya_lib_head = sollya.sollya_lib_head
47 5 storres
        sollya_lib_is_absolute = sollya.sollya_lib_is_absolute
48 5 storres
        sollya_lib_obj_is_function = sollya.sollya_lib_obj_is_function
49 5 storres
        sollya_lib_obj_is_list = sollya.sollya_lib_obj_is_list
50 5 storres
        sollya_lib_obj_is_range = sollya.sollya_lib_obj_is_range
51 5 storres
        sollya_lib_obj_is_structure = sollya.sollya_lib_obj_is_structure
52 5 storres
        sollya_lib_off = sollya.sollya_lib_off
53 5 storres
        sollya_lib_on = sollya.sollya_lib_on
54 5 storres
        sollya_lib_parse_string = sollya.sollya_lib_parse_string
55 5 storres
        sollya_lib_range = sollya.sollya_lib_range
56 5 storres
        sollya_lib_relative = sollya.sollya_lib_relative
57 5 storres
        sollya_lib_remez = sollya.sollya_lib_remez
58 5 storres
        sollya_lib_set_canonical = sollya.sollya_lib_set_canonical
59 5 storres
        sollya_lib_set_prec = sollya.sollya_lib_set_prec
60 5 storres
        sollya_lib_taylor = sollya.sollya_lib_taylor
61 5 storres
        sollya_lib_taylorform = sollya.sollya_lib_taylorform
62 5 storres
63 5 storres
except :
64 5 storres
    print "\nCould not rename one of the functions.\n"
65 5 storres
    sys.exit(1)
66 5 storres
67 5 storres
# Set the return type of several functions (those that have a return
68 5 storres
# type different from c_int or void). We consider the all the functions
69 5 storres
# returning a sollya_obj_t as returning an int.
70 5 storres
try:
71 5 storres
    sollya_lib_get_free_variable_name.restype = c_char_p
72 5 storres
except :
73 5 storres
    print "\nOne of the Python-Sollya return type setting command has \
74 5 storres
          failed.\n"
75 5 storres
    sys.exit(1)
76 5 storres
#
77 5 storres
# Set the argument type of several functions.
78 5 storres
#
79 5 storres
try:
80 5 storres
    sollya_lib_get_constant_as_int.argtypes  = [POINTER(c_int), c_int]
81 5 storres
    sollya_lib_get_function_arity.argtypes   = [POINTER(c_int), c_int]
82 5 storres
    sollya_lib_get_head_function.argtypes    = [POINTER(c_int), c_int]
83 5 storres
    sollya_lib_get_list_elements.argtypes    = [POINTER(POINTER(c_longlong)), POINTER(c_int),\
84 5 storres
                                                POINTER(c_int), c_int]
85 5 storres
    sollya_lib_get_prec_of_constant.argtypes = [POINTER(c_int), c_int]
86 5 storres
    sollya_lib_get_subfunctions.argtypes     = [c_int, POINTER(c_int), \
87 5 storres
    POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), \
88 5 storres
    POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int)]
89 5 storres
except :
90 5 storres
    print "\nOne of the Python-Sollya arguement type setting command has \
91 5 storres
          failed.\n"
92 5 storres
    sys.exit(1)
93 5 storres
#
94 5 storres
# Give it a try!
95 5 storres
#
96 5 storres
print "Sollya library tests"
97 5 storres
print sollya.sollya_lib_get_free_variable_name()
98 5 storres
sollyaExp = sollya_lib_parse_string("exp(x)")
99 5 storres
retc = sollya_lib_autoprint(sollyaExp, None)
100 5 storres
arg = sollya_lib_constant_from_int(int(1))
101 5 storres
print "Type of sollya_obj_t: ",type(arg), "Value: ", arg
102 5 storres
res = sollya_lib_evaluate(sollyaExp, arg)
103 5 storres
retc = sollya_lib_autoprint(res, None)
104 5 storres
retc = sollya_lib_get_prec(None)
105 5 storres
a = c_int(0)
106 5 storres
sollya_lib_get_constant_as_int(byref(a), retc)
107 5 storres
print "Precision : ", a.value
108 5 storres
print "Address of a.value ", addressof(a)
109 5 storres
#b = RealNumber()
110 5 storres
#print cast(retc, POINTER(c_int)).contents
111 5 storres
#retc = cast(retc, POINTER(c_int)).contents
112 5 storres
#arg = sollya_lib_constant_from_int(int(retc))
113 5 storres
#retc = sollya_lib_autoprint(arg, None)
114 5 storres
#sollya_lib_set_prec(c_int(100))