[net.math.symbolic] reduce ?s

leff@smu.UUCP (10/24/84)

Outstanding Reduce questions:
These issues concern REDUCE 3.1 running under 4.2BSD.
Emacs used (associated with one problem) is Unipress Emacs.
#264 of Monday May 16

1. Application of chain rule.

Let us assume we have a function f(y) which one wishes to differentiate
with respect to x.  However, y itself is a function of x.
How does one do this?

I tried the following (output of reduce copied here:)

depend f,y;


depend y,x;


df(f,x);


DF(F,X)

The last line is the output from Reduce. It is not what was was wanted.  What I wanted was df(f,y)*df(y,x).

2. Interface of Symbolic Math to algebraic mode question

How does one interface symbolic mode to the algebraic sub function?

Assume there are two lists and one wants to sub the car of one
list for the car of the other.  One could write

algebraic sub (symbolic (car list1 ) := symbolic (car list2));

but that doesn't work.  

One possibility would be to create a character string and pass it to the
reader as a REDUCE statement.  Is there another way to do this.

3. Interface of Reduce with Emacs

Symptoms: emacs hangs up (doesn't respond to keyboard and needs to be killed
          from other terminal)

Files in question:
rp13  (attach at end of this article)
.emacs_pro (attach at end of this article)

Reproduce by:

Emacs is invoked as normal (make sure appropriate .emacs_pro is used).
rp13 is loaded into one buffer.
An escape-3 is issued (which divides terminal into two windows, one being rp13 and the other being a shell).  Enter the command reduce \CR
A control y is issued which moves cursor back to window with rp13.
An escape-2 is issued (which will transmit the entire buffer containing rp13
to the REDUCE that was invoked by the shell).
Try and do something with the screen.  You will not be able to.  When you
do ps from other terminal, you will notice that the reduce process takes
12 seconds and then no more.  I. E. repetititive ps's show no change from
this amount of CPU time used.


Note:

I have used this technique dozes of times to send files to commands
running on another shell.  There are other a few other REDUCE programs
that create these conditions, equally long.
Also the specific reduce program will work under reduce
when invoked without using emacs.  I also tried transmitting a file
twice the size of rp13 to cat > /dev/null using this procedure and there were
no hang up conditions or other problems.  So the problem is not simply
the size of the file being transmitted.

Sorry about the length of the files but it is impossible to reporduce
with shorter ones.


4. SQRT and SOLVE facility

Even if SOLVEINTERVAL is on, the machine does not handle the request
solve(sqrt(x)-4,x).  The answer is left in terms of sqrt, rather in terms
of sqr(4) or 16.
It does handle the analagous request solve(sin(x)-1), however.

5. NUMVAL mode

The Numval mode of REDUCE, documented in section 6-2 is not listed in
appendix D, Mode Switches in Reduce.

6. RESUBS difficulty

Let us say one wants to apply some rule like replacing all occurrences
of f(i) with some function of f(i-1).  However, one wishes to do it once.
It would appear the resubs flag would be the thing to use.  However, REDUCE
appears to be making a substitution inside the resubstitution command
creating problems.  The following program illustrates the problem:

off resubs;
operator f;
for all i let f(i)=begin scalar temp1;
write "in procedure ",i;
temp1:=f(i-1);
return temp1;
end;

f(5);

It produces the following output (terminated manually for obvious reasons).

% reduce
REDUCE 3.0, 15-Apr-83 ...

1: 
2: 
3: 3: 3: 3: 3: 
4: 4: 
in procedure 5

in procedure 4

in procedure 3

in procedure 2

in procedure 1

in procedure 0

in procedure (-1)

in procedure (-2)

in procedure (-3)

in procedure (-4)

in procedure (-5)

in procedure (-6)

Note: the problem also occurs with a simple let rule without the begin end
pair, but I would not have been able to insert a print statement to show
what was happening.


BTW, I could not figure out a way to do this using MACSYMA either.
None of the APPLY functions can be told to replace all occurrences of
a function once.  


----------------------- cut here   rp 13 -----------------------------------

off nat;
procedure cubic(la,lb,lc,ld);
sub(a=la,b=lb,c=lc,d=ld,y-(a+b*x+c*x**2+d*x**3));

PROCEDURE LINE(LX1,LY1,LX2,LY2);  
SUB(Y2=LY2,Y1=LY1,X1=LX1,X2=LX2,(Y-Y1)-(Y2-Y1)/(X2-X1)*(X-X1));

PROCEDURE SQR(X); X**2;

PROCEDURE DISTANCE(LX1,LY1,LX2,LY2);
SQRT(SQR(LX2-LX1)+SQR(LY2-LY1));

procedure pointslope(lx1,lx2,lm);
line(lx1,lx2,lx1+1,lx2+lm);

% for all v let tan(2*atan(v)) = 2*v/(1-v**2);

area:=0;

AB:=line(0,x9,x1,y1);
solve(AB,y);
exprfory:=soln(1,1);
ABfy:=exprfory;
m1:=df(exprfory,x);
BC:=line(x2,y2,x3,y3);
solve(BC,y);
exprfory:=soln(1,1);
m2:=df(exprfory,x);

cubic1:=cubic(a1,b1,c1,d1);
temp1:=sub(x=x1,y=y1,cubic1);
temp2:=sub(x=x2,y=y2,cubic1);
solve(cubic1,y);
exprfory:=soln(1,1);
dcubic1:=df(exprfory,x);
temp3:=sub(x=x1,m1-dcubic1);
temp4:=sub(x=x2,m2-dcubic1);

solve(lst(temp1,temp2,temp3,temp4),a1,b1,c1,d1);
out po3;
write "a = ",soln(1,1)$
write "b = ",soln(1,2)$
write "c = ",soln(1,3)$
write "d = ",soln(1,4)$
out t$
newcubic1:=sub(a1=soln(1,1),b1=soln(1,2),c1=soln(1,3),d1=soln(1,4),cubic1);

%check that solution gave desired results
sub(y=y1,x=x1,newcubic1); %should give 0
sub(y=y2,x=x2,newcubic1); %should give 0
solve(newcubic1,y);
exprfory:=soln(1,1); 
dnewcubic1:=df(exprfory,x); 
sub(x=x1,dnewcubic1); %should give m1
sub(x=x2,dnewcubic1); % should give m2
dnewcubic1:=0;
HI:=line(x5,y5,x6,y6);
xvalue:=(x2-x1)*i/(n1);
solve(HI,y);
HIfunction:=soln(1,1); % y=f(x) when on line GH
% something about the line containg temp1:=int below causes a segmentation violation
write "exprfory = ",exprfory;
write "HIfunction = ",HIfunction;
% temp1:=int(exprfory-HIfunction,x);
area:=area+sub(x=x2,temp1)-sub(x=x1,temp1);
yonline:=sub(x=xvalue,HIfunction);
yoncubic:=sub(x=xvalue,newcubic1);
yvalue:=yonline+(yoncubic-yonline)*j/m;
out po3;
write "value of yj = ",yvalue$
write " ";
out t$
shut po3;
yoncubic:=0;
yvalue:=0;
newcubic1:=0;

xvalue:=(x3-x2)*i/(n2);
line23:=line(x2,y2,x3,y3);
solve(line23,y);
exprfory:=soln(1,1);
yontopline:=sub(x=xvalue,exprfory);
yonbottomline:=sub(x=xvalue,HIfunction);
% temp1:=int(exprfory-HIfunction,x);
%area:=area+sub(x=x3,temp1)-sub(x=x2,temp1);
yvalue:=yonbottomline+(yontopline-yonbottomline)*j/m;
out po4;
write "value of yj = ",yvalue$
write " ";
out t$
shut po4;

CE:=line(x4,y4,x10,y10);
solve (AB,y);
exprfory:=soln(1,1);
m3:=df(exprfory,x);
cubic2:=cubic(a2,b2,c2,d2);
temp1:=sub(x=x3,y=y3,cubic2);
temp2:=sub(x=x4,y=y4,cubic2);
solve(cubic2,y);
exprfory:=soln(1,1);
dcubic2:=df(exprfory,x);
temp3:=sub(x=x3,m2-dcubic2);
temp4:=sub(x=x4,m3-dcubic2);

solve(lst(temp1,temp2,temp3,temp4),a2,b2,c2,d2);
temp1:=0;
temp2:=0;
temp3:=0;
temp4:=0;
out po5;
write "a = ",soln(1,1)$
write "b = ",soln(1,2)$
write "c = ",soln(1,3)$
write "d = ",soln(1,4)$
out t$
on output;
%check results
newcubic2:=sub(a2=soln(1,1),b2=soln(1,2),c2=soln(1,3),d2=soln(1,4),cubic2);
sub(y=y3,x=x3,newcubic2); %should give 0
sub(y=y4,x=x4,newcubic2); % "
solve(newcubic2,y);
exprfory:=soln(1,1);
temp1:=int(exprfory-HIfunction,x);
area:=area+sub(x=x4,temp1)-sub(x=x1,temp1);
dnewcubic2:=df(exprfory,x);
sub(x=x3,dnewcubic2)-m2 ; % should give 0
sub(x=x4,dnewcubic2)-m3 ; % should give 0
dnewcubic2:=0;
xvalue:=(x4-x3)*i/n3;
yonline:=sub(x=xvalue,HIfunction);
yoncubic:=sub(x=xvalue,newcubic2);
yvalue:=yonline+(yoncubic-yonline)*j/m;
out po5;
write "value of yj = ",yvalue$
write " ";
out t$
shut po5;
yonline:=0;
yoncubic:=0;

% region 6

fx:=x5/2;
fy:=sub(x=fx,ABfy);
FJ:=line(fx,fy,x5,0);
solve(FJ,y);
FJfy:=soln(1,1);
mFJ:=df(FJfy,x);
finaltheta:=atan(mFJ);
starttheta:=pi/2;
thetavalue:=starttheta+(finaltheta-starttheta)*i/(n4);
linevalue:=pointslope(x5,0,tan(thetavalue)); % line from J out containing nodes
solve(lst(linevalue,AB),x,y);
lineendx:=soln(1,1); %x and y coordinates for intersection of radial line
lineendy:=soln(1,2); %with AB
temp1:=distance(0,x5,lineendx,lineendy); % distance from J to that intersection
distancevalue:=r1+j*(temp1-r1)/m; % radial distance for point ij from J
xvalue:=cos(thetavalue)*distancevalue+x5;
yvalue:=sin(thetavalue)*distancevalue;
out po6;
write "x ij is at ",xvalue$
write "y ij is at ",yvalue$
write " ";
out t$
shut po6;

%do region 5
starttheta:=finaltheta;
finaltheta:=0;
thetavalue:=starttheta+(finaltheta-starttheta)*i/n5;
linevalue:=pointslope(x5,0,tan(thetavalue)); % ray from J out containing nodes
solve(linevalue,y);
exprfory:=soln(1,1);
lineendx:=x5/2;
lineendy:=sub(x=lineendx,exprfory);
temp1:=distance(0,x5,lineendx,lineendy);
distancevalue:=r1+j*(temp1-r1)/m; 
xvalue:=cos(theta)*distancevalue+x5;
yvalue:=sin(theta)*distancevalue;
out po7;
write "x ij is at ",xvalue$
write "y ij is at ",yvalue$
write " ";
out t$
shut po7;



%do region 4
GF:=line(0,0,fx,fy);
starttheta:=atan(fy/fx);
finaltheta:=0;
thetavalue:=starttheta+(finaltheta-starttheta)*i/n5;
linevalue:=pointslope(0,0,tan(thetavalue)); % ray from J out containing nodes
solve(linevalue,y);
exprfory:=soln(1,1);
lineendx:=x5/2;
lineendy:=sub(x=lineendx,exprfory);
temp1:=distance(0,0,lineendx,lineendy);
distancevalue:=r3+j*(temp1-r3)/m2; 
xvalue:=cos(theta)*distancevalue+x5;
yvalue:=sin(theta)*distancevalue;
out po8;
write "x ij is at ",xvalue$
write "y ij is at ",yvalue$
write " ";
out t$
shut po8;

% region 3

FG:=line(fx,fy,0,0);
solve(FG,y);
FGfy:=soln(1,1);
mFJ:=df(FGfy,x);
starttheta:=atan(mFG);
finaltheta:=pi/2;
thetavalue:=starttheta+(finaltheta-starttheta)*i/(n6);
linevalue:=pointslope(0,0,tan(thetavalue)); % line from G out containing nodes
solve(lst(linevalue,AB),x,y);
lineendx:=soln(1,1); %x and y coordinates for intersection of radial line
lineendy:=soln(1,2); %with AB
temp1:=distance(0,0,lineendx,lineendy); % distance from J to that intersection
distancevalue:=r3+j*(temp1-r1)/m2; % radial distance for point ij from J
xvalue:=cos(theta)*distancevalue;
yvalue:=sin(theta)*distancevalue;
out po9;
write "x ij is at ",xvalue$
write "y ij is at ",yvalue$
write " ";
out t$
shut po9;

% finish computing area of region

area:=area+x1*y9+(y1-y9)/2;
area:=area-pi*r1**2/4;
area:=area+pi*y9**2/4;
area:=area-pi*r3**2/2;
area:=area+y4*(x10-x4);
area:=area+(x10-x4)*(y10-y4)/2;
area:=area+pi*y10**2/4;
area:=area+pi*r4**2/2;
area:=2*area;
out po12;
write "area of torque bar = ",area$
write " ";
out t$
shut po12;


% metallurgical simulation
% region ABC

finaltheta:=pi/4;
starttheta:=pi/2;
linevalue:=line(0,0,a*i/n,a); % line out from B containing node
solve(lst(linevalue,y-a),x,y);
lineendx:=soln(1,1);
lineendy:=soln(1,2);
solve(linevalue,y);
thetavalue:=atan(df(soln(1,1),x)); % theta = arctan(slope);
% handle points from 1 to m1 (before circle)
distancevalue:=r/m1;
xvalue:=cos(thetavalue)*distancevalue;
yvalue:=sin(thetavalue)*distancevalue;
out po10;
write "for j <=m1"$
write "x ij is at ",xvalue$
write "y ij is at ",yvalue$
write " ";
out t$
% handle points after circle from m1+1 to m1+m2 
distancevalue:=r+(distance(0,0,lineendx,lineendy)-r1)*(i-m1)/m2;
xvalue:=cos(thetavalue)*distancevalue;
yvalue:=sin(thetavalue)*distancevalue;
out po10;
write "for j >=m1 and < m2";
write "x ij is at",xvalue$
write "y ij is at",yvalue$
write " ";
out t$
shut po10;

%region CBD
linevalue:=line(0,0,a,a*i/n); % line out from B containing node
solve(lst(linevalue,x-a),x,y);
lineendx:=soln(1,1);
lineendy:=soln(1,2);
solve(linevalue,y);
thetavalue:=atan(df(soln(1,1),x));
% handle points from 1 to m1 (before circle);
distancevalue:=r/m1;
xvalue:=cos(thetavalue)*distancevalue;
yvalue:=sin(thetavalue)*distancevalue;
out po11;
write "for j <= m1"$
write "x ij is at ", xvalue$
write "y ij is at ", yavalue$
write " ";
out t;
% handle points after circle from  m1+1 to m2
distancevalue:=r+(distance(0,0,lineendx,lineendy)-r1)*(i-m1)/m2;
xvalue:=cos(thetavalue)*distancevalue;
yvalue:=sin(thetavalue)*distancevalue;
out po11;
write "for j >=m1 and < m2"$
write "x ij is at",xvalue$
write "y ij is at",yvalue$
write " ";
out t$
shut po11;

---------------------------------- end of rp13 -------------------------------

---------------------------------- start of .emacs_pro -----------------------

(defun (help (info)))
(autoload "new-undo" "undo.ml")
(autoload "time" "time.ml")
(autoload "spell" "spell.ml")
(autoload "incremental-search" "incr-search.ml")
(autoload "reverse-incremental-search" "incr-search.ml")
(autoload "electric-c-mode" "electric-c.ml")
(autoload "electric-lisp-mode" "electric-lisp.ml")
(autoload "electric-mlisp-mode" "electric-lisp.ml")
(autoload "scribe-mode" "scribe.ml")
(autoload "lisp" "process.ml")
(autoload "post" "post.ml")
(autoload "checkbboards" "bboard.ml")
(setq quick-redisplay 1)
(setq default-mode-line-format " %[Buffer: %b%*  File: %f  %M (%m)  %p%]")
(setq backup-before-writing 1)
(setq backup-by-copying-when-linked 1)
(bind-to-key "new-undo" "\^X\^U")
(if (= (getenv "TERM") "perq")
    (load "mouse"))
(auto-execute "electric-c-mode" "*.c")
(auto-execute "electric-c-mode" "*.h")
(auto-execute "text-mode" "/tmp/*")
(auto-execute "scribe-mode" "*.mss")
(auto-execute "electric-mlisp-mode" "*.ml")
(auto-execute "electric-lisp-mode" "*.l")
(auto-execute "electric-mlisp-mode" "*.emacs_pro")
(defun (lm1 (save-excursion (beginning-of-file) (set-mark)
           (end-of-file) (region-to-process "shell"))))
(bind-to-key "lm2" "\^o")
(load "man")
(load "mark-ring")
(load "paragraphs")
(load "readonly")
(defun (lm2 (end-of-line) (newline)))
(defun (lm18 (previous-line) (end-of-line) (newline)))
(bind-to-key "lm18" "\e1")
(bind-to-key "lm1" "\e2")
(load "goto")
(defun (lm3 (setq wrap-long-lines 1) (shell) (string-to-process "shell" "stty nl\^m")))

(bind-to-key "lm3" "\e3")
(defun (lm4 (delete-buffer (current-buffer-name))))
(bind-to-key "lm4" "\e4")
(bind-to-key "next-window" "\^Y")
(bind-to-key "next-line" "\^J")
(bind-to-key "previous-line" "\^K")
(bind-to-key "search-reverse" "\^X\^A")
(bind-to-key "forward-character" "\^L")
(bind-to-key "redraw-display" "\^X\^L")
(bind-to-key "next-page" "\^N")
(bind-to-key "previous-page" "\^R")
(bind-to-key "transpose-characters" "\^X\^T")
(bind-to-key "forward-word" "\^P")
(bind-to-key "backward-word" "\^T")
(bind-to-key "forward-sentence" "\^I")
(bind-to-key "backward-sentence" "\^F")

(defun (lm5 (beginning-of-line) (set-mark) (end-of-line ) (delete-to-killbuffer) (delete-next-character)))

(bind-to-key "lm5" "\^V")
(defun (lm6 (save-window-excursion (next-window) (previous-page))))
(bind-to-key "lm6" "\^_")
(bind-to-key "goto-line" "\^X\^J")
(bind-to-key "goto-percent" "\^X\^P")
(load "writeregion")
(bind-to-key "write-region-to-file" "\^Xa")
(defun (lm7 temp1 (setq temp1 (dot)) (error-occurred (search-forward (arg 1 "String to search for?"))) (if (= temp1 (dot))( progn (beginning-of-file) (error-occurred (search-forward "" ))
(if (= (dot) 1) (goto-character temp1))))))
(bind-to-key "lm7" "\^S")

(bind-to-key "search-forward" "\^X\^K")
(defun (lm8 (set-mark) (forward-sentence)  (delete-to-killbuffer)))
(defun (lm9 (set-mark) (backward-sentence)  (delete-to-killbuffer)))
(defun (lm10 (backward-sentence) (set-mark) (forward-sentence) (delete-to-killbuffer)))
(defun (lm11 (local-bind-to-key "next-line" "\^J")))
(bind-to-key "lm8" "\eg")
(bind-to-key "lm9" "\ei")
(bind-to-key "lm10" "\ek")
(bind-to-key "lm11" "\em")
(defun (lm12 (set-mark) (beginning-of-line) (delete-to-killbuffer)))
(defun (lm13 (set-mark) (end-of-line) (delete-to-killbuffer)))
(defun (lm14 (set-mark) (backward-paragraph) (delete-to-killbuffer)))
(defun (lm16 (set-mark) (forward-paragraph) (delete-to-killbuffer)))
(defun (lm15 (backward-paragraph ) (set-mark) (forward-paragraph) (delete-to-killbuffer)))
(bind-to-key "lm12" "\en")
(bind-to-key "lm13" "\eo")
(bind-to-key "lm14" "\ep")
(bind-to-key "lm15" "\es")
(bind-to-key "lm16" "\et")
(bind-to-key "yank-from-killbuffer" "\ew")
(bind-to-key "append-region-to-buffer" "\ey")
(bind-to-key "next-line" "\eB")
(bind-to-key "previous-line" "\eA")
(bind-to-key "backward-character" "\eD")
(bind-to-key "forward-character" "\eC")
(bind-to-key "yank-from-killbuffer" "\e0")
(defun (lm17 temp1 
   (setq temp1 pop-up-windows)
   (setq pop-up-windows 0)
   (visit-file (arg 1 "File to Visit:"))
   (setq pop-up-windows temp1)
       ))
(bind-to-key "lm17" "\e5")

--------------------------------- end of .emacs_pro -------------------------