Index: pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage
===================================================================
--- pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage	(revision 80)
+++ pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage	(revision 81)
@@ -96,4 +96,6 @@
                     "has no \"numerator()\" member." 
             return([])
     return(numeratorsList)
-# End sro_numerators
\ No newline at end of file
+# End sro_numerators
+
+print "sageRationalOperations loaded..."
\ No newline at end of file
Index: pobysoPythonSage/src/sageSLZ/sageSLZ-Notes.html
===================================================================
--- pobysoPythonSage/src/sageSLZ/sageSLZ-Notes.html	(revision 80)
+++ pobysoPythonSage/src/sageSLZ/sageSLZ-Notes.html	(revision 81)
@@ -306,21 +306,28 @@
 <h2>The approximation interval problem</h2>
 
 <p>When Sollya computes an approximation polynomial for a given function,
-degree and range, it also returns the approximation error (and the center of
-the interval as well).</p>
+degree and range, it also returns the approximation error (refered to, in the sequel, 
+as the
+		<span class="langElem">computedError</span> and the center of
+the interval as well).
+	</p>
 
-<p>Very often we want to solve a slightly different problem: for a given
-function, degree, lower bound and approximation error, computed the
+<p>Very often, we want to solve a slightly different problem: for a given
+function, degree, lower bound and approximation error (referred to,  in the 
+sequel, as the
+		<span class="langElem">targetError</span> ), compute the
 approximation polynomial and the upper bound of the interval comprised between
-it and the upper bound for which the approximation error stands.</p>
+it and the lower bound for which the approximation error stands.
+	</p>
 
-<p>Very often the idea is to break a given &ldquo;large&rdquo; into a
+<p>The idea is to break a given initially &ldquo;large&rdquo; interval into a
 collection of smaller intervals because for the given function-degree-error the
 initial interval is too large.</p>
 
-<p>The naive approach is to:</p>
+<p>The most naive approach is to:</p>
 <ol>
-  <li>give it a try with the initial data;</li>
+  <li>give it a try with the initial data (a very probably too high upper bound
+      for the given <span class="langElem">targetError</span>);</li>
   <li>when you get a too large error, reduce (e. g. divide by 2) the interval by
     lowering the upper bound until the computed error matches the target
     error;</li>
@@ -330,15 +337,16 @@
 </ol>
 
 <p>In step 2 you may have to compute several polynomials until the computed
-error is below or equal to the expected error. You must not decrease the
-interval width too agressively.  There is no point in getting a too small approximation error since it multiplies the number of interval (and
+error is below or equal to the expected error. But you must not decrease the
+interval width too agressively:  there is no point in getting a too small 
+approximation error since it multiplies the number of interval (and
 lengthens the subsequent manipulations that are made on each sub-interval).</p>
 
 <p>In step 3 you probably inutily compute polynomials for too large intervals
 and you could know it from the previous computations.</p>
 
 <p>The whole idea is to reduce the number of polynomial computations and get the
-maximum width (compatible with the expected approwimaiton error).</p>
+maximum width (compatible with the target error).</p>
 
 <p>This process has different aspects:</p>
 <ol>
@@ -347,14 +355,26 @@
   <li>reuse the computation already done in previous steps.</li>
 </ol>
 
-<p>For point 1, can something be done with the derivative at the upper bound or
-at the center point of the interval (also given by Sollya).</p>
+<p>We use two strategies.</p>
+	<p>The first is in the inner function that computes the first approximation 
+	   polynomial. If the upper bound is too high, we shrink the interval by a non
+	   linear (and complex) factor computed from the ratio beetwen the obtained 
+	   error and the target error.<br>The whole idea is not to end up with a too 
+	   small interval.</p>
+	<p>This only takes into account aspect 1</p>.   
+	<p>The second strategy is in the outer function. In this function the 
+	    computed intervals returned by the inner function give all correct 
+	    approximation errors. The computation of  next upper bound will take into 
+	    account the value of the previous interval and that of the previous 
+	    computed error.</p>
+	<p>If the errors ratio is lower than 2, we try the same interval length 
+	   as given by the previous computation.  If larger we increase the next 
+	   interval but by a small margin (log2(errorsRatio).</p>
 
-<p>For point 2, can some type of data structure keep the informations (which
-ones ?) and allow for an efficient reuse.</p>
-
-<p>Adjacent question: is it possible, given a the result of a previous
-computation, to forecast the effect on the approximation precision of a degree
-in(de)crease?</p>
+   <p>In this case, aspects 1 and 2 are considered </p>
+   
+<p>For the moment, we do not resort to more complex forcasting techniques 
+   (using the derivative of the function?). This could be an option if the 
+   present strategies did not output enough performance. </p>
 </body>
 </html>
Index: pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage
===================================================================
--- pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage	(revision 80)
+++ pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage	(revision 81)
@@ -107,6 +107,22 @@
     return(expressionAsString)
 # End spo_expression_as_string.
 
+def spo_norm(poly, degree):
+    """
+    Behaves more or less (no infinity defined) as the norm for the
+    univariate polynomials.
+    Quoting the Sage documentation:
+    Definition: For integer p, the p-norm of a polynomial is the pth root of 
+    the sum of the pth powers of the absolute values of the coefficients of 
+    the polynomial.
+    """
+    # TODO: check the arguments.
+    norm = 0
+    for coefficient in poly.coefficients():
+        norm +=  (coefficient^degree).abs()
+    return pow(norm, 1/degree)
+# end spo_norm
+
 def spo_polynomial_to_matrix(p, pRing, alpha, N, columnsWidth=0):
     """
     From a (bivariate) polynomial and some other parameters build a matrix
@@ -316,3 +332,5 @@
     # End for pPower loop
     return protoMatrixRows
 # End spo_polynomial_to_matrix
+
+print "sagePolynomialOperations loaded..."
\ No newline at end of file
Index: pobysoPythonSage/src/sageSLZ/sageSLZ.sage
===================================================================
--- pobysoPythonSage/src/sageSLZ/sageSLZ.sage	(revision 80)
+++ pobysoPythonSage/src/sageSLZ/sageSLZ.sage	(revision 81)
@@ -12,8 +12,6 @@
     are returned.
     """
     RRR = lowerBoundSa.parent()
-    #goldenRatioSa = RRR(5.sqrt() / 2 - 1/2)
-    #intervalShrinkConstFactorSa = goldenRatioSa
     intervalShrinkConstFactorSa = RRR('0.5')
     absoluteErrorTypeSo = pobyso_absolute_so_so()
     currentRangeSo = pobyso_bounds_to_range_sa_so(lowerBoundSa, upperBoundSa)
@@ -29,19 +27,23 @@
     maxErrorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
     while maxErrorSa > approxPrecSa:
         sollya_lib_clear_obj(maxErrorSo)
-        errorRatioSa = 1/(maxErrorSa/approxPrecSa).log2()
+        sollya_lib_clear_obj(polySo)
+        sollya_lib_clear_obj(intervalCenterSo)
+        shrinkFactorSa = RRR('5.0')/(maxErrorSa/approxPrecSa).log2().abs()
+        #shrinkFactorSa = 1.5/(maxErrorSa/approxPrecSa)
+        #errorRatioSa = approxPrecSa/maxErrorSa
         #print "Error ratio: ", errorRatioSa
-        if errorRatioSa > intervalShrinkConstFactorSa:
-            currentUpperBoundSa = currentLowerBoundSa + \
-                                  (currentUpperBoundSa - currentLowerBoundSa) * \
-                                   intervalShrinkConstFactorSa
+        
+        if shrinkFactorSa > intervalShrinkConstFactorSa:
+            actualShrinkFactorSa = intervalShrinkConstFactorSa
+            #print "Fixed"
         else:
-            currentUpperBoundSa = currentLowerBoundSa + \
+            actualShrinkFactorSa = shrinkFactorSa
+            #print "Computed",shrinkFactorSa,maxErrorSa
+            #print shrinkFactorSa, maxErrorSa
+        currentUpperBoundSa = currentLowerBoundSa + \
                                   (currentUpperBoundSa - currentLowerBoundSa) * \
-                                  intervalShrinkConstFactorSa
-            currentUpperBoundSa = currentLowerBoundSa + \
-                                  (currentUpperBoundSa - currentLowerBoundSa) * \
-                                  errorRatioSa
+                                   actualShrinkFactorSa
         #print "Current upper bound:", currentUpperBoundSa
         sollya_lib_clear_obj(currentRangeSo)
         sollya_lib_clear_obj(polySo)
@@ -55,7 +57,7 @@
         maxErrorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
     sollya_lib_clear_obj(absoluteErrorTypeSo)
     return((polySo, currentRangeSo, intervalCenterSo, maxErrorSo))
-    # End slz_compute_polynomial_and_interval
+# End slz_compute_polynomial_and_interval
 
 def slz_compute_scaled_function(functionSa, \
                                       lowerBoundSa, \
@@ -111,7 +113,7 @@
     polynomialRing = QQ[str(polyOfFloat.variables()[0])]
     return(polynomialRing(polyOfFloat))
 # End slz_float_poly_of_float_to_rat_poly_of_rat
-     
+
 def slz_get_intervals_and_polynomials(functionSa, degreeSa, 
                                       lowerBoundSa, 
                                       upperBoundSa, floatingPointPrecSa, 
@@ -166,13 +168,30 @@
     realIntervalField = RealIntervalField(max(lowerBoundSa.parent().precision(),
                                               upperBoundSa.parent().precision()))
     boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField)
+    # Compute the next upper bound.
+    # If the error of approximation is more than half of the target,
+    # use the same interval.
+    # If it is less, increase it a bit.
+    errorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
+    currentErrorRatio = approxPrecSa / errorSa
+    currentScaledUpperBoundSa = boundsSa.endpoints()[1]
+    if currentErrorRatio  < 2 :
+        currentScaledUpperBoundSa += \
+            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0])
+    else:
+        currentScaledUpperBoundSa += \
+            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0]) \
+                         * currentErrorRatio.log2() * 2
+    if currentScaledUpperBoundSa > scaledUpperBoundSa:
+        currentScaledUpperBoundSa = scaledUpperBoundSa
     # Compute the other expansions.
     while boundsSa.endpoints()[1] < scaledUpperBoundSa:
         currentScaledLowerBoundSa = boundsSa.endpoints()[1]
         (polySo, boundsSo, intervalCenterSo, maxErrorSo) = \
             slz_compute_polynomial_and_interval(functionSo, degreeSo,
                                             currentScaledLowerBoundSa, 
-                                            scaledUpperBoundSa, approxPrecSa, 
+                                            currentScaledUpperBoundSa, 
+                                            approxPrecSa, 
                                             internalSollyaPrecSa)
         # Change variable stuff
         changeVarExpressionSo = sollya_lib_build_function_sub(
@@ -182,12 +201,35 @@
         resultArray.append((polySo, polyVarChangedSo, boundsSo, \
                             intervalCenterSo, maxErrorSo))
         boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField)
+        # Compute the next upper bound.
+        # If the error of approximation is more than half of the target,
+        # use the same interval.
+        # If it is less, increase it a bit.
+        errorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
+        currentErrorRatio = approxPrecSa / errorSa
+        if currentErrorRatio  < RR('1.5') :
+            currentScaledUpperBoundSa = \
+                            boundsSa.endpoints()[1] + \
+                            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0])
+        elif currentErrorRatio < 2:
+            currentScaledUpperBoundSa = \
+                            boundsSa.endpoints()[1] + \
+                            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0]) \
+                             * currentErrorRatio.log2()
+        else:
+            currentScaledUpperBoundSa = \
+                            boundsSa.endpoints()[1] + \
+                            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0]) \
+                             * currentErrorRatio.log2() * 2
+        if currentScaledUpperBoundSa > scaledUpperBoundSa:
+            currentScaledUpperBoundSa = scaledUpperBoundSa
     sollya_lib_clear_obj(functionSo)
     sollya_lib_clear_obj(degreeSo)
     sollya_lib_clear_obj(scaledBoundsSo)
     return(resultArray)
-    # End slz_get_intervals_and_polynomials
+# End slz_get_intervals_and_polynomials
 
+
 def slz_interval_scaling_expression(boundsInterval, expVar):
     """
     Compute the scaling expression to map an interval that span only
Index: pobysoPythonSage/src/pobyso.py
===================================================================
--- pobysoPythonSage/src/pobyso.py	(revision 80)
+++ pobysoPythonSage/src/pobyso.py	(revision 81)
@@ -522,7 +522,7 @@
     #pobyso_autoprint(polySo)
     polyVariableSa = expressionSa.variables()[0]
     polyRingSa = realFieldSa[str(polyVariableSa)]
-    print polyRingSa
+    #print polyRingSa
     # Do not use the polynomial(expressionSa, ring=polyRingSa) form!
     polynomialSa = polyRingSa(expressionSa)
     return(polynomialSa)
