Maxima generally assumes there is someone at the console to answer questions. The functions asksign and askinteger attempt to answer a question about their arguments by first consulting the assume database, and if that fails, then ask the user interactively. It is not possible to completely disable this interactive behavior.

This page is a sketch of a replacement for MEVAL which captures asksign and askinteger queries and constructs a conditional if ... then ... else from the possible alternatives. Here are some example calculations.

(%i20) MEVAL ('integrate (exp(a*x), x, 0, inf));
Principal Value
                       1
(%o20) if a < 0 then - - elseif equal(a, 0) then 0
                       a
                               else merror(Integral is divergent)
(%i21) MEVAL ('integrate (x^k, x));

                                                k + 1
                                               x
(%o21)     if equal(k + 1, 0) then log(x) else ------
                                               k + 1
(%i22) MEVAL ('integrate (x^k, x, 1, b));

(%o22) if k < 0 then (if equal(k + 1, 0)
 then (if b - 1 < 0 then (if b < 0 then log(- b) else log(b))
                    k + 1                k + 1
                   b          1         b          1
 else log(b)) else ------ - -----) else ------ - -----
                   k + 1    k + 1       k + 1    k + 1
(%i23) MEVAL ('integrate (x**a/(x+1), x, 0, inf));

                                             inf
                                            /      a
                                            [     x
(%o23) if a + 1 < 0 or equal(a + 1, 0) then I    ----- dx
                                            ]    x + 1
                                            /
                                             0
                                                    inf
                                                   /      a
                                                   [     x
         else (if a < 0 then beta(a + 1, - a) else I    ----- dx)
                                                   ]    x + 1
                                                   /
                                                    0
(%i24) MEVAL ('limit (x^a, x, inf));

(%o24) if a < 0 then 0 elseif equal(a, 0) then 1 else inf
(%i25) MEVAL ('limit (x^a, x, minf));

(%o25)                         und
(%i26) declare (a, integer);

(%o26)                        done
(%i27) MEVAL ('limit (x^a, x, minf));

                                                    a
(%o27) if a < 0 then 0 elseif equal(a, 0) then (- 1)  else minf
(%i28) MEVAL ('integrate (x**a/(x+1)**(5/2), x, 0, inf));

                                                      2 a + 2
(%o28) merror(Improper argument to ~:M:~%~M, declare, -------)
                                                         5

Here is the script "catch_ask.mac". This script assumes that code for unevaluated conditionals ("mand.lisp") and a modified asksign which throws something instead of asking the user ("tmp-asksign1.lisp") have been loaded. The script includes simplification rules for if -- it is often the case that the result is the same for different alternatives, so (for example) if A then B else B can be simplified to just B.

/* load ("mand.lisp");
 * load ("tmp-asksign1.lisp");
 * batch ("catch_ask.mac");
 * prederror: false;
 */

/* examples:
 * MEVAL ('integrate (exp(a*x), x, 0, inf));
 * MEVAL ('integrate (x^k, x));
 * MEVAL ('integrate (x^k, x, 1, b));
 * MEVAL ('integrate (x**a/(x+1), x, 0, inf));
 * MEVAL ('integrate (x**a/(x+1)**(5/2), x, 0, inf));         <-- FAILS -- attempt to declare nonatomic expr
 * MEVAL ('limit (x^a, x, inf));
 * MEVAL ('limit (x^a, x, minf));
 * declare (a, integer);
 * MEVAL ('limit (x^a, x, minf));
 */
MEVAL (e%) := catch (MEVAL1 ());    /* bind e% for the benefit of MEVAL1 */

MEVAL1 () := block ([r%: catch (ev (e%, nouns))],   /* by the time we get here, e% is bound by MEVAL */
  if not atom(r%) and op(r%) = 'asksign
    then block ([a%, s%, c%, L%],
      a%: args(r%)[1],
      s%: args(r%)[2],
      c%:
        if s% = 'pnz then [a% < 0, equal (a%, 0), a% > 0]
        elseif s% = 'nz then [a% < 0, equal (a%, 0)]
        elseif s% = 'pz then [equal (a%, 0), a% > 0]
        elseif s% = 'pn then [a% < 0, a% > 0]
        elseif s% = 'znz then [equal (a%, 0), not equal (a%, 0)]
        else throw (oops_unknown (s%)),

      L%: apply (enumerate_cases, [c%]),

      if s% = 'pnz or s% = 'znz then c% [length(c%)]: true, /* to make final "else" */

      funmake ("if", interleave (c%, L%)))

  else if not atom(r%) and op(r%) = 'askprop
    /* FOLLOWING ASKPROP STUFF NEEDS WORK */
    then block ([a%, s%, c%, L%],
      a%: args(r%)[1],
      s%: args(r%)[2],
      c%: ['kind (a%, 'integer), true],
      L%:
       [block ([w%, z%: gensym()],
          newcontext (z%),
          apply (declare, [a%, 'integer]),
          w%: MEVAL1(),
          killcontext (z%),
          w%),
       block ([w%, z%: gensym()],
          newcontext (z%),
          apply (declare, [a%, 'noninteger]),
          w%: MEVAL1(),
          killcontext (z%),
          w%)],

      funmake ("if", interleave (c%, L%)))

  else r%);

enumerate_cases (L%) :=
  map (lambda ([p%], block ([r%], assume (p%), r%: MEVAL1(), forget (p%), r%)), L%);

interleave (L1, L2) := flatten (map (lambda ([e1, e2], [e1, e2]), L1, L2));

:lisp (defun merror (s &rest l) (meval `(($throw) '((merror) ,s ,@l))))

:lisp (defun $gensym () (cadr (dollarify `(,(gensym)))))

matchdeclare ([aa, bb, cc, dd], true);

simp: false;

tellsimpafter (if aa then bb else bb, bb);

tellsimpafter (if aa then bb elseif cc then bb else bb, bb);

tellsimpafter (if aa then bb elseif cc then dd else dd, if aa then bb else dd);

tellsimpafter (if aa then bb elseif cc then bb else dd, if aa or cc then bb else dd);

tellsimpafter ('if aa then bb else bb, bb);

tellsimpafter ('if aa then bb elseif cc then bb else bb, bb);

tellsimpafter ('if aa then bb elseif cc then dd else dd, 'if aa then bb else dd);

tellsimpafter ('if aa then bb elseif cc then bb else dd, 'if aa or cc then bb else dd);

simp: true;