rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

sort(rat(...)) internal error #2374

Closed rtoy closed 4 months ago

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:20 Created by macrakis on 2007-12-17 14:52:38 Original: https://sourceforge.net/p/maxima/bugs/1303


sort(rat([x=1,y=1])) => fatal error

Maxima 5.13.0 GCL 2.6.8 Windows XP

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:22 Created by macrakis on 2007-12-17 19:10:28 Original: https://sourceforge.net/p/maxima/bugs/1303/#a0cd


Logged In: YES user_id=588346 Originator: YES

This appears to come from orderlessp(rat(a=1),rat(b=1)) => fatal error

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:25 Created by willisbl on 2007-12-18 12:32:36 Original: https://sourceforge.net/p/maxima/bugs/1303/#fb91


Logged In: YES user_id=895922 Originator: NO

I think there is a bug / weirdness with the way rat interacts with = expressions.

(%i1) e : rat(x=1)$

We have ratp(e) --> false and ratp(first(e)) --> true.

(%i2) ratp(e); (%o2) false

(%i3) ratp(first(e)); (%o3) true

Also, ratdisrep doesn't convert the left and right sides of e to general form.

(%i4) e : ratdisrep(e)$ (%i5) ratp(first(e)); (%o5) true

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:29 Created by nobody on 2007-12-18 15:07:03 Original: https://sourceforge.net/p/maxima/bugs/1303/#f348


Logged In: NO

Re: e: rat(x=1)$ ratp(e) => false; ratp(lhs(e)) => true

This is as designed (though it may be surprising that ratp(rat(...)) isn't always true. After all, there is no way to represent relational operators in CRE form.

> ratdisrep doesn't convert the left and right sides of e to general form.

This is normal. ratdisrep only disreps the top level. You need totaldisrep to disrep all the way down.

You get the same thing with rat([x,y]). Which brings up another bug...:

rat([(x^2-1)/(x-1)]) => [x-1]

but

rat({(x^2-1)/(x-1)}) => {(x^2-1)/(x-1)}

This is precisely *because* ratp(rat({x})) = true!

(%i54) rat([(x^2-1)/(x-1)]); Evaluation took 0.00 seconds (0.00 elapsed) (%o54)/R/ [x + 1]

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:32 Created by willisbl on 2007-12-18 18:29:16 Original: https://sourceforge.net/p/maxima/bugs/1303/#c9cf


Logged In: YES user_id=895922 Originator: NO

Changing ratdisrep to $totaldisrep in $sort makes this bug go away. But I don't know if this is the right thing to do.

(defmfun $sort (l &optional (f 'lessthan)) (let ((llist l) comparfun bfun) (unless ($listp llist) (merror "The first argument to `sort' must be a list:~%~M" llist)) (setq llist (copy-list (cdr llist)) comparfun (mfunction1 (setq bfun (getopr f)))) (when (member bfun '(lessthan great) :test #'eq) (setq llist (mapcar #'$totaldisrep llist))) (cons '(mlist simp) (sort llist comparfun))))

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:36 Created by robert_dodier on 2008-06-15 01:26:48 Original: https://sourceforge.net/p/maxima/bugs/1303/#ecea


rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:39 Created by robert_dodier on 2008-06-15 01:26:48 Original: https://sourceforge.net/p/maxima/bugs/1303/#5e40


Logged In: YES user_id=501686 Originator: NO

Maxima 5.14.99rc1:

sort(rat([x=1, y=1])) => error

orderlessp(rat(a=1),rat(b=1)) => true (not an error as observed before)

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:43 Created by robert_dodier on 2008-06-15 01:34:37 Original: https://sourceforge.net/p/maxima/bugs/1303/#82a8


Logged In: YES user_id=501686 Originator: NO

I take it back.

orderlessp(rat(a=1),rat(b=1)) => error

after all.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:46 Created by crategus on 2010-06-04 18:46:42 Original: https://sourceforge.net/p/maxima/bugs/1303/#b072


rtoy commented 4 months ago

Imported from SourceForge on 2024-07-06 07:10:50 Created by crategus on 2010-06-04 18:46:42 Original: https://sourceforge.net/p/maxima/bugs/1303/#633f


This bug has been fixed some times ago in simp.lisp revision 1.106. We get the results: (%i1) sort(rat([x=1,y=1])); (%o1) [x = 1,y = 1] (%i2) orderlessp(rat(a=1),rat(b=1)); (%o2) true

Closing this bug report as fixed. Dieter Kaiser