Sindbad~EG File Manager
/* Operators for related rates problems in MathXpert */
/* M. Beeson
Original date not recorded, probably 1990.
6.14.98 last modified
*/
#include <string.h>
#include <assert.h>
#define TRIGCALC_DLL
#include "globals.h"
#include "graphstr.h"
#include "document.h"
#include "ops.h"
#include "calc.h"
#include "checkarg.h"
#include "operator.h"
#include "prover.h"
#include "getprob.h"
#include "relrates.h"
#include "probtype.h"
#include "nextstep.h" /* opseq */
#include "trig.h" /* ssolveop */
#include "symbols.h"
#include "cflags.h"
#include "errbuf.h"
#include "autosimp.h" /* SetShowStepOperation */
#include "fsubst.h" /* free_subst */
/* Related Rates problems.
1. The independent variable is always 't' (for time),
whether or not it is mentioned in the problem.
2. The statement of the problem involves an equation between
several variables (at least two), and possibly more equations
involving the derivatives of those variables which are valid for
all times (or all times in the relevant interval of t values).
In textbook problems there is just one additional equation and it
is already solved for a derivative.
3. In addition there will be zero or one (or more) equations that are
not valid for all times but only for one specific time. These
equations are entered separately in the GetProblem dialog.
In a problem file, they are separated from the equations valid for
all times by a vertical bar.
4. The solution method is as follows:
(a) differentiate the main equation.
(b) Use each of the other equations valid for all t to
eliminate one derivative term or one variable.
(c) Substitute the values from 3.
(d) That should leave just one derivative term. Solve for it.
If it leaves more than one, pick one and solve for it.
If it leaves none, you're done.
5. The lines of the solution will be of the form (or(A,B))
at first, where A is the generally valid equation(s) and B is the
specific-instant equation(s). As soon as difeqn is used, the
form shifts to an AND.
*/
/*___________________________________________________________*/
MEXPORT_TRIGCALC int used(int k)
/* return the line at which choice k on the related_rates menus has
already been used, 0 if not */
{ int i;
int currentline = get_currentline();
operation *opseq;
controldata cd;
get_controldata(&cd);
opseq = cd.opseq;
for(i=1;i<=currentline; i++)
{ if ( opseq[i].men == related_rates &&
(int) opseq[i].choice == k
)
return i;
}
return 0;
}
/*_____________________________________________________________*/
MEXPORT_TRIGCALC int eliminatederivative(term t, term arg, term *next, char *reason)
/* t is an AND of equations. One of them must have the form dx/dt = ...
Substitute the right side of that equation for the left in the
other equation(s). Doesn't work unless difeqn has been used already.
Doesn't work if the other equations don't actually contain that
derivative.
Can be called as a 'dowith' operation from the Term Selection Menu,
in which case arg is the derivative term to be eliminated; so if arg is
not ILLEGAL, this operation only works if one of the left-hand-sides of
the args of t is equal to arg and has the form dx/dt.
*/
{ unsigned short n;
int i,j,err;
term lhs, rhs,temp,u;
unsigned short path[7];
if(FUNCTOR(t) != AND)
return 1;
if(!used(DIFEQN))
{ errbuf(0, english(805));
/* You should first differentiate the equation. */
return 1;
}
n = ARITY(t);
for(i=0;i<n;i++)
{ if(FUNCTOR(ARG(i,t)) != '=')
return 1;
}
for(i=0;i<n;i++)
{ lhs = ARG(0,ARG(i,t));
rhs = ARG(1,ARG(i,t));
if(FUNCTOR(lhs) == DIFF && ISATOM(ARG(0,lhs)))
{ if(FUNCTOR(arg) == ILLEGAL)
break;
if(equals(arg,lhs))
break;
}
}
if(i==n)
{ errbuf(0,english(1920));
/* No equation is solved for a derivative of a variable. */
return 1 ;
}
HIGHLIGHT(rhs);
if(n == 2)
{ u = ARG(i ? 0 : 1, t);
subst(rhs,lhs,u,next);
if(equals(*next,u))
return 1;
}
else
{ *next = make_term(AND,(unsigned short)(n-1));
err = 1;
for(j=0;j<n-1;j++)
{ copy(rhs,&temp);
{ u = ARG(j<i? j : j+1,t);
subst(temp,lhs,u,ARGPTR(*next)+j);
if(!equals(u,ARG(j,*next)))
err = 0;
}
}
if(err == 1)
{ destroy_term(temp);
RELEASE(*next);
return 1;
}
}
strcpy(reason, english(1921));
/* eliminate derivative */
path[0] = AND;
path[1] = i+1;
path[2] = '=';
path[3] = 1;
path[4] = 0;
set_pathtail(path);
return 0;
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists