Index: pobyso.py
===================================================================
--- pobyso.py	(revision 84)
+++ pobyso.py	(revision 85)
@@ -85,15 +85,15 @@
 
 pobyso_max_arity = 9
 
+def pobyso_absolute_so_so():
+    return(sollya_lib_absolute(None))
+
 def pobyso_autoprint(arg):
     sollya_lib_autoprint(arg,None)
 
 def pobyso_autoprint_so_so(arg):
     sollya_lib_autoprint(arg,None)
     
-def pobyso_absolute_so_so():
-    return(sollya_lib_absolute(None))
-
 def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa, \
                                  precisionSa=None):
     """
@@ -104,7 +104,7 @@
     # Sanity check.
     if rnLowerBoundSa > rnUpperBoundSa:
         return None
-    if precision is None:
+    if precisionSa is None:
         # Check for the largest precision.
         lbPrecSa = rnLowerBoundSa.parent().precision()
         ubPrecSa = rnLowerBoundSa.parent().precision()
@@ -132,8 +132,20 @@
 def pobyso_build_function_sub_so_so(exp1So, exp2So):
     return(sollya_lib_build_function_sub(exp1So, exp2So))
 
-def pobyso_cmp(rnArg, soCte):
+def pobyso_change_var_in_function_so_so(funcSo, chvarExpSo):
     """
+    Variable change in a function.
+    """
+    return(sollya_lib_evaluate(funcSo,chvarExpSo))
+# End pobyso_change_var_in_function_so_so     
+
+def pobyso_chebyshevform_so_so(functionSo, degreeSo, intervalSo):
+    resultSo = sollya_lib_chebyshevform(functionSo, degreeSo, intervalSo)
+    return(resultSo)
+# End pobyso_chebyshevform_so_so.
+
+def pobyso_cmp(rnArgSa, cteSo):
+    """
     Compare the MPFR value a RealNumber with that of a Sollya constant.
     
     Get the value of the Sollya constant into a RealNumber and compare
@@ -142,33 +154,21 @@
     """
     precisionOfCte = c_int(0)
     # From the Sollya constant, create a local Sage RealNumber.
-    sollya_lib_get_prec_of_constant(precisionOfCte, soCte) 
+    sollya_lib_get_prec_of_constant(precisionOfCte, cteSo) 
     #print "Precision of constant: ", precisionOfCte
     RRRR = RealField(precisionOfCte.value)
-    rnLocal = RRRR(0)
-    sollya_lib_get_constant(get_rn_value(rnLocal), soCte)
-    #print "rnDummy: ", rnDummy
+    rnLocalSa = RRRR(0)
+    sollya_lib_get_constant(get_rn_value(rnLocalSa), cteSo)
     # Compare the local Sage RealNumber with rnArg.
-    return(cmp_rn_value(rnArg, rnLocal))
+    return(cmp_rn_value(rnArgSa, rnLocal))
 # End pobyso_smp
 
-def pobyso_change_var_in_function_so_so(funcSo, chvarExpSo):
-    """
-    Variable change in a function.
-    """
-    return(sollya_lib_evaluate(funcSo,chvarExpSo))
-# End pobyso_change_var_in_function_so_so     
-
-def pobyso_chebyshevform_so_so(functionSo, degreeSo, intervalSo):
-    resultSo = sollya_lib_chebyshevform(functionSo, degreeSo, intervalSo)
-    return(resultSo)
-# End pobyso_chebyshevform_so_so.
-
 def pobyso_compute_pos_function_abs_val_bounds_sa_sa(funcSa, lowerBoundSa, \
                                                      upperBoundSa):
     """
-    TODO: set the variable name in Sollya.
+    TODO: completely rework and test.
     """
+    pobyso = pobyso_name_free_variable_sa_so(funcSa.variables()[0])
     funcSo = pobyso_parse_string(funcSa._assume_str())
     rangeSo = pobyso_range_sa_so(lowerBoundSa, upperBoundSa)
     infnormSo = pobyso_infnorm_so_so(funcSo,rangeSo)
@@ -186,7 +186,7 @@
     infnormSo = pobyso_infnorm_so_so(funcAuxSo,rangeSo)
     fMinSa = pobyso_get_interval_from_range_so_sa(infnormSo)
     sollya_lib_clear_obj(infnormSo)
-    fMinLowerBoundSa = topBinadeLimit - fMinSa.lower()
+    fMinLowerBoundSa = binadeTopLimitSa - fMinSa.lower()
     # Compute the maximum of the precisions of the different bounds.
     maxPrecSa = max([fMinLowerBoundSa.parent().precision(), \
                      fMaxUpperBoundSa.parent().precision()])
@@ -211,14 +211,16 @@
     # Precision stuff
     if precisionSa is None:
         precisionSa = rnArgSa.parent().precision()
-    currentSollyaPrecisionSo = pobyso_get_prec_so()
-    currentSollyaPrecisionSa = pobyso_get
+    currentSollyaPrecisionSo = sollya_lib_get_prec()
+    currentSollyaPrecisionSa = \
+        pobyso_constant_from_int(currentSollyaPrecisionSo)
     if precisionSa > currentSollyaPrecisionSa:
         pobyso_set_prec_sa_so(precisionSa)
         constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
         pobyso_set_prec_sa_so(currentSollyaPrecision)
     else:
         constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
+    sollya_lib_clear_obj(currentSollyaPrecisionSo)
     return(constantSo)
     
 def pobyso_constant_0_sa_so():
@@ -348,15 +350,15 @@
     else:
         return None
 
-def pobyso_get_constant(rnArg, soConst):
+def pobyso_get_constant(rnArgSa, constSo):
     """ Legacy function. See pobyso_get_constant_so_sa. """
-    return(pobyso_get_constant_so_sa(rnArg, soConst))
+    return(pobyso_get_constant_so_sa(rnArgSa, constSo))
 
 def pobyso_get_constant_so_sa(rnArgSa, constSo):
     """
-    Set the value of rnArg to the value of soConst in MPFR_RNDN mode.
+    Set the value of rnArgSo to the value of constSo in MPFR_RNDN mode.
     rnArg must already exist and belong to some RealField.
-    We assume that soConst points to a Sollya constant.
+    We assume that constSo points to a Sollya constant.
     """
     return(sollya_lib_get_constant(get_rn_value(rnArgSa), constSo))
     
@@ -389,11 +391,11 @@
     """
     Get a Sollya constant as a Sage "real number".
     If no real field is specified, the precision of the floating-point number 
-    returned is that of the Solly constant.
+    returned is that of the Sollya constant.
     Otherwise is is that of the real field. Hence rounding may happen.
     """
     if realFieldSa is None:
-        sollyaPrecSa = pobyso_get_prec_so_sa()
+        sollyaPrecSa = pobyso_get_prec_of_constant_so_sa(ctExpSo)
         realFieldSa = RealField(sollyaPrecSa)
     rnSa = realFieldSa(0)
     sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo)
@@ -457,10 +459,10 @@
     """ Legacy function. See pobyso_get_list_elements_so_so. """
     return(pobyso_get_list_elements_so_so(soObj))
  
-def pobyso_get_list_elements_so_so(soObj):
+def pobyso_get_list_elements_so_so(objSo):
     """
     Get the list elements as a Sage/Python array of Sollya objects.
-    The other data returned are also Sage/Python objects.
+    The other data returned are Sage/Python objects.
     """
     listAddress = POINTER(c_longlong)()
     numElements = c_int(0)
@@ -469,18 +471,18 @@
     result = sollya_lib_get_list_elements(byref(listAddress),\
                                           byref(numElements),\
                                           byref(isEndElliptic),\
-                                          soObj)
+                                          objSo)
     if result == 0 :
         return None
     for i in xrange(0, numElements.value, 1):
-        listAsList.append(listAddress[i])
+       listAsList.append(sollya_lib_copy_obj(listAddress[i]))
     return(listAsList, numElements.value, isEndElliptic.value)
 
 def pobyso_get_max_prec_of_exp(soExp):
     """ Legacy function. See pobyso_get_max_prec_of_exp_so_sa. """
     return(pobyso_get_max_prec_of_exp_so_sa(soExp))
 
-def pobyso_get_max_prec_of_exp_so_sa(soExp):
+def pobyso_get_max_prec_of_exp_so_sa(expSo):
     """
     Get the maximum precision used for the numbers in a Sollya expression.
     
@@ -495,10 +497,10 @@
     maxPrecision = 0
     minConstPrec = 0
     currentConstPrec = 0
-    operator = pobyso_get_head_function_so_sa(soExp)
+    operator = pobyso_get_head_function_so_sa(expSo)
     if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
     (operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
-        (arity, subexpressions) = pobyso_get_subfunctions_so_sa(soExp)
+        (arity, subexpressions) = pobyso_get_subfunctions_so_sa(expSo)
         for i in xrange(arity):
             maxPrecisionCandidate = \
                 pobyso_get_max_prec_of_exp_so_sa(subexpressions[i])
@@ -506,10 +508,10 @@
                 maxPrecision = maxPrecisionCandidate
         return(maxPrecision)
     elif operator == SOLLYA_BASE_FUNC_CONSTANT:
-        minConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
+        #minConstPrec = pobyso_get_min_prec_of_constant_so_sa(expSo)
         #currentConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
         #print minConstPrec, " - ", currentConstPrec 
-        return(pobyso_get_min_prec_of_constant_so_sa(soExp))
+        return(pobyso_get_min_prec_of_constant_so_sa(expSo))
     
     elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
         return(0)
@@ -517,59 +519,60 @@
         print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
         return(0)
 
-def pobyso_get_min_prec_of_constant_so_sa(soConstExp):
+def pobyso_get_min_prec_of_constant_so_sa(constExpSo):
     """
     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
+    We assume that constExpSo is a point
     """
-    constExpAsRn = pobyso_get_constant_as_rn_so_sa(soConstExp)
-    return(min_mpfr_size(get_rn_value(constExpAsRn)))
+    constExpAsRnSa = pobyso_get_constant_as_rn_so_sa(constExpSo)
+    return(min_mpfr_size(get_rn_value(constExpAsRnSa)))
 
-def pobyso_get_sage_exp_from_sollya_exp(sollyaExp, realField = RR):
+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(sollyaExp, realField = RR))
+    return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, \
+                                                     realField = RR))
 
-def pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExp, realField = RR):
+def pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, realFieldSa = RR):
     """
     Get a Sage expression from a Sollya expression. 
     Currently only tested with polynomials with floating-point coefficients.
     Notice that, in the returned polynomial, the exponents are RealNumbers.
     """
     #pobyso_autoprint(sollyaExp)
-    operator = pobyso_get_head_function_so_sa(sollyaExp)
+    operatorSa = pobyso_get_head_function_so_sa(sollyaExpSo)
     sollyaLibFreeVariableName = sollya_lib_get_free_variable_name()
     # Constants and the free variable are special cases.
     # All other operator are dealt with in the same way.
-    if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
-       (operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
-        (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) + ")")
-        elif arity == 2:
+    if (operatorSa != SOLLYA_BASE_FUNC_CONSTANT) and \
+       (operatorSa != SOLLYA_BASE_FUNC_FREE_VARIABLE):
+        (aritySa, subexpressionsSa) = pobyso_get_subfunctions_so_sa(sollyaExpSo)
+        if aritySa == 1:
+            sageExpSa = eval(pobyso_function_type_as_string_so_sa(operatorSa) + \
+            "(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[0], \
+            realFieldSa) + ")")
+        elif aritySa == 2:
             # We do not get through the preprocessor.
             # The "^" operator is then a special case.
-            if operator == SOLLYA_BASE_FUNC_POW:
-                operatorAsString = "**"
+            if operatorSa == SOLLYA_BASE_FUNC_POW:
+                operatorAsStringSa = "**"
             else:
-                operatorAsString = \
-                    pobyso_function_type_as_string_so_sa(operator)
-            sageExp = \
-              eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)"\
-              + " " + operatorAsString + " " + \
-                   "pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[1], realField)")
+                operatorAsStringSa = \
+                    pobyso_function_type_as_string_so_sa(operatorSa)
+            sageExpSa = \
+              eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[0], realFieldSa)"\
+              + " " + operatorAsStringSa + " " + \
+                   "pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[1], realFieldSa)")
         # We do not know yet how to deal with arity >= 3 
         # (is there any in Sollya anyway?).
         else:
-            sageExp = eval('None')
-        return(sageExp)
-    elif operator == SOLLYA_BASE_FUNC_CONSTANT:
+            sageExpSa = eval('None')
+        return(sageExpSa)
+    elif operatorSa == SOLLYA_BASE_FUNC_CONSTANT:
         #print "This is a constant"
-        return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExp, realField)
-    elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
+        return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExpSo, realFieldSa)
+    elif operatorSa == SOLLYA_BASE_FUNC_FREE_VARIABLE:
         #print "This is free variable"
         return(eval(sollyaLibFreeVariableName))
     else:
@@ -720,15 +723,15 @@
 def pobyso_lib_init():
     sollya_lib_init(None)
     
-def pobyso_name_free_variable(freeVariableName):
+def pobyso_name_free_variable(freeVariableNameSa):
     """ Legacy function. See pobyso_name_free_variable_sa_so. """
-    pobyso_name_free_variable_sa_so(freeVariableName)
+    pobyso_name_free_variable_sa_so(freeVariableNameSa)
 
-def pobyso_name_free_variable_sa_so(freeVariableName):
+def pobyso_name_free_variable_sa_so(freeVariableNameSa):
     """
     Set the free variable name in Sollya from a Sage string.
     """
-    sollya_lib_name_free_variable(freeVariableName)
+    sollya_lib_name_free_variable(freeVariableNameSa)
 
 def pobyso_parse_string(string):
     """ Legacy function. See pobyso_parse_string_sa_so. """
@@ -745,19 +748,19 @@
     return(pobyso_range_sa_so(rnLowerBound, rnUpperBound)) 
 
 
-def pobyso_range_to_interval_so_sa(rangeSo, realIntervalField = None):
+def pobyso_range_to_interval_so_sa(rangeSo, realIntervalFieldSa = None):
     """
     Get a Sage interval from a Sollya range.
     If no realIntervalField is given as a parameter, the Sage interval
     precision is that of the Sollya range.
-    Otherwise, the precision is that of the realIntervalField. Rounding
-    may happen.
+    Otherwise, the precision is that of the realIntervalField. In this case
+    rounding may happen.
     """
-    if realIntervalField is None:
+    if realIntervalFieldSa is None:
         precSa = pobyso_get_prec_of_range_so_sa(rangeSo)
-        realIntervalField = RealIntervalField(precSa)
+        realIntervalFieldSa = RealIntervalField(precSa)
     intervalSa = \
-        pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalField) 
+        pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalFieldSa) 
     return(intervalSa)
 
 def pobyso_remez_canonical_sa_sa(func, \
@@ -778,8 +781,8 @@
                                  degree, \
                                  lowerBound, \
                                  upperBound, \
-                                 weight = None, \
-                                 quality = None)
+                                 weight, \
+                                 quality)
     # String test
     if parent(func) == parent("string"):
         functionSa = eval(func)
@@ -793,12 +796,13 @@
     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)
+    RRRRSa = RealField(maxPrecision)
+    polynomialRingSa = RRRRSa[functionSa.variables()[0]]
+    expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRRSa)
+    polySa = polynomial(expSa, polynomialRingSa)
     sollya_lib_clear_obj(polySo)
     return(polySa)
+# End pobyso_remez_canonical_sa_sa
     
 def pobyso_remez_canonical(func, \
                            degree, \
@@ -827,30 +831,35 @@
     """
     var('zorglub')    # Dummy variable name for type check only. Type of
     # zorglub is "symbolic expression".
-    currentVariableName = None
+    currentVariableNameSa = None
     # The func argument can be of different types (string, 
     # symbolic expression...)
     if parent(func) == parent("string"):
-        functionSo = sollya_lib_parse_string(func)
+        localFuncSa = eval(func)
+        if len(localFuncSa.variables()) > 0:
+            currentVariableNameSa = localFuncSa.variables()[0]
+            sollya_lib_name_free_variable(str(currentVariableNameSa))
+            functionSo = sollya_lib_parse_string(localFuncSa._assume_str())
     # Expression test.
     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())
+        if len(func.variables()) > 0:
+            currentVariableNameSa = func.variables()[0]
+            sollya_lib_name_free_variable(str(currentVariableNameSa))
+            functionSo = sollya_lib_parse_string(func._assume_str())
     else:
         return(None)
-    if weight is None:
+    if weight is None: # No weight given -> 1.
         weightSo = pobyso_constant_1_sa_so()
-    elif parent(weight) == parent("string"):
+    elif parent(weight) == parent("string"): # Weight given as string: parse it.
         weightSo = sollya_lib_parse_string(func)
-    elif type(weight) == type(zorglub): 
+    elif type(weight) == type(zorglub): # Weight given as symbolice expression.
         functionSo = sollya_lib_parse_string_sa_so(weight._assume_str())
     else:
         return(None)
     degreeSo = pobyso_constant_from_int(degree)
-    rangeSo = pobyso_range_sa_so(lowerBound, upperBound)
+    rangeSo = pobyso_bounds_to_range_sa_so(lowerBound, upperBound)
     if not quality is None:
         qualitySo= pobyso_constant_sa_so(quality)
     else:
@@ -867,7 +876,7 @@
     sollya_lib_clear_obj(rangeSo)
     sollya_lib_clear_obj(weightSo)
     if not qualitySo is None:
-        sollya_lib_clear_obj(qualtiySo)
+        sollya_lib_clear_obj(qualitySo)
     return(remezPolySo)
 # End pobyso_remez_canonical_sa_so
 
@@ -892,21 +901,52 @@
 
 def pobyso_set_prec(p):
     """ Legacy function. See pobyso_set_prec_sa_so. """
-    return( pobyso_set_prec_sa_so(p))
+    pobyso_set_prec_sa_so(p)
 
 def pobyso_set_prec_sa_so(p):
     a = c_int(p)
     precSo = c_void_p(sollya_lib_constant_from_int(a))
-    sollya_lib_set_prec(precSo)
+    sollya_lib_set_prec(precSo, None)
 
-def pobyso_supnorm_so_so(polySo, funcSo, intervalSo, errorTypeSo, accuracySo):
-    return(sollya_lib_supnorm(polySo, funcSo, intervalSo, errorTypeSo, \
-                              accuracySo))
+def pobyso_set_prec_so_so(newPrecSo):
+    sollya_lib_set_prec(newPrecSo, None)
 
-def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, rangeSo, \
-                                                errorTypeSo, \
-                                                sollyaPrecSo=None):
+def pobyso_supnorm_so_so(polySo, funcSo, intervalSo, errorTypeSo = None,\
+                         accuracySo = None):
     """
+    Computes the supnorm of the approximation error between the given 
+    polynomial and function.
+    errorTypeSo defaults to "absolute".
+    accuracySo defaults to 2^(-40).
+    """
+    if errorTypeSo is None:
+        errorTypeSo = sollya_lib_absolute(None)
+        errorTypeIsNone = True
+    else:
+        errorTypeIsNone = False
+    #
+    if accuracySo is None:
+        # Notice the **!
+        accuracySo = pobyso_constant_sa_so(RR(2**(-40)))
+        accuracyIsNone = True
+    else:
+        accuracyIsNone = False
+    pobyso_autoprint(accuracySo)
+    resultSo = \
+        sollya_lib_supnorm(polySo, funcSo, intervalSo, errorTypeSo, \
+                              accuracySo)
+    if errorTypeIsNone:
+        sollya_lib_clear_obj(errorTypeSo)
+    if accuracyIsNone:
+        sollya_lib_clear_obj(accuracySo)
+    return resultSo
+# End pobyso_supnorm_so_so
+
+def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, \
+                                                  rangeSo, \
+                                                  errorTypeSo=None, \
+                                                  sollyaPrecSo=None):
+    """
     Compute the Taylor expansion with the variable change
     x -> (x-intervalCenter) included.
     """
@@ -915,6 +955,12 @@
         initialPrecSo = sollya_lib_get_prec(None)
         sollya_lib_set_prec(sollyaPrecSo)
     #
+    # Error type stuff: default to absolute.
+    if errorTypeSo is None:
+        errorTypeIsNone = True
+        errorTypeSo = sollya_lib_absolute(None)
+    else:
+        errorTypeIsNone = False
     intervalCenterSo = sollya_lib_mid(rangeSo)
     taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
                                          intervalCenterSo, \
@@ -932,11 +978,15 @@
     if not sollyaPrecSo is None:
         sollya_lib_set_prec(initialPrecSo)
         sollya_lib_clear_obj(initialPrecSo)
+    if errorTypeIsNone:
+        sollya_lib_clear_obj(errorTypeSo)
+    sollya_lib_clear_obj(taylorFormSo)
+    # Do not clear maxErrorSo.
     return((polyVarChangedSo, intervalCenterSo, maxErrorSo))
 # end pobyso_taylor_expansion_with_change_var_so_so
 
 def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo, \
-                                                errorTypeSo, \
+                                                errorTypeSo=None, \
                                                 sollyaPrecSo=None):
     """
     Compute the Taylor expansion without the variable change
@@ -946,20 +996,29 @@
     if not sollyaPrecSo is None:
         initialPrecSo = sollya_lib_get_prec(None)
         sollya_lib_set_prec(sollyaPrecSo)
-    #
+    # Error type stuff: default to absolute.
+    if errorTypeSo is None:
+        errorTypeIsNone = True
+        errorTypeSo = sollya_lib_absolute(None)
+    else:
+        errorTypeIsNone = False
     intervalCenterSo = sollya_lib_mid(rangeSo)
     taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
                                          intervalCenterSo, \
                                          rangeSo, errorTypeSo, None)
-    (taylorFormListSo, numElements, isEndElliptic) = \
+    (taylorFormListSo, numElementsSo, isEndEllipticSo) = \
         pobyso_get_list_elements_so_so(taylorFormSo)
-    polySo = taylorFormListSo[0]
+    polySo = sollya_lib_copy_obj(taylorFormListSo[0])
     errorRangeSo = taylorFormListSo[2]
     maxErrorSo = sollya_lib_sup(errorRangeSo)
     # If changed, reset the Sollya working precision.
     if not sollyaPrecSo is None:
         sollya_lib_set_prec(initialPrecSo)
         sollya_lib_clear_obj(initialPrecSo)
+    if errorTypeIsNone:
+        sollya_lib_clear_obj(errorTypeSo)
+    sollya_lib_clear_obj(taylorFormSo)
+    # Do not clear maxErrorSo.
     return((polySo, intervalCenterSo, maxErrorSo))
 # end pobyso_taylor_expansion_no_change_var_so_so
 
@@ -970,8 +1029,9 @@
 def pobyso_taylor_so_so(functionSo, degreeSo, pointSo):
     return(sollya_lib_taylor(functionSo, degreeSo, pointSo))
     
-def pobyso_taylorform(function, degree, point = None, interval = None, errorType=None):
-    """ Legacy function. See ;"""
+def pobyso_taylorform(function, degree, point = None, 
+                      interval = None, errorType=None):
+    """ Legacy function. See pobyso_taylorform_sa_sa;"""
     
 def pobyso_taylorform_sa_sa(functionSa, \
                             degreeSa, \
@@ -980,8 +1040,8 @@
                             errorTypeSa=None, \
                             precisionSa=None):
     """
-    Compute the Taylor form of 'degree' for 'functionSa' at 'point' 
-    for 'interval' with 'errorType' (a string). 
+    Compute the Taylor form of 'degreeSa' for 'functionSa' at 'pointSa' 
+    for 'intervalSa' with 'errorTypeSa' (a string) using 'precisionSa'. 
     point: must be a Real or a Real interval.
     return the Taylor form as an array
     TODO: take care of the interval and of the point when it is an interval;
@@ -1008,8 +1068,9 @@
             pobyso_set_prec_sa_so(precisionSa)
             precisionChangedSa = True
             
-    varSa = functionSa.variables()[0]
-    pobyso_name_free_variable_sa_so(str(varSa))
+    if len(functionSa.variables()) > 0:
+        varSa = functionSa.variables()[0]
+        pobyso_name_free_variable_sa_so(str(varSa))
     # In any case (point or interval) the parent of pointSa has a precision
     # method.
     pointPrecSa = pointSa.parent().precision()
@@ -1033,6 +1094,10 @@
     taylorFormSo = \
         sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
                                          None)
+    sollya_lib_clear_obj(functionSo)
+    sollya_lib_clear_obj(degreeSo)
+    sollya_lib_clear_obj(pointSo)
+    sollya_lib_clear_obj(errorTypeSo)
     (tfsAsList, numElements, isEndElliptic) = \
             pobyso_get_list_elements_so_so(taylorFormSo)
     polySo = tfsAsList[0]
@@ -1042,13 +1107,11 @@
     if precisionChangedSa:
         sollya_lib_set_prec(currentSollyaPrecSo)
         sollya_lib_clear_obj(currentSollyaPrecSo)
-    # Clean up.
-    sollya_lib_clear_obj(pointSo) # Works, whatever the type of pointSo is.
-    sollya_lib_clear_obj(errorTypeSo)
-    sollya_lib_clear_obj(degreeSo)
     polynomialRing = polyRealField[str(varSa)]
     polySa = polynomial(expSa, polynomialRing)
     taylorFormSa = [polySa]
+    # Final clean-up.
+    sollya_lib_clear_obj(taylorFormSo)
     return(taylorFormSa)
 # End pobyso_taylor_form_sa_sa
 
