Index: pobyso.py
===================================================================
--- pobyso.py	(revision 82)
+++ pobyso.py	(revision 83)
@@ -115,17 +115,20 @@
     #print "rnDummy: ", rnDummy
     # Compare the local Sage RealNumber with rnArg.
     return(cmp_rn_value(rnArg, 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):
     """
@@ -134,6 +137,7 @@
     funcSo = pobyso_parse_string(funcSa._assume_str())
     rangeSo = pobyso_range_sa_so(lowerBoundSa, upperBoundSa)
     infnormSo = pobyso_infnorm_so_so(funcSo,rangeSo)
+    # Sollya return the infnorm as an interval.
     fMaxSa = pobyso_get_interval_from_range_so_sa(infnormSo)
     # Get the top bound and compute the binade top limit.
     fMaxUpperBoundSa = fMaxSa.upper()
@@ -142,7 +146,7 @@
     funcAuxSo = pobyso_parse_string(str(binadeTopLimitSa) +  \
                                     '-(' + f._assume_str() + ')')
     pobyso_autoprint(funcAuxSo)
-    # Clear the Sollay range before a new call to infnorm and issue the call.
+    # Clear the Sollya range before a new call to infnorm and issue the call.
     sollya_lib_clear_obj(infnormSo)
     infnormSo = pobyso_infnorm_so_so(funcAuxSo,rangeSo)
     fMinSa = pobyso_get_interval_from_range_so_sa(infnormSo)
@@ -154,12 +158,12 @@
     # Create a RealIntervalField and create an interval with the "good" bounds.
     RRRI = RealIntervalField(maxPrecSa)
     imageIntervalSa = RRRI(fMinLowerBoundSa, fMaxUpperBoundSa)
-    # Free the uneeded Sollya objects
+    # Free the unneeded Sollya objects
     sollya_lib_clear_obj(funcSo)
     sollya_lib_clear_obj(funcAuxSo)
     sollya_lib_clear_obj(rangeSo)
     return(imageIntervalSa)
-    # End pobyso_compute_function_abs_val_bounds_sa_sa
+# End pobyso_compute_pos_function_abs_val_bounds_sa_sa
 
 def pobyso_constant(rnArg):
     """ Legacy function. See pobyso_constant_sa_so. """
@@ -301,37 +305,58 @@
     return(sollya_lib_get_constant(get_rn_value(rnArg), soConst))
     
 def pobyso_get_constant_as_rn(ctExpSo):
-    """ Legacy function. See pobyso_get_constant_as_rn_so_sa. """ 
+    """ 
+    Legacy function. See pobyso_get_constant_as_rn_so_sa. 
+    """ 
     return(pobyso_get_constant_as_rn_so_sa(ctExpSo))
     
 def pobyso_get_constant_as_rn_so_sa(constExpSo):
+    """
+    Get a Sollya constant as a Sage "real number".
+    The precision of the floating-point number returned is that of the Sollya
+    constant.
+    """
     precisionSa  = pobyso_get_prec_of_constant_so_sa(constExpSo) 
     RRRR = RealField(precisionSa)
     rnSa = RRRR(0)
     sollya_lib_get_constant(get_rn_value(rnSa), constExpSo)
     return(rnSa)
+# End pobyso_get_constant_as_rn_so_sa
 
 def pobyso_get_constant_as_rn_with_rf(ctExp, realField):
-    """ Legacy function. See pobyso_get_constant_as_rn_with_rf_so_sa."""
+    """ 
+    Legacy function. See pobyso_get_constant_as_rn_with_rf_so_sa.
+    """
     return(pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField))
     
 def pobyso_get_constant_as_rn_with_rf_so_sa(ctExpSo, realFieldSa = None):
+    """
+    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.
+    Otherwise is is that of the real field. Hence rounding may happen.
+    """
     if realFieldSa is None:
         sollyaPrecSa = pobyso_get_prec_so_sa()
         realFieldSa = RealField(sollyaPrecSa)
     rnSa = realFieldSa(0)
     sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo)
     return(rnSa)
+# End pobyso_get_constant_as_rn_with_rf_so_sa
 
 def pobyso_get_free_variable_name():
-    """ Legacy function. See pobyso_get_free_variable_name_so_sa."""
+    """ 
+    Legacy function. See pobyso_get_free_variable_name_so_sa.
+    """
     return(pobyso_get_free_variable_name_so_sa())
 
 def pobyso_get_free_variable_name_so_sa():
     return(sollya_lib_get_free_variable_name())
     
 def pobyso_get_function_arity(expressionSo):
-    """ Legacy function. See pobyso_get_function_arity_so_sa."""
+    """ 
+    Legacy function. See pobyso_get_function_arity_so_sa.
+    """
     return(pobyso_get_function_arity_so_sa(expressionSo))
 
 def pobyso_get_function_arity_so_sa(expressionSo):
@@ -340,7 +365,9 @@
     return(int(arity.value))
 
 def pobyso_get_head_function(expressionSo):
-    """ Legacy function. See pobyso_get_head_function_so_sa. """
+    """ 
+    Legacy function. See pobyso_get_head_function_so_sa. 
+    """
     return(pobyso_get_head_function_so_sa(expressionSo)) 
 
 def pobyso_get_head_function_so_sa(expressionSo):
@@ -351,7 +378,7 @@
 def pobyso_get_interval_from_range_so_sa(soRange, realIntervalFieldSa = None ):
     """
     Return the Sage interval corresponding to the Sollya range argument.
-    If no reaInterval lField is passed as argument, the interval bounds are not
+    If no reaIntervalField is passed as an argument, the interval bounds are not
     rounded: they are elements of RealIntervalField of the "right" precision
     to hold all the digits.
     """
@@ -456,6 +483,7 @@
     """
     #pobyso_autoprint(sollyaExp)
     operator = pobyso_get_head_function_so_sa(sollyaExp)
+    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 \
@@ -487,13 +515,16 @@
         return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExp, realField)
     elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
         #print "This is free variable"
-        return(eval(sollya_lib_get_free_variable_name()))
+        return(eval(sollyaLibFreeVariableName))
     else:
         print "Unexpected"
         return eval('None')
 # End pobyso_get_sage_poly_from_sollya_poly
 
 def pobyso_get_poly_sa_so(polySo, realFieldSa=None):
+    """
+    Create a Sollya polynomial from a Sage polynomial.
+    """
     pass
 # pobyso_get_poly_sa_so
 
@@ -537,7 +568,8 @@
     Get the subfunctions of an expression.
     Return the number of subfunctions and the list of subfunctions addresses.
     S.T.: Could not figure out another way than that ugly list of declarations
-    to recover the addresses of the subfunctions. 
+    to recover the addresses of the subfunctions.
+    We limit ourselves to arity 8 functions. 
     """
     subf0 = c_int(0)
     subf1 = c_int(0)
@@ -551,14 +583,20 @@
     arity = c_int(0)
     nullPtr = POINTER(c_int)()
     sollya_lib_get_subfunctions(expressionSo, byref(arity), \
-    byref(subf0), byref(subf1), byref(subf2), byref(subf3), byref(subf4), byref(subf5),\
-     byref(subf6), byref(subf7), byref(subf8), nullPtr, None) 
-#    byref(cast(subfunctions[0], POINTER(c_int))), byref(cast(subfunctions[0], POINTER(c_int))), \
-#    byref(cast(subfunctions[2], POINTER(c_int))), byref(cast(subfunctions[3], POINTER(c_int))), \
-#    byref(cast(subfunctions[4], POINTER(c_int))), byref(cast(subfunctions[5], POINTER(c_int))), \
-#    byref(cast(subfunctions[6], POINTER(c_int))), byref(cast(subfunctions[7], POINTER(c_int))), \
+      byref(subf0), byref(subf1), byref(subf2), byref(subf3), \
+      byref(subf4), byref(subf5),\
+      byref(subf6), byref(subf7), byref(subf8), nullPtr, None) 
+#    byref(cast(subfunctions[0], POINTER(c_int))), \
+#    byref(cast(subfunctions[0], POINTER(c_int))), \
+#    byref(cast(subfunctions[2], POINTER(c_int))), \
+#    byref(cast(subfunctions[3], POINTER(c_int))), \
+#    byref(cast(subfunctions[4], POINTER(c_int))), \
+#    byref(cast(subfunctions[5], POINTER(c_int))), \
+#    byref(cast(subfunctions[6], POINTER(c_int))), \
+#    byref(cast(subfunctions[7], POINTER(c_int))), \
 #    byref(cast(subfunctions[8], POINTER(c_int))), nullPtr)
-    subfunctions = [subf0, subf1, subf2, subf3, subf4, subf5, subf6, subf7, subf8]
+    subfunctions = [subf0, subf1, subf2, subf3, subf4, subf5, subf6, subf7, \
+                    subf8]
     subs = []
     if arity.value > pobyso_max_arity:
         return(0,[])
@@ -581,6 +619,7 @@
     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. """
@@ -612,6 +651,9 @@
     pobyso_name_free_variable_sa_so(freeVariableName)
 
 def pobyso_name_free_variable_sa_so(freeVariableName):
+    """
+    Set the free variable name in Sollya from a Sage string.
+    """
     sollya_lib_name_free_variable(freeVariableName)
 
 def pobyso_parse_string(string):
@@ -619,6 +661,9 @@
     return(pobyso_parse_string_sa_so(string))
  
 def pobyso_parse_string_sa_so(string):
+    """
+    Get the Sollya expression computed from a Sage string.
+    """
     return(sollya_lib_parse_string(string))
 
 def pobyso_range(rnLowerBound, rnUpperBound):
@@ -627,12 +672,14 @@
 
 def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa):
     """
-    Return a Sollya range from to 2 RealField elements.
+    Return a Sollya range from to 2 RealField Sage elements.
     The Sollya range element has a sufficient precision to hold all
-    the digits of the bounds.
+    the digits of the Sage bounds.
     """
+    # Sanity check.
     if rnLowerBoundSa > rnUpperBoundSa:
         return None
+    # Check for the largest precision.
     lbPrec = rnLowerBoundSa.parent().precision()
     ubPrec = rnLowerBoundSa.parent().precision()
     currentSollyaPrecSa = pobyso_get_prec_so_sa()
@@ -645,7 +692,6 @@
     lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa))
     upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa))
     rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
-    currentPrecSo = sollya_lib_get_prec(None)
     if maxPrecSa > currentSollyaPrecSa:
         sollya_lib_set_prec(currentPrecSo)
         sollya_lib_clear_obj(currentPrecSo)
@@ -655,6 +701,13 @@
     return(rangeSo)
 
 def pobyso_range_to_interval_so_sa(rangeSo, realIntervalField = 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.
+    """
     if realIntervalField is None:
         precSa = pobyso_get_prec_of_range_so_sa(rangeSo)
         realIntervalField = RealIntervalField(precSa)
@@ -672,20 +725,25 @@
     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.
+    The return value is a Sage polynomial.
     """
-    var('zorglub')    # Dummy variable name for type check only.
+    var('zorglub')    # Dummy variable name for type check only. Type of 
+    # zorglub is "symbolic expression".
     polySo = pobyso_remez_canonical_sa_so(func, \
                                  degree, \
                                  lowerBound, \
                                  upperBound, \
                                  weight = None, \
                                  quality = None)
+    # String test
     if parent(func) == parent("string"):
         functionSa = eval(func)
     # Expression test.
     elif type(func) == type(zorglub):
         functionSa = func
+    else:
+        return None
+    #
     maxPrecision = 0
     if polySo is None:
         return(None)
@@ -694,6 +752,7 @@
     polynomialRing = RRRR[functionSa.variables()[0]]
     expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRR)
     polySa = polynomial(expSa, polynomialRing)
+    sollya_lib_clear_obj(polySo)
     return(polySa)
     
 def pobyso_remez_canonical(func, \
@@ -721,7 +780,8 @@
     Otherwise the function fails. 
     The return value is a pointer to a Sollya function.
     """
-    var('zorglub')    # Dummy variable name for type check only.
+    var('zorglub')    # Dummy variable name for type check only. Type of
+    # zorglub is "symbolic expression".
     currentVariableName = None
     # The func argument can be of different types (string, 
     # symbolic expression...)
@@ -750,13 +810,22 @@
         qualitySo= pobyso_constant_sa_so(quality)
     else:
         qualitySo = None
-    return(sollya_lib_remez(functionSo, \
-                            degreeSo, \
-                            rangeSo, \
-                            weightSo, \
-                            qualitySo, \
-                            None))
-    
+        
+    remezPolySo = sollya_lib_remez(functionSo, \
+                                   degreeSo, \
+                                   rangeSo, \
+                                   weightSo, \
+                                   qualitySo, \
+                                   None)
+    sollya_lib_clear_obj(functionSo)
+    sollya_lib_clear_obj(degreeSo)
+    sollya_lib_clear_obj(rangeSo)
+    sollya_lib_clear_obj(weightSo)
+    if not qualitySo is None:
+        sollya_lib_clear_obj(qualtiySo)
+    return(remezPolySo)
+# End pobyso_remez_canonical_sa_so
+
 def pobyso_remez_canonical_so_so(funcSo, \
                                  degreeSo, \
                                  rangeSo, \
@@ -817,7 +886,7 @@
     # If changed, reset the Sollya working precision.
     if not sollyaPrecSo is None:
         sollya_lib_set_prec(initialPrecSo)
-        sollya_lib_clear_obj(initailPrecSo)
+        sollya_lib_clear_obj(initialPrecSo)
     return((polyVarChangedSo, intervalCenterSo, maxErrorSo))
 # end pobyso_taylor_expansion_with_change_var_so_so
 
@@ -870,10 +939,10 @@
     for 'interval' with 'errorType'. 
     point: must be a Real or a Real interval.
     return the Taylor form as an array
-    TODO: take care of the interval and of point when it is an interval;
+    TODO: take care of the interval and of the point when it is an interval;
           when errorType is not None;
-          take care of the other elements of the Taylor form (coefficients errors and
-          delta.
+          take care of the other elements of the Taylor form (coefficients 
+          errors and delta.
     """
     # Absolute as the default error.
     if errorType is None:
@@ -902,7 +971,8 @@
         # TODO: deal with the interval case.
         pass
     # Call Sollya
-    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
+    taylorFormSo = \
+        sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
                                          None)
     (tfsAsList, numElements, isEndElliptic) = \
             pobyso_get_list_elements_so_so(taylorFormSo)
