> For moderate arguments final adjustment to
> satisfy requirements of ISQRT may add nontrivial cost.

That's not entirely true: with following patch
and testcase
    [approxSqrt(x) for x in (1..2*10^5)];

it's 0.86s v.s. 0.80s.

Well, for small arguments we can even hard code answers.

So I propose to
1. change the documentation to \spad{-1 < x - sqrt(n) <= 0}
2. apply following check
3. use ISQRT for INT/NNI/PI

--- a/src/algebra/intfact.spad
+++ b/src/algebra/intfact.spad
@@ -300,11 +300,16 @@
          n := n quo (4::I)
          s := approxSqrt shift(a, -2 * n)
          s := shift(s, n)
-         return ((1 + s + a quo s) quo two)
+         new := ((1 + s + a quo s) quo two)
+         err0 := new*new - a
+         if err0 > 0 then new:=new-1
+         return new
       -- initial approximation for the root is within a factor of 2
       (new, old) := (shift(1, n quo two), 1)
       while new ~= old repeat
          (new, old) := ((1 + new + a quo new) quo two, new)
+      err0 := new*new - a
+      err0 > 0 => new-1
       new

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to