# [Maxima] askinteger: Look in the database for facts

Dieter Kaiser drdieterkaiser at web.de
Sun Nov 15 14:39:13 CST 2009

```I have worked on the bug report ID: 1038624 - "askinteger ignores

askinteger calls the functions maxima-integerp and nonintegerp to
determine, if the argument is definitely an integer or a noninteger.
Therefore, is not a weakness of askinteger to ignore facts like
assume(equal(x,0)) but of the called functions.

Both functions do not look completely for facts in the database. This
can be improved. Here are two small routines which do a bit more of the
needed work:

;; Look into the database for symbols which are declared to be equal
;; to an integer or an expression which is an integer.
(defun check-integer-facts (x)
(do ((factsl (cdr (facts1 x)) (cdr factsl)))
((null factsl) nil)
(cond ((eq (caar (car factsl)) '\$equal)
(cond ((and (symbolp (cadr (car factsl)))
;; Case equal(x,expr): Test expr to be an integer.
;; Case equal(expr,x): Test expr to be integer.

;; Look into the database for symbols which are declared to be equal
;; to a noninteger or an expression which is a noninteger.
(defun check-noninteger-facts (x)
(do ((factsl (cdr (facts1 x)) (cdr factsl)))
((null factsl) nil)
(cond ((eq (caar (car factsl)) '\$equal)
(cond ((and (symbolp (cadr (car factsl)))
;; Case equal(x,expr): Test expr to be an integer.
;; Case equal(expr,x): Test expr to be integer.

We can call these routines in maxima-integerp and nonintegerp, e.g.

(defun maxima-integerp (x &aux factsl)
(cond ((integerp x))
((mnump x) nil)
((and (symbolp x)
(or (kindp x '\$integer)
(kindp x '\$even)
(kindp x '\$odd)
--->              (check-integer-facts x))))
....

With these extensions, we get the following:

(%i1) assume(equal(a,0), equal(b,2), equal(c,1/3), equal(d,1.5),
equal(e,3.0b0))\$

(%o2) [yes, yes, no, no, no]

(%i3) assume(equal(x,2*b), equal(y,b/2), equal(z,e))\$
(%o4)                           [yes, yes, no]

It is only a small extension and it works not as general as is desired:

The following works as expected:

(%o12) yes
(%o13) yes
(%o14) yes
(%o15) yes

But not this expression:

Is (b+4)/2 an integer?

y;
(%o16) yes

The testsuite and share_testsuite have no problems.

Further work is possible.

Dieter Kaiser

```