#789 bad language design with ?floor

closed
nobody
Lisp Core (471)
5
2005-09-28
2005-09-26
No

Hello,
Maxima uses some Lisp functions like ?floor, ?ceiling,
etc..

In Lisp we have

(%i1) :lisp(floor (sqrt 2))
1
0.41421356237309515

but in Maxima we have

(%i1) ?floor(sqrt(2));
Maxima encountered a Lisp error:

Error in MACSYMA-TOP-LEVEL [or a callee]:
((MEXPT SIMP) 2 ((RAT SIMP) 1 2))
is not of type (OR RATIONAL LISP:FLOAT).

This is bad designed.

I would suggest the following definition.

(defun $floor (x &optional (d 1))
(let ((f (simplify ($float x))))
(and (numberp f) (floor f d))))

The result is

(%i3) floor(sqrt(2));
(%o3) 1
(%i4) floor(8,3);
(%o4) 2
(%i5) floor(8/3);
(%o5) 2
(%i6) floor(8.3);
(%o6) 8
(%i7) floor(x);
(%o7) FALSE

ffloor, ceiling, fceiling, truncate and ftruncate could
be defined
in the same way.

Volker van Nek

Discussion

  • Stavros Macrakis

    • status: open --> closed
    • milestone: 482214 -->
     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346

    It is not a bug that Lisp functions do not operate correctly
    on all Maxima forms. When you use Lisp functions like
    ?floor within Maxima, you are working with Maxima internals.

    Why are you using the Lisp function ?floor rather than the
    existing Maxima function Entier?

    By the way, your proposed definition for $floor violates
    Maxima conventions in several ways:

    1) it is using approximate operations (floating-point
    evaluation) to evaluate exact expressions;

    2) it doesn't handle bfloats correctly;

    3) it does not return a symbolic expression when it cannot
    evaluate;

    4) it does not take advantage of symbolic properties, e.g.
    declare(m,integer)$ floor(m) should give m;

    By the way, the "simplify" around $float is not necessary.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks