🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.mail-lists.reduce
Article #41

separating positive and negative terms

#41
From: Stanley L. Kameny
Date: Mon, 03 Feb 1992 18:18
85 lines
3172 bytes
This is the reply which I sent to Quentin Vaughan on this subject.  I
did not try to do it in algebraic mode, since it seemed to be easier to
do it in symbolic mode.  It will handle not only  a-b-c+d but also
such expressions as   2a-3b/5-c+5d/2.  I also checked it out in rounded
mode, and it worked fine.


From stan  Sat Feb  1 21:50 PST 1992
Date: Sat, 1-Feb-92 21:50:10 PST
From: stan (Stanley L. Kameny)
Subject: In Reduce: separating sum into positives and negatives formally.
To: vaughan@src.bae.co.uk
CC: stan
In-Reply-To: Your message of Sat, 01 Feb 92 09:34:43 -0800

Hi Quentin,

I am assuming from your message that you would like in general to
separate a sum of terms into those with positive and negative
coefficients on the top level.  Whether the terms themselves are
^^^^^^^^^^^^
positive or negative is not determined.

There might be some simple way for doing this, but I doubt it;  however,
it can be done quite readily by defining a few functions, which are
based upon the logic in which expressions are returned by prepsq (the
lisp format which is processed into the algebraic format returned by
Reduce.)

% if you try

share xx;

xx := a - b - c + d;

%then

lisp(prepsq simp!* xx);

% yields:  (PLUS A (MINUS B) (MINUS C) D)

% In addition to this, if there are fractional coefficients, the format
% is wrapped into a list which starts with QUOTIENT and ends with the
% value of the denominator.

% therefore

share plusses,minusses;

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: plusses := mkplus(p,q); minusses := 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 q>>;

symbolic operator seps;

x := a-b-c+d;

seps x;

plusses;

minusses;

plusses - minusses;

% will yield the desired results, if I understood your question. If not,
% write me.

Stan Kameny    stan%valley.uucp@rand.org     stan_kameny@rand.org
Technical Details
Message-ID: <9202031818.AA12072@hilbert.rand.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ccut!hearn@rand.org

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 12b417,ecae09f716779355,start
X-Google-Attributes: gid12b417,public
X-Google-ArrivalTime: 1992-02-03 10:18:19 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 positive and negative terms
Message-ID: <9202031818.AA12072@hilbert.rand.org>
Date: 3 Feb 92 18:18:19 GMT
Sender: hearn@rand.org
Distribution: fj
Lines: 85
Approved: fj.mail-lists.reduce@ccut.cc.u-tokyo.ac.jp
Return-Path: <hearn@rand.org>
Original-To: melenk@sc.zib-berlin.de, reduce-forum@rand.org
Original-Cc: valley!stan@rand.org