Sindbad~EG File Manager
/* unitelogs and unitelns, for MathXpert by M. Beeson */
/*
Original date 2.12.94
5.26.95 code last modified
2.27.98 TRIGCALC_DLL etc.
*/
#include <string.h>
#include <assert.h>
#define TRIGCALC_DLL
#include "globals.h"
#include "ops.h"
#include "order.h"
#include "operator.h"
#include "probtype.h"
#include "algaux.h"
#include "eqn.h"
#include "prover.h"
#include "autosub.h"
#include "symbols.h"
#include "psubst.h"
static int unitelogs_aux(unsigned f, int flag, term t, term *next, char *reason);
/*__________________________________________________________________*/
MEXPORT_TRIGCALC int unitelogs(term t, term arg, term *next, char *reason)
/* use logofpower in an equation if afterwards it makes all logs have
the same argument. */
{ return unitelogs_aux(LOG,1,t,next,reason);
}
/*__________________________________________________________________*/
MEXPORT_TRIGCALC int unitelns(term t, term arg, term *next, char *reason)
/* use lnofpower in an equation if afterwards it makes all lns have
the same argument. */
{ return unitelogs_aux(LN,1,t,next,reason);
}
/*__________________________________________________________________*/
MEXPORT_TRIGCALC int unitelogs2(term t, term arg, term *next, char *reason)
/* use logofproduct in an equation if afterwards it makes all logs have
the same argument. */
{ return unitelogs_aux(LOG,2,t,next,reason);
}
/*__________________________________________________________________*/
MEXPORT_TRIGCALC int unitelns2(term t, term arg, term *next, char *reason)
/* use lnofproduct in an equation if afterwards it makes all lns have
the same argument. */
{ return unitelogs_aux(LN,2,t,next,reason);
}
/*__________________________________________________________________*/
static log_power_subterm(term t, term *ans)
/* look for a subterm of t of the form ln u� or log u�, with u not constant;
return 0 for success, 1 for failure. Put the found term in *ans. */
{ int err;
unsigned short i,n;
if(ATOMIC(t))
return 1;
if(FUNCTOR(t) == LOG || FUNCTOR(t) == LN)
{ if(FUNCTOR(ARG(0,t)) != '^' || econstant(ARG(0,t)))
return 1;
*ans = t;
return 0;
}
n = ARITY(t);
for(i=0;i<n;i++)
{ err = log_power_subterm(ARG(i,t),ans);
if(!err)
return 0;
}
return 1;
}
/*__________________________________________________________________*/
static log_product_subterm(term t, term *ans)
/* look for a subterm of t of the form ln uv or log uv, with uv not constant;
return 0 for success, 1 for failure. Put the found term in *ans. */
{ int err;
unsigned short i,n;
if(ATOMIC(t))
return 1;
if(FUNCTOR(t) == LOG || FUNCTOR(t) == LN)
{ if(FUNCTOR(ARG(0,t)) != '*' || econstant(ARG(0,t)))
return 1;
*ans = t;
return 0;
}
n = ARITY(t);
for(i=0;i<n;i++)
{ err = log_product_subterm(ARG(i,t),ans);
if(!err)
return 0;
}
return 1;
}
/*__________________________________________________________________*/
static int unitelogs_aux(unsigned f, int flag, term t, term *next, char *reason)
/* do the work of unitelns or unitelogs; f will be LN or LOG */
{ term n,c,s,p,u,temp;
int err,rval;
if(FUNCTOR(t) != '=')
return 1;
switch(flag)
{ case 1:
err = log_power_subterm(t,&p);
break;
case 2:
err = log_product_subterm(t,&p);
break;
default: assert(0);
}
if(err)
return 1;
if(FUNCTOR(p) != f)
return 1;
u = ARG(0,p);
if(FUNCTOR(u) == '^' && econstant(ARG(1,u)))
p = f==LN ? ln1(ARG(0,u)) : log1(ARG(0,u));
/* Not ARGREP(p,0,ARG(0,u)) which trashes t, as the args of p
are still part of t; only the head of p is local. */
else if(FUNCTOR(u) == '*')
{ ncs(u,&n,&c,&s);
p = f==LN ? ln1(s) : log1(s);
}
/* In case p was ln x� or ln(ax�) it is now ln x */
SETCOLOR(p,YELLOW); /* this colors only the ln term itself, but
the only alternative would be to color the
entire answer. */
rval = psubst(var0,p,t,&temp);
if(rval != 3)
return 1;
if(!econstant(temp))
return 1; /* the eigenvariable was not eliminated */
subst(p,var0,temp,next);
if(FUNCTOR(p) == LN && flag==1)
strcpy(reason, english(1138));
/* ln a� = n ln a */
else if(FUNCTOR(p) == LOG && flag==1)
strcpy(reason, english(1140));
/* log a� = n log a */
else if(FUNCTOR(p) == LN)
strcpy(reason, "ln ab = ln a + ln b");
else
strcpy(reason, "log ab=log a + log b");
return 0;
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists