Sindbad~EG File Manager

Current Path : /usr/home/beeson/Otter-Lambda/yyy/trigcalc/
Upload File :
Current File : /usr/home/beeson/Otter-Lambda/yyy/trigcalc/moretrig.c

/* Some little-used operators for MathXpert, by M. Beeson.
1.10.94 original date
3.30.99 last modified
3.10.00 corrected strcat to strcpy in sumofarctan
*/

#include <string.h>
#include <math.h>
#define TRIGCALC_DLL
#include "globals.h"
#include "ops.h"
#include "trig.h"
#include "match.h"
#include "order.h"
#include "cancel.h"
#include "prover.h"
#include "symbols.h"

/*__________________________________________________________________*/
MEXPORT_TRIGCALC int sincossame(term t, term arg, term *next, char *reason)
/* cos x cos x = � sin 2x */
{ int err;
  term lhs,rhs,a,temp,u;
  lhs = product(sin1(var0),cos1(var0));
  rhs = sin1(product(two,var0));
  err = match(t,lhs,rhs,&a,&temp);   /* instantiate a and temp */
  if(err)
     { destroy_term(lhs);
       destroy_term(rhs);
       return 1;
     }
  SETCOLOR(temp,YELLOW);
  err = cancel(temp,two,&u,next);  /* make 2 sin x cos x = sin 2x */
  if(err)
     { u = make_fraction(one,two);
       SETCOLOR(u,YELLOW);
       *next = product(make_fraction(one,two),temp);
       strcpy(reason,"$sin � cos � = �sin 2�$");
       return 0;
     }
  strcpy(reason,"$2 sin � cos � = sin 2�$");
  return 0;
}
/*__________________________________________________________________*/
MEXPORT_TRIGCALC int sumofarcsin(term t, term arg, term *next, char *reason)
/* arcsin x + arccos x = �/2 */
{ term lhs,rhs,a;
  int err;
  if(FUNCTOR(t) != '+')
     return 1;
  lhs = sum(asin1(var0),acos1(var0));
  rhs = make_fraction(pi,two);
  err = match(t,lhs,rhs,&a,next);   /* instantiate a and *next */
  if(err)
     { destroy_term(lhs);
       destroy_term(rhs);
       return 1;
     }
  SETCOLOR(*next,YELLOW);
  strcpy(reason,"$arcsin x+arccos x=�/2$");
  return 0;
}
/*__________________________________________________________________*/
MEXPORT_TRIGCALC int sumofarctan(term t, term arg, term *next, char *reason)
/* arctan x + arctan 1/x = �x/2|x| */
{ term lhs,rhs,a,temp;
  int err,complex;
  if(FUNCTOR(t) != '+')
     return 1;
  lhs = sum(atan1(var0),atan1(reciprocal(var0)));
  rhs = make_fraction(pi,two);
  err = match(t,lhs,rhs,&a,next);   /* instantiate a and *next */
  if(err)
     { destroy_term(lhs);
       destroy_term(rhs);
       return 1;
     }
  strcpy(reason, "arctan x + arctan 1/x ");
  complex = get_complex();
  err = infer(lessthan(zero,complex ? re(a) : a));
  if(!err)
      { if(complex)
           strcat(reason,"$= �/2 (Re[x] > 0)$");
        else
           strcat(reason,"$= �/2 (x > 0)$");
        SETCOLOR(*next,YELLOW);
        return 0;
      }
  err = infer(lessthan(complex ? re(a) : a,zero));
  if(!err)
     { *next = tnegate(*next);
       if(complex)
          strcat(reason, "$= -�/2 (Re[x] < 0)$");
       else
          strcat(reason,"$= -�/2 (x < 0)$");
       SETCOLOR(*next,YELLOW);
       return 0;;
     }
  temp = product(make_fraction(pi,two),make_fraction(a,abs1(a)));
  polyval(temp,next);
  SETCOLOR(*next,YELLOW);
  return 0;
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists