Index: pobysoPythonSage/src/pobyso.py
===================================================================
--- pobysoPythonSage/src/pobyso.py	(revision 199)
+++ pobysoPythonSage/src/pobyso.py	(revision 200)
@@ -273,18 +273,54 @@
     """
     Get a Sollya constant from a Sage int.
     """
-    return(sollya_lib_constant_from_int(int(anInt)))
+    return(sollya_lib_constant_from_int64(long(anInt)))
 
 def pobyso_constant_from_int_so_sa(constSo):
     """
     Get a Sage int from a Sollya int constant.
     Usefull for precision or powers in polynomials.
     """
-    constSa = c_int(0)
-    sollya_lib_get_constant_as_int(byref(constSa), constSo)
+    constSa = c_long(0)
+    sollya_lib_get_constant_as_int64(byref(constSa), constSo)
     return(constSa.value)
 # End pobyso_constant_from_int_so_sa
 
+def pobyso_constant_from_mpq_sa_so(rationalSa, precision = None):
+    """
+    Make a Sollya constant from Sage rational.
+    A bit convoluted to take into account precision and the fact
+    that mpq constants in Sollya a non-evaluated expressions.
+    Function building and evaluation is needed to make it a "real"
+    evaluated constant.
+    """
+    ## Deal with precision stuff.
+    curPrecSa = None
+    curPrecSo = None
+    if not precision is None:
+        curPrecSo = pobyso_get_prec_so()
+        curPrecSaSa = c_int(0)
+        sollya_lib_get_constant_as_int(byref(curPrecSaSa), curPrecSo)
+        curPrecSa = int(curPrecSaSa.value)
+        if curPrecSa != precision:
+            pobyso_set_prec_sa_so(precision)
+    ## In Sollya mpq constants are non-evaluated expressions.
+    #  We must force evaluation.
+    zeroSo    = pobyso_constant_0_sa_so()
+    oneSo     = pobyso_constant_1_sa_so()
+    ratExprSo = \
+        sollya_lib_constant_from_mpq(sgmp_get_rational_value(rationalSa))
+    addExprSo = sollya_lib_build_function_add(zeroSo, ratExprSo)
+    constSo   = sollya_lib_evaluate(addExprSo,oneSo)
+    ## Clears expression and arguments, as the former was created with a
+    #  "build" variant.
+    sollya_lib_clear_obj(addExprSo)
+    sollya_lib_clear_obj(oneSo)
+    if curPrecSa != precision:
+        pobyso_set_prec_so_so(curPrecSo)
+        sollya_lib_clear_obj(curPrecSo)
+    return constSo
+# End pobyso_constant_from_mpq_sa_so.
+
 def pobyso_error_so():
     return sollya_lib_error(None)
 # End pobyso_error().
@@ -441,6 +477,13 @@
     return(rnSa)
 # End pobyso_get_constant_as_rn_with_rf_so_sa
 
+def pobyso_get_float_poly_sa_so(polySa, realFieldSa=None):
+    """
+    Create a Sollya polynomial from a Sage polynomial.
+    """
+    pass
+# End get_float_poly_sa_so.
+    
 def pobyso_get_free_variable_name():
     """ 
     Legacy function. See pobyso_get_free_variable_name_so_sa.
@@ -588,6 +631,107 @@
     constExpAsRnSa = pobyso_get_constant_as_rn_so_sa(constExpSo)
     return(min_mpfr_size(get_rn_value(constExpAsRnSa)))
 
+def pobyso_get_poly_so_sa(polySo, realFieldSa=None):
+    """
+    Convert a Sollya polynomial into a Sage polynomial.
+    We assume that the polynomial is in canonical form.
+    If no realField is given, a RealField corresponding to the maximum 
+    precision of the coefficients is internally computed.
+    The real field is not returned but can be easily retrieved from 
+    the polynomial itself.
+    ALGORITHM:
+    - (optional) compute the RealField of the coefficients;
+    - convert the Sollya expression into a Sage expression;
+    - convert the Sage expression into a Sage polynomial
+    TODO: the canonical thing for the polynomial.
+    """    
+    if realFieldSa is None:
+        expressionPrecSa = pobyso_get_max_prec_of_exp_so_sa(polySo)
+        realFieldSa = RealField(expressionPrecSa)
+    #print "Sollya expression before...",
+    #pobyso_autoprint(polySo)
+
+    expressionSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, \
+                                                             realFieldSa)
+    #print "...Sollya expression after.",
+    #pobyso_autoprint(polySo)
+    polyVariableSa = expressionSa.variables()[0]
+    polyRingSa = realFieldSa[str(polyVariableSa)]
+    #print polyRingSa
+    # Do not use the polynomial(expressionSa, ring=polyRingSa) form!
+    polynomialSa = polyRingSa(expressionSa)
+    return(polynomialSa)
+# End pobyso_get_poly_so_sa
+
+def pobyso_get_prec():
+    """ Legacy function. See pobyso_get_prec_so_sa(). """
+    return(pobyso_get_prec_so_sa())
+
+def pobyso_get_prec_so():
+    """
+    Get the current default precision in Sollya.
+    The return value is a Sollya object.
+    Usefull when modifying the precision back and forth by avoiding
+    extra conversions.
+    """
+    return(sollya_lib_get_prec(None))
+    
+def pobyso_get_prec_so_sa():
+    """
+    Get the current default precision in Sollya.
+    The return value is Sage/Python int.
+    """
+    precSo = sollya_lib_get_prec(None)
+    precSa = c_int(0)
+    sollya_lib_get_constant_as_int(byref(precSa), precSo)
+    sollya_lib_clear_obj(precSo)
+    return int(precSa.value)
+# End pobyso_get_prec_so_sa.
+
+    
+def pobyso_get_prec_of_constant(ctExpSo):
+    """ Legacy function. See pobyso_get_prec_of_constant_so_sa. """
+    return(pobyso_get_prec_of_constant_so_sa(ctExpSo))
+
+def pobyso_get_prec_of_constant_so_sa(ctExpSo):
+    """
+    Tries to find a precision to represent ctExpSo without rounding.
+    If not possible, returns None.
+    """
+    prec = c_int(0)
+    retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None)
+    if retc == 0:
+        return(None)
+    return(int(prec.value))
+
+def pobyso_get_prec_of_range_so_sa(rangeSo):
+    """
+    Returns the number of bits elements of a range are coded with.
+    """
+    prec = c_int(0)
+    retc = sollya_lib_get_prec_of_range(byref(prec), rangeSo, None)
+    if retc == 0:
+        return(None)
+    return(int(prec.value))
+# End pobyso_get_prec_of_range_so_sa()
+
+def pobyso_get_rat_poly_sa_so(polySa, precSa = None):
+    """
+    Create a Sollya polynomial from a Sage rational polynomial.
+    """
+    ## TODO: filter arguments.
+    ##
+    if not precSa is None:
+        initialPrecSo = pobyso_get_prec_so() 
+    coefficients = polySa.coefficients()
+    exponents    = polySa.exponents()
+    ## TODO: deal with variables names.
+    
+    ## If necessary, return Sollya to its initial default precision.
+    if not precSa is None:
+        pobyso_set_prec_so_so(initialPrecSo)
+# End pobyso_get_rat_poly_sa_so    
+    
 def pobyso_get_sage_exp_from_sollya_exp(sollyaExpSo, realField = RR):
     """ Legacy function. See pobyso_get_sage_exp_from_sollya_exp_so_sa. """
     return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, \
@@ -640,49 +784,11 @@
 # End pobyso_get_sage_exp_from_sollya_exp_so_sa
 
 
-def pobyso_get_poly_sa_so(polySo, realFieldSa=None):
-    """
-    Create a Sollya polynomial from a Sage polynomial.
-    """
-    pass
-# pobyso_get_poly_sa_so
-
-def pobyso_get_poly_so_sa(polySo, realFieldSa=None):
-    """
-    Convert a Sollya polynomial into a Sage polynomial.
-    We assume that the polynomial is in canonical form.
-    If no realField is given, a RealField corresponding to the maximum 
-    precision of the coefficients is internally computed.
-    The real field is not returned but can be easily retrieved from 
-    the polynomial itself.
-    ALGORITHM:
-    - (optional) compute the RealField of the coefficients;
-    - convert the Sollya expression into a Sage expression;
-    - convert the Sage expression into a Sage polynomial
-    TODO: the canonical thing for the polynomial.
-    """    
-    if realFieldSa is None:
-        expressionPrecSa = pobyso_get_max_prec_of_exp_so_sa(polySo)
-        realFieldSa = RealField(expressionPrecSa)
-    #print "Sollya expression before...",
-    #pobyso_autoprint(polySo)
-
-    expressionSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, \
-                                                             realFieldSa)
-    #print "...Sollya expression after.",
-    #pobyso_autoprint(polySo)
-    polyVariableSa = expressionSa.variables()[0]
-    polyRingSa = realFieldSa[str(polyVariableSa)]
-    #print polyRingSa
-    # Do not use the polynomial(expressionSa, ring=polyRingSa) form!
-    polynomialSa = polyRingSa(expressionSa)
-    return(polynomialSa)
-# End pobyso_get_sage_poly_from_sollya_poly
-
 def pobyso_get_subfunctions(expressionSo):
     """ Legacy function. See pobyso_get_subfunctions_so_sa. """
     return(pobyso_get_subfunctions_so_sa(expressionSo)) 
-
+# End pobyso_get_subfunctions.
+ 
 def pobyso_get_subfunctions_so_sa(expressionSo):
     """
     Get the subfunctions of an expression.
@@ -724,51 +830,8 @@
         subs.append(int(subfunctions[i].value))
         #print subs[i]
     return(int(arity.value), subs)
+# End pobyso_get_subfunctions_so_sa
     
-def pobyso_get_prec():
-    """ Legacy function. See pobyso_get_prec_so_sa(). """
-    return(pobyso_get_prec_so_sa())
-
-def pobyso_get_prec_so():
-    """
-    Get the current default precision in Sollya.
-    The return value is a Sollya object.
-    Usefull when modifying the precision back and forth by avoiding
-    extra conversions.
-    """
-    return(sollya_lib_get_prec(None))
-    
-def pobyso_get_prec_so_sa():
-    """
-    Get the current default precision in Sollya.
-    The return value is Sage/Python int.
-    """
-    precSo = sollya_lib_get_prec(None)
-    precSa = c_int(0)
-    sollya_lib_get_constant_as_int(byref(precSa), precSo)
-    sollya_lib_clear_obj(precSo)
-    return int(precSa.value)
-# End pobyso_get_prec_so_sa.
-
-def pobyso_get_prec_of_constant(ctExpSo):
-    """ Legacy function. See pobyso_get_prec_of_constant_so_sa. """
-    return(pobyso_get_prec_of_constant_so_sa(ctExpSo))
-
-def pobyso_get_prec_of_constant_so_sa(ctExpSo):
-    prec = c_int(0)
-    retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None)
-    if retc == 0:
-        return(None)
-    return(int(prec.value))
-
-def pobyso_get_prec_of_range_so_sa(rangeSo):
-    prec = c_int(0)
-    retc = sollya_lib_get_prec_of_range(byref(prec), rangeSo, None)
-    if retc == 0:
-        return(None)
-    return(int(prec.value))
-# End pobyso_get_prec_of_range_so_sa()
-
 def pobyso_guess_degree_sa_sa(functionSa, intervalSa, approxErrorSa, 
                               weightSa=None, degreeBoundSa=None):
     """
@@ -923,6 +986,13 @@
     """
     return(sollya_lib_parse_string(string))
 
+def pobyso_precision_so_sa(ctExpSo):
+    precisionSo = sollya_lib_precision(ctExpSo)
+    precisionSa = pobyso_constant_from_int_so_sa(precisionSo)
+    sollya_lib_clear_obj(precisionSo)
+    return precisionSa
+# End pobyso_precision_so_sa
+    
 def pobyso_range(rnLowerBound, rnUpperBound):
     """ Legacy function. See pobyso_range_sa_so. """
     return(pobyso_range_sa_so(rnLowerBound, rnUpperBound)) 
@@ -997,6 +1067,8 @@
                                         upperBound, \
                                         weight, \
                                         quality))
+# End pobyso_remez_canonical.
+
 def pobyso_remez_canonical_sa_so(func, \
                                  degree, \
                                  lowerBound, \
@@ -1075,7 +1147,8 @@
     if not sollya_lib_obj_is_function(funcSo):
         return(None)
     return(sollya_lib_remez(funcSo, degreeSo, rangeSo, weightSo, qualitySo, None))
-    
+# End pobyso_remez_canonical_so_so.
+
 def pobyso_set_canonical_off():
     sollya_lib_set_canonical(sollya_lib_off())
 
