Index: pobysoPythonSage/src/pobyso.py
===================================================================
--- pobysoPythonSage/src/pobyso.py	(revision 83)
+++ pobysoPythonSage/src/pobyso.py	(revision 84)
@@ -94,6 +94,41 @@
 def pobyso_absolute_so_so():
     return(sollya_lib_absolute(None))
 
+def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa, \
+                                 precisionSa=None):
+    """
+    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 Sage bounds.
+    """
+    # Sanity check.
+    if rnLowerBoundSa > rnUpperBoundSa:
+        return None
+    if precision is None:
+        # Check for the largest precision.
+        lbPrecSa = rnLowerBoundSa.parent().precision()
+        ubPrecSa = rnLowerBoundSa.parent().precision()
+        maxPrecSa = max(lbPrecSa, ubPrecSa)
+    else:
+        maxPrecSa = precisionSa
+    sollyaCurrentPrecSo = pobyso_get_prec_so()
+    sollyaCurrentPrecSa = pobyso_constant_from_int_so_sa(sollyaCurrentPrecSo)
+    # Change the current Sollya precision only if necessary.
+    if maxPrecSa > sollyaCurrentPrecSa:
+        pobyso_set_prec_sa_so(maxPrecSa)
+    lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa))
+    upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa))
+    rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
+    # Back to original precision.
+    if maxPrecSa > sollyaCurrentPrecSa:
+        sollya_lib_set_prec(sollyaCurrentPrecSo)
+    # Clean up
+    sollya_lib_clear_obj(sollyaCurrentPrecSo)
+    sollya_lib_clear_obj(lowerBoundSo)
+    sollya_lib_clear_obj(upperBoundSo)
+    return(rangeSo)
+# End pobyso_bounds_to_range_sa_so
+
 def pobyso_build_function_sub_so_so(exp1So, exp2So):
     return(sollya_lib_build_function_sub(exp1So, exp2So))
 
@@ -169,11 +204,22 @@
     """ Legacy function. See pobyso_constant_sa_so. """
     return(pobyso_constant_sa_so(rnArg))
     
-def pobyso_constant_sa_so(rnArg):
+def pobyso_constant_sa_so(rnArgSa, precisionSa=None):
     """
     Create a Sollya constant from a RealNumber.
     """
-    return(sollya_lib_constant(get_rn_value(rnArg)))
+    # Precision stuff
+    if precisionSa is None:
+        precisionSa = rnArgSa.parent().precision()
+    currentSollyaPrecisionSo = pobyso_get_prec_so()
+    currentSollyaPrecisionSa = pobyso_get
+    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))
+    return(constantSo)
     
 def pobyso_constant_0_sa_so():
     return(pobyso_constant_from_int_sa_so(0))
@@ -192,6 +238,16 @@
 def pobyso_constant_from_int_sa_so(anInt):
     return(sollya_lib_constant_from_int(int(anInt)))
 
+def pobyso_constant_from_int_so_sa(constSo):
+    """
+    Get a Sollya constant as an int.
+    Use full for precision or powers in polynomials.
+    """
+    constSa = c_int(0)
+    sollya_lib_get_constant_as_int(byref(constSa), constSo)
+    return(constSa.value)
+# End pobyso_constant_from_int_so_sa
+
 def pobyso_function_type_as_string(funcType):
     """ Legacy function. See pobyso_function_type_as_string_so_sa. """
     return(pobyso_function_type_as_string_so_sa(funcType))
@@ -296,13 +352,13 @@
     """ Legacy function. See pobyso_get_constant_so_sa. """
     return(pobyso_get_constant_so_sa(rnArg, soConst))
 
-def pobyso_get_constant_so_sa(rnArg, soConst):
+def pobyso_get_constant_so_sa(rnArgSa, constSo):
     """
     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.
     """
-    return(sollya_lib_get_constant(get_rn_value(rnArg), soConst))
+    return(sollya_lib_get_constant(get_rn_value(rnArgSa), constSo))
     
 def pobyso_get_constant_as_rn(ctExpSo):
     """ 
@@ -609,6 +665,15 @@
     """ 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.
@@ -643,6 +708,15 @@
     print "Do not use this function. User pobyso_supnorm_so_so instead."
     return(None)
 
+def pobyso_interval_to_range_sa_so(intervalSa, precisionSa=None):
+    if precisionSa is None:
+        precisionSa = intervalSa.parent().precision()
+    intervalSo = pobyso_bounds_to_range_sa_so(intervalSa.lower(),\
+                                              intervalSa.upper(),\
+                                              precisionSa)
+    return(intervalSo)
+# End pobyso_interval_to_range_sa_so
+
 def pobyso_lib_init():
     sollya_lib_init(None)
     
@@ -670,35 +744,6 @@
     """ Legacy function. See pobyso_range_sa_so. """
     return(pobyso_range_sa_so(rnLowerBound, rnUpperBound)) 
 
-def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa):
-    """
-    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 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()
-    maxPrecSa = max(lbPrec, ubPrec, currentSollyaPrecSa)
-    # Change the current Sollya precision only if necessary.
-    if maxPrecSa > currentSollyaPrecSa:
-        currentPrecSo = sollya_lib_get_prec(None)
-        newPrecSo = solly_lib_constant_from_uint64(maxPrecSa)
-        sollya_lib_set_prec(newPrecSo)
-    lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa))
-    upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa))
-    rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
-    if maxPrecSa > currentSollyaPrecSa:
-        sollya_lib_set_prec(currentPrecSo)
-        sollya_lib_clear_obj(currentPrecSo)
-        sollya_lib_clear_obj(newPrecSo)
-    sollya_lib_clear_obj(lowerBoundSo)
-    sollya_lib_clear_obj(upperBoundSo)
-    return(rangeSo)
 
 def pobyso_range_to_interval_so_sa(rangeSo, realIntervalField = None):
     """
@@ -929,14 +974,14 @@
     """ Legacy function. See ;"""
     
 def pobyso_taylorform_sa_sa(functionSa, \
-                            degree, \
-                            point, \
-                            precision, \
-                            interval=None, \
-                            errorType=None):
+                            degreeSa, \
+                            pointSa, \
+                            intervalSa=None, \
+                            errorTypeSa=None, \
+                            precisionSa=None):
     """
     Compute the Taylor form of 'degree' for 'functionSa' at 'point' 
-    for 'interval' with 'errorType'. 
+    for 'interval' with 'errorType' (a string). 
     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;
@@ -945,31 +990,45 @@
           errors and delta.
     """
     # Absolute as the default error.
-    if errorType is None:
+    if errorTypeSa is None:
         errorTypeSo = sollya_lib_absolute()
+    elif errorTypeSa == "relative":
+        errorTypeSo = sollya_lib_relative()
+    elif errortypeSa == "absolute":
+        errorTypeSo = sollya_lib_absolute()
     else:
-        #TODO: deal with the other case.
-        pass
+        # No clean up needed.
+        return None
+    # Global precision stuff
+    precisionChangedSa = False
+    currentSollyaPrecSo = pobyso_get_prec_so()
+    currentSollyaPrecSa = pobyso_constant_from_int_so_sa(currentSollyaPrecSo)
+    if not precisionSa is None:
+        if precisionSa > currentSollyaPrecSa:
+            pobyso_set_prec_sa_so(precisionSa)
+            precisionChangedSa = True
+            
     varSa = functionSa.variables()[0]
-    pointBaseRingString = str(point.base_ring())
-    if not re.search('Real', pointBaseRingString):
-        return None
-    # Call Sollya but first "sollyafy" the arguments.
     pobyso_name_free_variable_sa_so(str(varSa))
-    #pobyso_set_prec_sa_so(300)
+    # In any case (point or interval) the parent of pointSa has a precision
+    # method.
+    pointPrecSa = pointSa.parent().precision()
+    if precisionSa > pointPrecSa:
+        pointPrecSa = precisionSa
+    # In any case (point or interval) pointSa has a base_ring() method.
+    pointBaseRingString = str(pointSa.base_ring())
+    if re.search('Interval', pointBaseRingString) is None: # Point
+        pointSo = pobyso_constant_sa_so(pointSa, pointPrecSa)
+    else: # Interval.
+        pointSo = pobyso_interval_to_range_sa_so(pointSa, pointPrecSa)
     # Sollyafy the function.
     functionSo = pobyso_parse_string_sa_so(functionSa._assume_str())
     if sollya_lib_obj_is_error(functionSo):
         print "pobyso_tailorform: function string can't be parsed!"
         return None
     # Sollyafy the degree
-    degreeSo = sollya_lib_constant_from_int(int(degree))
+    degreeSo = sollya_lib_constant_from_int(int(degreeSa))
     # Sollyafy the point
-    if not re.search('Interval', pointBaseRingString):
-        pointSo  = pobyso_constant_sa_so(point)
-    else:
-        # TODO: deal with the interval case.
-        pass
     # Call Sollya
     taylorFormSo = \
         sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
@@ -980,7 +1039,13 @@
     maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
     polyRealField = RealField(maxPrecision)
     expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, polyRealField)
-    sollya_lib_close()
+    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]
