Jeroen Demeyer on Mon, 11 May 2009 10:22:15 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: PATCH: gequal1 and gequal_1 for t_SERs


Bill Allombert wrote:
On Tue, Feb 10, 2009 at 12:09:22PM +0100, Jeroen Demeyer wrote:
Hello pari-dev,

It seems that gcmp1() and gcmp_1() were not implemented for t_SER (they always returned 0). This patch should fix that.

CHANGES:
- Implemented gcmp1() and gcmp_1() for t_SERs.

Well, this change the semantic of gcmp1() and gcmp_1(), but I think
it is in an expected way, the current behaviour being rather
unexpecected.

However I am not entirely sure the implementation is correct:
We should have the equivalence gcmp1(x) == gequal(x,gen_1) and this is far from obvious from the code, though that might be
an issue with gequal rather than with your code.

I am opening this thread again since there haven't been any replies...

Do you think there are any problems with this patch? If there aren't, then you should commit it to SVN. Maybe there are some (unrelated) problems with gequal(), but at least I think that this patch is an improvement over the current situation where gequal(1+O(t^10), 1) returns 1 but gequal1(1+O(t^10)) returns 0.

Cheers,
Jeroen.
Index: src/basemath/gen2.c
===================================================================
--- src/basemath/gen2.c	(revision 11705)
+++ src/basemath/gen2.c	(working copy)
@@ -406,6 +406,8 @@
 int
 gequal1(GEN x)
 {
+  long i;
+
   switch(typ(x))
   {
     case t_INT:
@@ -434,6 +436,12 @@
 
     case t_POL:
       return lg(x)==3 && gequal1(gel(x,2));
+
+    case t_SER:
+      if (signe(x) == 0 || valp(x) != 0 || !gequal1(gel(x,2))) return 0;
+      for (i = 3; i < lg(x); i++) if (!gequal0(gel(x,i))) return 0;
+      return 1;
+
   }
   return 0;
 }
@@ -443,7 +451,7 @@
 gequalm1(GEN x)
 {
   pari_sp av;
-  long y;
+  long i, y;
   GEN p1;
 
   switch(typ(x))
@@ -478,6 +486,11 @@
 
     case t_POL:
       return lg(x)==3 && gequalm1(gel(x,2));
+
+    case t_SER:
+      if (signe(x) == 0 || valp(x) != 0 || !gequalm1(gel(x,2))) return 0;
+      for (i = 3; i < lg(x); i++) if (!gequal0(gel(x,i))) return 0;
+      return 1;
   }
   return 0;
 }