Improvement to askinteger for review/comment



The askinteger function does not know that sqrt(3) is not an integer.

For a rational numbers N, Maxima simplifies (most?) expressions of form 
sqrt(N^2) to abs(N).  The patch below assumes that this simplification
has occured
and an expression of the form sqrt(x) is not an integer if
numberp(x)=true.  
Are there cases when this is unsafe?  One possibility I considered is
for (very) large x.

So some questions:
 - is this patch correct?
 - if not, what additional tests/constrains are needed?
 - are there any simple generalizations?      

	David

Index: askp.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/askp.lisp,v
retrieving revision 1.13
diff -u -6 -r1.13 askp.lisp
--- askp.lisp 10 Feb 2009 05:42:06 -0000 1.13
+++ askp.lisp 11 Oct 2009 03:32:00 -0000
@@ -65,12 +65,17 @@
 (defun ask-integerp (x)
   (let (integer-ans)
     (if (and (mplusp x) (integerp (cadr x))) (setq x (addn (cddr x)
t)))
     (if (and (mtimesp x) (equal (cadr x) -1)) (setq x (muln (cddr x)
t)))
     (cond ((or (maxima-integerp x) (memalike x integerl)) '$yes)
    ((or ($numberp x) (nonintegerp x) (memalike x nonintegerl)) '$no)
+          ;; Assumes a simplified sqrt of a number is never an integer.
+          ((and (mexptp x) 
+  ($numberp (second x)) 
+  (alike1 (third x) '((rat) 1 2))) 
+    '$no)
    ((eq (setq integer-ans (ask-prop x 'integer nil)) '$yes)
     (ask-declare x '$integer) '$yes)
    ((eq integer-ans '$no)
     (ask-declare x '$noninteger) '$no)
    (t '$unknown))))

This email is confidential and may also be privileged.  If you are not the intended recipient, please notify us immediately and delete this message from your system without first printing or copying it. Any personal data in this email (including any attachments) must be handled in accordance with the Rio Tinto Group Data Protection Policy and all applicable data protection laws.