Index: pobyso.py
===================================================================
--- pobyso.py	(revision 51)
+++ pobyso.py	(revision 52)
@@ -102,13 +102,16 @@
     return(pobyso_constant_sa_so(rnArg))
     
 def pobyso_constant_sa_so(rnArg):
+    """
+    Create a Sollya constant from a RealNumber.
+    """
     return(sollya_lib_constant(get_rn_value(rnArg)))
     
 def pobyso_constant_1():
     """ Legacy function. See pobyso_constant_so_so. """
-    return(pobyso_constant_1_so_so())
+    return(pobyso_constant_1_sa_so())
 
-def pobyso_constant_1_so_so():
+def pobyso_constant_1_sa_so():
     return(pobyso_constant_from_int_sa_so(1))
 
 def pobyso_constant_from_int(anInt):
@@ -223,17 +226,22 @@
     pobyso_get_constant_so_sa(rnArg, soConst)
 
 def pobyso_get_constant_so_sa(rnArg, soConst):
-    set_rn_value(rnArg, soConst)
+    """
+    Set the value of rnArg to the value of soConst in MPFR_RNDN mode.
+    rnArg must already exist and belong to some RealField.
+    We assume that soConst points to a Sollya constant.
+    """
+    sollya_lib_get_constant(get_rn_value(rnArg), soConst)
     
 def pobyso_get_constant_as_rn(ctExp):
     """ Legacy function. See pobyso_get_constant_as_rn_so_sa. """ 
     return(pobyso_get_constant_as_rn_so_sa(ctExp))
     
-def pobyso_get_constant_as_rn_so_sa(ctExp):
-    precision  = pobyso_get_prec_of_constant(ctExp) 
+def pobyso_get_constant_as_rn_so_sa(constExp):
+    precision  = pobyso_get_prec_of_constant(constExp) 
     RRRR = RealField(precision)
     rn = RRRR(0)
-    sollya_lib_get_constant(get_rn_value(rn), ctExp)
+    sollya_lib_get_constant(get_rn_value(rn), constExp)
     return(rn)
 
 def pobyso_get_constant_as_rn_with_rf(ctExp, realField):
@@ -300,12 +308,18 @@
 def pobyso_get_max_prec_of_exp_so_sa(soExp):
     """
     Get the maximum precision used for the numbers in a Sollya expression.
+    
+    Arguments:
+    soExp -- a Sollya expression pointer
+    Return value:
+    A Python integer
     TODO: 
     - error management;
     - correctly deal with numerical type such as DOUBLEEXTENDED.
     """
     maxPrecision = 0
-    currentPrecision = c_int(0)
+    minConstPrec = 0
+    currentConstPrec = 0
     operator = pobyso_get_head_function_so_sa(soExp)
     if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
     (operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
@@ -317,16 +331,27 @@
                 maxPrecision = maxPrecisionCandidate
         return(maxPrecision)
     elif operator == SOLLYA_BASE_FUNC_CONSTANT:
-        sollya_lib_get_prec_of_constant(currentPrecision, soExp)
-        #sollya_lib_autoprint(soExp, None)
-        print currentPrecision
-        return(pobyso_get_prec_of_constant_so_sa(soExp))
+        minConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
+        #currentConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
+        #print minConstPrec, " - ", currentConstPrec 
+        return(pobyso_get_min_prec_of_constant_so_sa(soExp))
+    
     elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
         return(0)
     else:
         print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
         return(0)
 
+def pobyso_get_min_prec_of_constant_so_sa(soConstExp):
+    """
+    Get the minimum precision necessary to represent the value of a Sollya
+    constant.
+    MPFR_MIN_PREC and powers of 2 are taken into account.
+    We assume that soCteExp is a point
+    """
+    constExpAsRn = pobyso_get_constant_as_rn_so_sa(soConstExp)
+    return(min_mpfr_size(get_rn_value(constExpAsRn)))
+
 def pobyso_get_sage_exp_from_sollya_exp(sollyaExp, realField = RR):
     """ Legacy function. See pobyso_get_sage_exp_from_sollya_exp_so_sa. """
     return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExp, realField = RR))
@@ -346,13 +371,14 @@
         (arity, subexpressions) = pobyso_get_subfunctions_so_sa(sollyaExp)
         if arity == 1:
             sageExp = eval(pobyso_function_type_as_string_so_sa(operator) + \
-            "(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)\
-             + ")")
+            "(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], \
+            realField) + ")")
         elif arity == 2:
             if operator == SOLLYA_BASE_FUNC_POW:
                 operatorAsString = "**"
             else:
-                operatorAsString = pobyso_function_type_as_string_so_sa(operator)
+                operatorAsString = \
+                    pobyso_function_type_as_string_so_sa(operator)
             sageExp = \
               eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)"\
               + " " + operatorAsString + " " + \
@@ -462,6 +488,40 @@
     rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
     return(rangeSo)
 
+def pobyso_remez_canonical_sa_sa(func, \
+                                 degree, \
+                                 lowerBound, \
+                                 upperBound, \
+                                 weight = None, \
+                                 quality = None):
+    """
+    All arguments are Sage/Python.
+    The functions (func and weight) must be passed as expressions or strings.
+    Otherwise the function fails. 
+    The return value is a pointer is a Sage polynomial.
+    """
+    var('zorglub')    # Dummy variable name for type check only.
+    polySo = pobyso_remez_canonical_sa_so(func, \
+                                 degree, \
+                                 lowerBound, \
+                                 upperBound, \
+                                 weight = None, \
+                                 quality = None)
+    if parent(func) == parent("string"):
+        functionSa = eval(func)
+    # Expression test.
+    elif type(func) == type(zorglub):
+        functionSa = func
+    maxPrecision = 0
+    if polySo is None:
+        return(None)
+    maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
+    RRRR = RealField(maxPrecision)
+    polynomialRing = RRRR[functionSa.variables()[0]]
+    expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRR)
+    polySa = polynomial(expSa, polynomialRing)
+    return(polySa)
+    
 def pobyso_remez_canonical(func, \
                            degree, \
                            lowerBound, \
@@ -479,7 +539,7 @@
                                  degree, \
                                  lowerBound, \
                                  upperBound, \
-                                 weight = "1", \
+                                 weight = None, \
                                  quality = None):
     """
     All arguments are Sage/Python.
@@ -487,15 +547,24 @@
     Otherwise the function fails. 
     The return value is a pointer to a Sollya function.
     """
-    var('zorglub')
+    var('zorglub')    # Dummy variable name for type check only.
+    currentVariableName = None
+    # The func argument can be of different types (string, 
+    # symbolic expression...)
     if parent(func) == parent("string"):
         functionSo = sollya_lib_parse_string(func)
     # Expression test.
-    elif type(func) == type(zorglub): 
-        functionSo = sollya_lib_parse_string_sa_so(func._assume_str())
+    elif type(func) == type(zorglub):
+        # Until we are able to translate Sage expressions into Sollya 
+        # expressions : parse the string version.
+        currentVariableName = func.variables()[0]
+        sollya_lib_name_free_variable(str(currentVariableName))
+        functionSo = sollya_lib_parse_string(func._assume_str())
     else:
         return(None)
-    if parent(weight) == parent("string"):
+    if weight is None:
+        weightSo = pobyso_constant_1_sa_so()
+    elif parent(weight) == parent("string"):
         weightSo = sollya_lib_parse_string(func)
     elif type(weight) == type(zorglub): 
         functionSo = sollya_lib_parse_string_sa_so(weight._assume_str())
@@ -505,12 +574,19 @@
     rangeSo = pobyso_range_sa_so(lowerBound, upperBound)
     if not quality is None:
         qualitySo= pobyso_constant_sa_so(quality)
-    return(sollya_lib_remez(functionSo, degreeSo, rangeSo, weightSo, qualitySo, None))
+    else:
+        qualitySo = None
+    return(sollya_lib_remez(functionSo, \
+                            degreeSo, \
+                            rangeSo, \
+                            weightSo, \
+                            qualitySo, \
+                            None))
     
 def pobyso_remez_canonical_so_so(funcSo, \
                                  degreeSo, \
                                  rangeSo, \
-                                 weightSo = pobyso_constant_1_so_so(),\
+                                 weightSo = pobyso_constant_1_sa_so(),\
                                  qualitySo = None):
     """
     All arguments are pointers to Sollya objects.
