Article View: fj.mail-lists.reduce
Article #44separating expression into positive and negative terms.
From: Stanley L. Kameny
Date: Mon, 03 Feb 1992 22:07
Date: Mon, 03 Feb 1992 22:07
46 lines
2058 bytes
2058 bytes
Kako and Melenk gave solutions which (though they wouldn't handle
fractional coefficients) produced a list of the positive terms and
negative terms. This seems nice, though having an easy way of getting
at the two subexpressions (other that by using the operators first and
second on the list) seemed nice also.
So here is an updated version of my solution (without the typo) that
seems to do it all. (Possibly plus_minus would be a better name for it
than seps?)
share pterms,mterms;
symbolic procedure seps x;
if atom x or not eqcar(x,'quotient) then seps1(x,nil)
else seps1(cadr x,caddr x);
symbolic procedure seps1(x,q);
begin scalar p,m,c;
if atom (x := prepsq simp!* x) then <<p := x; goto ret>>;
if eqcar(x,'minus) then <<m := cadr x; goto ret>>;
if not eqcar(x,'plus) then <<p := x; goto ret>>;
x := cdr x;
lp: c := car x; x := cdr x;
if eqcar(c,'minus) then m := (cadr c) . m
else p := c . p;
if not atom x then go to lp;
ret: return list('list,pterms := mkplus(p,q),mterms := mkplus(m,q))
end;
symbolic procedure mkplus(p,q);
<<p := if atom p then p else if cdr p then 'plus . p else car p;
mk!*sq simp!* if q then list('quotient,p,q) else p>>;
symbolic operator seps;
% Example
x := 3a-2b/5-c+5d/2;
seps x;
pterms;
mterms;
pterms - mterms -x; % should always be 0.
Technical Details
Message-ID:
<9202032208.AA12762@hilbert.rand.org>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ccut!hearn@rand.orgShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 12b417,24a2f3901c88dd43,start X-Google-Attributes: gid12b417,public X-Google-ArrivalTime: 1992-02-03 14:07:59 PST Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ccut!hearn@rand.org From: valley!stan@rand.org (Stanley L. Kameny) Newsgroups: fj.mail-lists.reduce Subject: separating expression into positive and negative terms. Message-ID: <9202032208.AA12762@hilbert.rand.org> Date: 3 Feb 92 22:07:59 GMT Sender: hearn@rand.org Distribution: fj Lines: 46 Approved: fj.mail-lists.reduce@ccut.cc.u-tokyo.ac.jp Return-Path: <hearn@rand.org> Original-To: reduce-forum@rand.org Original-Cc: valley!stan@rand.org