[Maxima] Improvement to nonintegerp (was: Improvement to askinteger for review/comment)

Billinghurst, David (RTATECH) David.Billinghurst at riotinto.com
Wed Oct 14 22:26:24 CDT 2009

> From: dr dieter kaiser
> Am Sonntag, den 11.10.2009, 15:00 +1100 schrieb Billinghurst, David
> > 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?      
> I do not like the functions $askinteger and $asksign. Very 
> often these functions ask questions which are nonsense.

Agree, but I don't want to change the behaviour of the existing 
ODE code 

> It is a bit strange that a user has to call the function 
> $featurep to get the functionality of maxima-integerp, e.g. 
> featurep(sqrt(3),integer)
> -> false (Should we extend integerp, oddp and evenp to use
> maxima-integerp, mevenp and moddp?).
> When we extend the functionality of askinteger, we double 
> functionality we already have in maxima-integerp.

maxima-integerp and nonintegerp both return false for "don't know".
  featurep(sqrt(3),integer) -> false
  featurep(sqrt(3),noninteger) -> false

I now believe the correct solution is to extend nonintegerp, which 
is called by askinteger.  With this change
  featurep(sqrt(3),integer) -> false
  featurep(sqrt(3),noninteger) -> true

I was unsure if this would work for sqrt(N^2) when N is a large
integer, after inspecting the code and some testing I now think it 
is OK. I tested several cases near N^2 where N is a large Mersenne 

OK to commit this?

Index: compar.lisp
RCS file: /cvsroot/maxima/maxima/src/compar.lisp,v
retrieving revision 1.58
diff -u -1 -1 -r1.58 compar.lisp
--- compar.lisp	8 Oct 2009 19:45:54 -0000	1.58
+++ compar.lisp	15 Oct 2009 02:43:35 -0000
@@ -1690,24 +1690,26 @@
 (defmfun nonintegerp (e)
   (let (num)
     (cond ((integerp e) nil)
 	  ((mnump e) t)
 	  ((atom e) (kindp e '$noninteger))
 	  ((specrepp e) (nonintegerp (specdisrep e)))
 	  ((and (eq (caar e) 'mplus) (ratnump (cadr e)) (intp (cdr e)))
 	  ((and (integerp (setq num ($num e)))
 		    (setq e ($denom e))
 		    (or (eq (csign (sub e num)) '$pos)
-			(eq (csign (add2 e num)) '$neg))))
-	   t))))
+			(eq (csign (add2 e num)) '$neg)))) t)
+          ;; Assumes a simplified sqrt of a number is not an integer.
+          ((and (mexptp e) (mnump (second e)) (alike1 (third e) 1//2))
+	  (t nil))))

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.

More information about the Maxima mailing list