Index: pobyso.py
===================================================================
--- pobyso.py	(revision 271)
+++ pobyso.py	(revision 272)
@@ -521,7 +521,16 @@
         precSo = pobyso_constant_from_int(precSa)
         pobyso_set_prec_so_so(precSo)
         sollya_lib_clear_obj(precSo)
-        sollyaPrecChanged = True    
+        sollyaPrecChanged = True
+    ## Free variable stuff.
+    freeVariableNameChanged = False 
+    polyFreeVariableNameSa = \
+        str(polySa.variables()[0])
+    currentFreeVariableNameSa = pobyso_get_free_variable_name_so_sa() 
+    if polyFreeVariableNameSa != currentFreeVariableNameSa:
+        #print "Free variable names do not match.", polyFreeVariableNameSa
+        sollya_lib_name_free_variable(polyFreeVariableNameSa)
+        freeVariableNameChanged = True
     ## Get exponents and coefficients.
     exponentsSa     = polySa.exponents()
     coefficientsSa  = polySa.coefficients()
@@ -546,7 +555,10 @@
             polySo = sollya_lib_build_function_add(polySo, polyTermSo)
     if sollyaPrecChanged:
         pobyso_set_prec_so_so(initialSollyaPrecSo)
-        sollya_lib_clear_obj(initialSollyaPrecSo)
+    sollya_lib_clear_obj(initialSollyaPrecSo)
+    ## Do not set back the free variable name in Sollya to its initial value: 
+    #  it will change it back, in the Sollya polynomial, to what it was in the 
+    #  first place.
     return polySo
 # End pobyso_float_poly_sa_so    
 
@@ -1569,6 +1581,8 @@
 def pobyso_rat_poly_sa_so(polySa, precSa = None):
     """
     Create a Sollya polynomial from a Sage rational polynomial.
+    We first convert the rational polynomial into a floating-point 
+    polynomial.
     """
     ## TODO: filter arguments.
     ## Precision. If no precision is given, use the current precision
@@ -1581,7 +1595,7 @@
     P_RRR = RRR[polySa.variables()[0]]
     polyFloatSa = P_RRR(polySa)
     ## Make sure no precision is provided: pobyso_float_poly_sa_so will
-    #  recover it all by itself and not make an extra conversion.
+    #  recover it all by itself and will not make any extra conversion.
     return pobyso_float_poly_sa_so(polyFloatSa)
     
 # End pobyso_rat_poly_sa_so    
@@ -1807,6 +1821,10 @@
                                                 currentApproxErrorSo,
                                                 approxAccurSo,
                                                 debug=False):
+    """
+    From an input approximation polynomial, compute an output one with 
+    smaller coefficients and yet yields a sufficient approximation accuracy.
+    """
     if debug:
         print "Input arguments:"
         print "Polynomial: ", ; pobyso_autoprint(polySo)
@@ -1822,7 +1840,7 @@
     #  no possible gain.
     if currentApproxErrorSa >= approxAccurSa / 2:
         #### Do not return the initial argument but copies: caller may free 
-        #    as inutile after call.
+        #    the former as inutile after call.
         return (sollya_lib_copy_obj(polySo),
                 sollya_lib_copy_obj(currentApproxErrorSo))
     degreeSa             = pobyso_polynomial_degree_so_sa(polySo)
@@ -1833,12 +1851,13 @@
         print "intervalSa            :", intervalSa.str(style='brackets')
         print "currentApproxErrorSa  :", currentApproxErrorSa 
         print "approxAccurSa         :", approxAccurSa 
-    ### Start with a 0 value expression.
     radiusSa = intervalSa.absolute_diameter() / 2
     if debug:
         print "log2(radius):", RR(radiusSa).log2()
     iterIndex = 0
+    ## Build the "shaved" polynomial.
     while True: 
+        ### Start with a 0 value expression.
         resPolySo = pobyso_constant_0_sa_so()
         roundedPolyApproxAccurSa = approxAccurSa / 2
         currentRadiusPowerSa = 1 
@@ -1851,8 +1870,8 @@
             else:
                 roundingPowerSa = \
                     floor(((currentRadiusPowerSa/roundedPolyApproxAccurSa)*(degreeSa+1)).log2())
-            ## Under extreme conditions the above formulas can evaluate under 2, which is the
-            #  minimal precision of an MPFR number.
+            ## Under extreme conditions the above formulas can evaluate under 2,
+            #   which is the minimal precision of an MPFR number.
             if roundingPowerSa < 2:
                 roundingPowerSa = 2
             if debug:
@@ -1901,7 +1920,7 @@
                 #    free the former as inutile after call.
                 return (sollya_lib_copy_obj(polySo), 
                         sollya_lib_copy_obj(currentApproxErrorSo))
-            else: # Round 0, got round 1
+            else: # Round 0 (agressive rounding), got round 1 (proved rounding)
                 sollya_lib_clear_obj(resPolySo)
                 sollya_lib_clear_obj(infNormSo)
                 iterIndex += 1
@@ -2018,6 +2037,8 @@
     """
     Compute the Taylor expansion without the variable change
     x -> x-intervalCenter.
+    If errorTypeSo is None, absolute is used.
+    If sollyaPrecSo is None, Sollya internal precision is not changed. 
     """
     # Change internal Sollya precision, if needed.
     (initialSollyaPrecSo, initialSollyaPrecSa) = pobyso_get_prec_so_so_sa()
@@ -2037,33 +2058,35 @@
     taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo,
                                          intervalCenterSo,
                                          rangeSo, errorTypeSo, None)
-    # taylorFormListSaSo is a Python list of Sollya objects references that 
-    # are copies of the elements of taylorFormSo.
+    # Object taylorFormListSaSo is a Python list of Sollya objects references 
+    #  that are copies of the elements of taylorFormSo.
     # pobyso_get_list_elements_so_so clears taylorFormSo.
     (taylorFormListSaSo, numElementsSa, isEndEllipticSa) = \
         pobyso_get_list_elements_so_so(taylorFormSo)
+    ## Copy needed here since polySo will be returned and taylorFormListSaSo
+    #  will be cleared.
     polySo = sollya_lib_copy_obj(taylorFormListSaSo[0])
     #print "Num elements:", numElementsSa
     sollya_lib_clear_obj(taylorFormSo)
-    #polySo = taylorFormListSaSo[0]
-    #errorRangeSo = sollya_lib_copy_obj(taylorFormListSaSo[2])
-    errorRangeSo = taylorFormListSaSo[2]
     # No copy_obj needed here: a new objects are created.
-    maxErrorSo    = sollya_lib_sup(errorRangeSo)
-    minErrorSo    = sollya_lib_inf(errorRangeSo)
+    maxErrorSo    = sollya_lib_sup(taylorFormListSaSo[2])
+    minErrorSo    = sollya_lib_inf(taylorFormListSaSo[2])
+    # List taylorFormListSaSo is not needed anymore.
+    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
     absMaxErrorSo = sollya_lib_abs(maxErrorSo)
     absMinErrorSo = sollya_lib_abs(minErrorSo)
     sollya_lib_clear_obj(maxErrorSo)
     sollya_lib_clear_obj(minErrorSo)
     absMaxErrorSa = pobyso_get_constant_as_rn_so_sa(absMaxErrorSo)
     absMinErrorSa = pobyso_get_constant_as_rn_so_sa(absMinErrorSo)
-    # If changed, reset the Sollya working precision.
+    #
+    if errorTypeIsNone:
+        sollya_lib_clear_obj(errorTypeSo)
+    ## If changed, reset the Sollya working precision.
     if sollyaPrecChanged:
         sollya_lib_set_prec(initialSollyaPrecSo)
     sollya_lib_clear_obj(initialSollyaPrecSo)
-    if errorTypeIsNone:
-        sollya_lib_clear_obj(errorTypeSo)
-    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
+    ## According to what error is the largest, return the errors.
     if absMaxErrorSa > absMinErrorSa:
         sollya_lib_clear_obj(absMinErrorSo)
         return (polySo, intervalCenterSo, absMaxErrorSo)
@@ -2099,15 +2122,17 @@
     taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
                                          intervalCenterSo, \
                                          rangeSo, errorTypeSo, None)
-    # taylorFormListSaSo is a Python list of Sollya objects references that 
-    # are copies of the elements of taylorFormSo.
+    # Object taylorFormListSaSo is a Python list of Sollya objects references 
+    # that are copies of the elements of taylorFormSo.
     # pobyso_get_list_elements_so_so clears taylorFormSo.
-    (taylorFormListSo, numElements, isEndElliptic) = \
+    (taylorFormListSaSo, numElements, isEndElliptic) = \
         pobyso_get_list_elements_so_so(taylorFormSo)
-    polySo = taylorFormListSo[0]
-    errorRangeSo = taylorFormListSo[2]
-    maxErrorSo    = sollya_lib_sup(errorRangeSo)
-    minErrorSo    = sollya_lib_inf(errorRangeSo)
+    sollya_lib_clear_obj(taylorFormSo)
+    polySo = taylorFormListSaSo[0]
+    ## Maximum error computation with taylorFormListSaSo[2], a range
+    #  holding the actual error. Bounds can be negative.
+    maxErrorSo    = sollya_lib_sup(taylorFormListSaSo[2])
+    minErrorSo    = sollya_lib_inf(taylorFormListSaSo[2])
     absMaxErrorSo = sollya_lib_abs(maxErrorSo)
     absMinErrorSo = sollya_lib_abs(minErrorSo)
     sollya_lib_clear_obj(maxErrorSo)
@@ -2118,7 +2143,8 @@
                        sollya_lib_build_function_free_variable(),\
                        sollya_lib_copy_obj(intervalCenterSo))
     polyVarChangedSo = sollya_lib_evaluate(polySo, changeVarExpSo)
-    sollya_lib_clear_obj(polySo) 
+    # List taylorFormListSaSo is not needed anymore.
+    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
     sollya_lib_clear_obj(changeVarExpSo)
     # If changed, reset the Sollya working precision.
     if sollyaPrecChanged:
@@ -2126,7 +2152,6 @@
     sollya_lib_clear_obj(initialSollyaPrecSo)
     if errorTypeIsNone:
         sollya_lib_clear_obj(errorTypeSo)
-    sollya_lib_clear_obj(taylorFormSo)
     # Do not clear maxErrorSo.
     if absMaxErrorSa > absMinErrorSa:
         sollya_lib_clear_obj(absMinErrorSo)
