proposal to extend rhs / lhs to all relational operators, maybe others
Subject: proposal to extend rhs / lhs to all relational operators, maybe others
From: Robert Dodier
Date: Sun, 8 Jan 2006 17:41:55 -0700
Hello,
At present rhs and lhs return the right-hand side and left-hand side,
respectively, of an expression of the form a = b.
For any operator other than "=", rhs returns 0 while lhs returns the
whole expression.
I would like to change that so that rhs and lhs return the
right- and left-hand sides for all relational operators
(namely < <= = equal # notequal >= and >).
We might also consider having rhs / lhs recognize := ::= : and ::
since those also have unambiguous right- and left-hand sides.
Maybe there are others.
It is true that the right- and left-hand sides can be obtained at present
via part. However, (1) the operands of all relational operators should
be accessible the same way -- either all via rhs / lhs or none of them.
(2) There is precedent for having general-purpose named part functions
(e.g. op, args) as well as part itself.
I ran into this when I was trying to work with some inequalities.
Not a big deal, but it seems obvious and the implementation is simple
(see patch below).
Comments?
All the best,
Robert Dodier
PS.
Index: src/csimp.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/csimp.lisp,v
retrieving revision 1.6
diff -u -r1.6 csimp.lisp
--- src/csimp.lisp 7 Nov 2005 17:37:11 -0000 1.6
+++ src/csimp.lisp 8 Jan 2006 19:26:30 -0000
@@ -173,11 +173,21 @@
(defun subin (y x) (cond ((not (among var x)) x) (t
(maxima-substitute y var x))))
-(defmfun $rhs (eq)
- (cond ((or (atom eq) (not (eq (caar eq) 'mequal))) 0) (t (caddr eq))))
-
-(defmfun $lhs (eq)
- (cond ((or (atom eq) (not (eq (caar eq) 'mequal))) eq) (t (cadr eq))))
+(let
+ ((relops '(mlessp mleqp mequal mnotequal $equal $notequal mgeqp mgreaterp
+ %mlessp %mleqp %mequal %mnotequal %equal
%notequal %mgeqp %mgreaterp)))
+ (defmfun $rhs (rel)
+ (if (atom rel)
+ 0
+ (if (memq (caar rel) relops)
+ (caddr rel)
+ 0)))
+ (defmfun $lhs (rel)
+ (if (atom rel)
+ rel
+ (if (memq (caar rel) relops)
+ (cadr rel)
+ rel))))
(defun ratgreaterp (x y)
(cond ((and (mnump x) (mnump y))