From: SourceForge.net <no...@so...> - 2007-04-05 21:36:03
|
Bugs item #1692651, was opened at 2007-04-01 23:03 Message generated for change (Comment added) made by willisbl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=104933&aid=1692651&group_id=4933 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Lisp Core Group: None Status: Open Resolution: None Priority: 7 Private: No Submitted By: Robert Dodier (robert_dodier) Assigned to: Nobody/Anonymous (nobody) Summary: MGRP gets sense of comparison backwards Initial Comment: The function MGRP (greater-than comparison) can get the sense of the comparison backwards. MGRP is called indirectly from MEVALP and maybe other places as well. e.g. ?mgrp (x, 1); => x - 1 > 0 (OK) ?mgrp (1, x); => x - 1 > 0 (OOPS) I'm pretty sure the cause of this is the use of special variables in src/compar.lisp. I think what's happening is that SIGN1 calls itself, clobbering some of the specials. I believe the right way to fix this is to rework the comparison code to use only lexical variables instead of specials. For the record: (%i1) :lisp (trace sign1) (SIGN1) (%i1) ?mgrp (x, 1); 1> (SIGN1 ((MPLUS SIMP) -1 $X)) <1 (SIGN1 $PNZ) (%o1) x - 1 > 0 (%i2) ?mgrp (1, x); 1> (SIGN1 ((MPLUS SIMP) 1 ((MTIMES SIMP) -1 $X))) 2> (SIGN1 -1) <2 (SIGN1 $NEG) 2> (SIGN1 $X) <2 (SIGN1 $PNZ) 2> (SIGN1 -1) <2 (SIGN1 $NEG) 2> (SIGN1 ((MPLUS SIMP IRREDUCIBLE) -1 $X)) <2 (SIGN1 $PNZ) <1 (SIGN1 $PNZ) (%o2) x - 1 > 0 ---------------------------------------------------------------------- >Comment By: Barton Willis (willisbl) Date: 2007-04-05 16:35 Message: Logged In: YES user_id=895922 Originator: NO I see that memq is no longer in Maxima. Replacing memq with a call to member, and appending an infsimp (may or may not be a good idea, I don't know), I built Maxima CVS using XP and sbcl 1.02. I passes the test suite. The code: (defun mgrp (a b) (setq a (infsimp (sub a b))) (let ((sgn (csign a))) (cond ((eq sgn '$pos) t) ((eq sgn t) nil) ;; csign thinks a - b isn't real ((member sgn '($neg $zero $nz) :test #'eq) nil) (t `((mgreaterp) ,a 0))))) (defun mgqp (a b) (setq a (infsimp (sub a b))) (let ((sgn (csign a))) (cond ((member sgn '($pos $zero $pz) :test #'eq) t) ((eq sgn t) nil) ;; csign thinks a - b isn't real ((eq sgn '$neg) nil) (t `((mgeqp) ,a 0))))) ---------------------------------------------------------------------- Comment By: Barton Willis (willisbl) Date: 2007-04-05 06:16 Message: Logged In: YES user_id=895922 Originator: NO An attempt at a fix: (defun mgrp (a b) (setq a (sub a b)) (let ((sgn (csign a))) (cond ((eq sgn '$pos) t) ((eq sgn t) nil) ;; csign thinks a - b isn't real ((memq sgn '($neg $zero $nz)) nil) (t `((mgreaterp) ,a 0))))) (defun mgqp (a b) (setq a (sub a b)) (let ((sgn (csign a))) (cond ((memq sgn '($pos $zero $pz)) t) ((eq sgn t) nil) ;; csign thinks a - b isn't real ((eq sgn '$neg) nil) (t `((mgeqp) ,a 0))))) Notes: (1) With these functions, the test suite gives an error break on rtest15; rtest16 #39 reports a problem about the sign of infinity; and rtestsum #5 reports that the result is correct, but that Maxima expected the result to be wrong. (2) The functions c-$pos and friends may have some logic in them that I've overlooked. (3) The subtraction in my functions can be a problem for inf, minf, und, and ... (4) It's possible that my functions don't properly set the values of the 'evens', 'odds', and 'sign'. This scheme confuses me. I would like to expunge the functions c-$pos and friends along with 'evens', 'odds', and 'sign'. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=104933&aid=1692651&group_id=4933 |