Bug report ID:710307 "orderlessp of bfloat, %e, and inf"



We have the open bug report ID:710307 "orderlessp of bfloat, %e, and
inf".

I think the behavior of $orderlessp should not be changed. The function
$orderlessp is used abut 30 times in Maxima core code. Several algorithm
might depend on the order given by orderlessp (That is the order of
great).

Other predicate functions like "<" do not work completely, because they
are not a total order on the elements.

If it is desired to have an order by magnitude we can support an
additional predicate function like the following:

;; Test function to order a and b by magnitude. If it is not possible to
;; order a and b by magnitude they are ordered by great. This function
;; can be used by sort, e.g. sort([3,1,7,x,sin(1),minf],ordermagnitudep)
(defun $ordermagnitudep (a b)
  (let (sgn)
    (setq a (specrepcheck a)
          b (specrepcheck b))
    (cond ((and (or (constp a) (member a '($inf $minf)))
                (or (constp b) (member b '($inf $minf)))
                (member (setq sgn ($csign (sub b a))) '($pos $neg
$zero)))
           (cond ((eq sgn '$pos) t)
                 ((eq sgn '$zero) (and (not (alike1 a b)) (great b a)))
                 (t nil)))
          ((or (constp a) (member a '($inf $minf))) t)
          ((or (constp b) (member b '($inf $minf))) nil)
          (t (and (not (alike1 a b)) (great b a))))))


With this function we get the desired order by magnitude:

(%i10) sort([1,2,3,1.0,2.0,3.0,1.0b0,2.0b0,3.0b0,3/2,5/2],
       ordermagnitudep);
(%o10) [1,1.0,1.0b0,3/2,2,2.0,2.0b0,5/2,3,3.0,3.0b0]

(%i12) sort([1,5,%e,%pi,%phi,%gamma,inf,minf],
       ordermagnitudep);
(%o12) [minf,%gamma,1,%phi,%e,%pi,5,inf]

Constant expressions are ordered by magnitude too:

(%i14) sort([0,1,2,3,10,sin(1),%e^2],ordermagnitudep);
(%o14) [0,sin(1),1,2,3,%e^2,10]


The function sort does not sort by default in the order of magnitude,
but the user can supply the new predicate function (This can be changed
too).

We might have two options:

1. Implement a new predicate function ordermagnitudep and close 
   the bug report as fixed.
2. Close the bug report as won't fix.

Dieter Kaiser