Index: pobyso.py
===================================================================
--- pobyso.py	(revision 55)
+++ pobyso.py	(revision 56)
@@ -74,6 +74,7 @@
     SOLLYA_BASE_FUNC_TAN,
     SOLLYA_BASE_FUNC_TANH,
 SOLLYA_BASE_FUNC_TRIPLEDOUBLE) = map(int,xrange(44))
+print "\nSuperficial pobyso check..."    
 print "First constant - SOLLYA_BASE_FUNC_ABS: ", SOLLYA_BASE_FUNC_ABS
 print "Last constant  - SOLLYA_BASE_FUNC_TRIPLEDOUBLE: ", SOLLYA_BASE_FUNC_TRIPLEDOUBLE
 
@@ -298,21 +299,24 @@
     """ 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(constExp):
-    precision  = pobyso_get_prec_of_constant(constExp) 
-    RRRR = RealField(precision)
-    rn = RRRR(0)
-    sollya_lib_get_constant(get_rn_value(rn), constExp)
-    return(rn)
+def pobyso_get_constant_as_rn_so_sa(constExpSo):
+    precisionSa  = pobyso_get_prec_of_constant(constExpSo) 
+    RRRR = RealField(precisionSa)
+    rnSa = RRRR(0)
+    sollya_lib_get_constant(get_rn_value(rnSa), constExpSo)
+    return(rnSa)
 
 def pobyso_get_constant_as_rn_with_rf(ctExp, realField):
     """ 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(ctExp, realField):
-    rn = realField(0)
-    sollya_lib_get_constant(get_rn_value(rn), ctExp)
-    return(rn)
+def pobyso_get_constant_as_rn_with_rf_so_sa(ctExpSo, realFieldSa = None):
+    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)
 
 def pobyso_get_free_variable_name():
     """ Legacy function. See pobyso_get_free_variable_name_so_sa."""
@@ -339,25 +343,28 @@
     sollya_lib_get_head_function(byref(functionType), expressionSo, None)
     return(int(functionType.value))
 
-def pobyso_get_interval_from_range_so_sa(soRange):
+def pobyso_get_interval_from_range_so_sa(soRange, realIntervalFieldSa = None ):
     """
     Return the Sage interval corresponding to the Sollya range argument.
-    The interval bounds are not rounded: they are elements of RealIntervalField
-    of the "right" precision.
+    If no reaInterval lField is passed as argument, the interval bounds are not
+    rounded: they are elements of RealIntervalField of the "right" precision
+    to hold all the digits.
     """
     prec = c_int(0)
-    retval = sollya_lib_get_prec_of_range(byref(prec), soRange, None)
-    if retval == 0:
-        return(None)
-    RRRI = RealIntervalField(prec.value)
-    intervalSa = RRRI(0,0)
+    if realIntervalFieldSa is None:
+        retval = sollya_lib_get_prec_of_range(byref(prec), soRange, None)
+        if retval == 0:
+            return(None)
+        realIntervalFieldSa = RealIntervalField(prec.value)
+    intervalSa = realIntervalFieldSa(0,0)
     retval = \
         sollya_lib_get_interval_from_range(get_interval_value(intervalSa),\
                                            soRange)
     if retval == 0:
         return(None)
     return(intervalSa)
-    
+# End pobyso_get_interval_from_range_so_sa
+
 def pobyso_get_list_elements(soObj):
     """ Legacy function. See pobyso_get_list_elements_so_so. """
     return(pobyso_get_list_elements_so_so(soObj))
@@ -526,18 +533,28 @@
     Get the current default precision in Sollya.
     The return value is Sage/Python int.
     """
-    retc = sollya_lib_get_prec(None)
-    a = c_int(0)
-    sollya_lib_get_constant_as_int(byref(a), retc)
-    return(int(a.value))
+    precSo = sollya_lib_get_prec(None)
+    precSa = c_int(0)
+    sollya_lib_get_constant_as_int(byref(precSa), precSo)
+    sollya_lib_clear_obj(precSo)
+    return(int(precSa.value))
 
 def pobyso_get_prec_of_constant(ctExpSo):
     """ Legacy function. See pobyso_get_prec_of_constant_so_sa. """
     return(pobyso_get_prec_of_constant_so_sa(ctExpSo))
 
+def pobyso_get_prec_of_constant_so_sa(ctExpSo):
+    prec = c_int(0)
+    retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None)
+    if retc == 0:
+        return(None)
+    return(int(prec.value))
+
 def pobyso_get_prec_of_range_so_sa(rangeSo):
     prec = c_int(0)
     retc = sollya_lib_get_prec_of_range(byref(prec), rangeSo, None)
+    if retc == 0:
+        return(None)
     return(int(prec.value))
 
 def pobyso_infnorm_so_so(func, interval, file = None, intervalList = None):
@@ -565,12 +582,42 @@
     """ Legacy function. See pobyso_range_sa_so. """
     return(pobyso_range_sa_so(rnLowerBound, rnUpperBound)) 
 
-def pobyso_range_sa_so(rnLowerBound, rnUpperBound):
-    lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBound))
-    upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBound))
+def pobyso_range_sa_so(rnLowerBoundSa, rnUpperBoundSa):
+    """
+    Return a Sollya range from to 2 RealField elements.
+    The Sollya range element has a sufficient precision to hold all
+    the digits of the bounds.
+    """
+    # TODO: check the bounds.
+    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)
+    currentPrecSo = sollya_lib_get_prec(None)
+    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_so_sa(rangeSo, realIntervalField = None):
+    if realIntervalField is None:
+        precSa = pobyso_get_prec_of_range_so_sa(rangeSo)
+        realIntervalField = RealIntervalField(precSa)
+    intervalSa = \
+        pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalField) 
+    return(intervalSa)
+
 def pobyso_remez_canonical_sa_sa(func, \
                                  degree, \
                                  lowerBound, \
@@ -698,12 +745,36 @@
     return(sollya_lib_supnorm(polySo, funcSo, intervalSo, errorTypeSo, \
                               accuracySo))
 
+def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo, \
+                                                errorTypeSo, \
+                                                sollyaPrecSo=None):
+    # No global change of the working precision.
+    if not sollyaPrecSo is None:
+        initialPrecSo = sollya_lib_get_prec(None)
+        sollya_lib_set_prec(sollyaPrecSo)
+    #
+    intervalCenterSo = sollya_lib_mid(rangeSo)
+    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
+                                         intervalCenterSo, \
+                                         rangeSo, errorTypeSo, None)
+    (taylorFormListSo, numElements, isEndElliptic) = \
+        pobyso_get_list_elements_so_so(taylorFormSo)
+    polySo = 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(initailPrecSo)
+    return([polySo, intervalCenterSo, maxErrorSo])
+# end pobyso_taylor_expansion_no_change_var_so_so
+
 def pobyso_taylor(function, degree, point):
     """ Legacy function. See pobysoTaylor_so_so. """
     return(pobyso_taylor_so_so(function, degree, point))
 
-def pobyso_taylor_so_so(function, degree, point):
-    return(sollya_lib_taylor(function, degree, point))
+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 ;"""
@@ -810,7 +881,6 @@
     # There is no simple str() method defined for p's class.
     return(p.__str__())
 #
-print "Superficial test of pobyso:"    
 print pobyso_get_prec()  
 pobyso_set_prec(165)
 print pobyso_get_prec()  
@@ -819,4 +889,5 @@
 id(a)
 print "Max arity: ", pobyso_max_arity
 print "Function tripleDouble (43) as a string: ", pobyso_function_type_as_string(43)
-print "Function None (44) as a string: ", pobyso_function_type_as_string(44)
\ No newline at end of file
+print "Function None (44) as a string: ", pobyso_function_type_as_string(44)
+print "...Pobyso check done"
\ No newline at end of file
