Sindbad~EG File Manager

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

/* inverse trig function differentiation operators */
/*
2.22.92 Original date
2.27.98 last modified
*/
#include <string.h>
#include <assert.h>
#define TRIGCALC_DLL
#include "globals.h"
#include "ops.h"
#include "trig.h"
#include "calc.h"
#include "checkarg.h"
#include "polynoms.h"
#include "diff.h"   /* set_chainrule_errmsg */
#include "symbols.h"
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difatan(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ATAN)
    return 1;
  p = ARG(0,u);
  if(!equals(p,x))
     { set_chainrule_errmsg();
       return 1;
     }
  return difatan2(t,arg,next,reason);
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difatan2(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ATAN)
     return 1;
  p = ARG(0,u);
  if(equals(p,x))
     { if(get_orderflag() == ASCENDING)
          { strcpy(reason,"d/dx arctan x =      1/(1+x^2)");
            *next = make_fraction(one,sum(one,make_power(x,two)));
          }
       else
          { strcpy(reason,"d/dx arctan x =      1/(x^2+1)");
            *next = make_fraction(one,sum(make_power(x,two),one));
          }
     }
  else
     { if(get_orderflag() == ASCENDING)
          { strcpy(reason,"d/dx arctan u =      (du/dx)/(1+u^2)");
            *next = make_fraction(diff(p,x),sum(one,make_power(p,two)));
          }
      else
          { strcpy(reason,"d/dx arctan x =      (du/dx)/(u^2+1)");
            *next = make_fraction(diff(p,x),sum(make_power(p,two),one));
          }
     }
  HIGHLIGHT(*next);
  return 0;
}

/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difacot(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ACOT)
     return 1;
  p = ARG(0,u);
  if(!equals(p,x))
     { set_chainrule_errmsg();
       return 1;
     }
  return difacot2(t,arg,next,reason);
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difacot2(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ATAN)
     return 1;
  p = ARG(0,u);
  if(equals(p,x))
     { if(get_orderflag() == ASCENDING)
          { strcpy(reason,"d/dx arctan x =      -1/(1+x^2)");
            *next = tnegate(make_fraction(one,sum(one,make_power(x,two))));
          }
       else
          { strcpy(reason,"d/dx arccot x =      -1/(x^2+1)");
            *next = tnegate(make_fraction(one,sum(make_power(x,two),one)));
          }
     }
  else
     { if(get_orderflag() == ASCENDING)
          { strcpy(reason,"d/dx arccot u =      -(du/dx)/(1+u^2)");
            *next = tnegate(make_fraction(diff(p,x),sum(one,make_power(p,two))));
          }
       else
          { strcpy(reason,"d/dx arccot x =      -(du/dx)/(u^2+1)");
            *next = tnegate(make_fraction(diff(p,x),sum(make_power(p,two),one)));
          }
     }
  HIGHLIGHT(*next);
  return 0;
}

/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difasin(term t, term arg, term *next, char *reason)
{ term x,u;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ASIN)
     return 1;
  if(!equals(ARG(0,u),x))
      { set_chainrule_errmsg();
        return 1;
      }
  return difasin2(t,arg,next,reason);
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difasin2(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ASIN)
     return 1;
  p = ARG(0,u);
  if(equals(p,x))
     { *next = make_fraction(one,sqrt1(sum(one,tnegate(make_power(x,two)))));
       strcpy(reason,"d/dx arcsin x =      $1/�(1-x^2)$");
     }
  else
     { *next = make_fraction(diff(p,x),sqrt1(sum(one,tnegate(make_power(p,two)))));
       strcpy(reason,"d/dx arcsin u =      $(du/dx)/�(1-u^2)$");
     }
  HIGHLIGHT(*next);
  return 0;
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difacos(term t, term arg, term *next, char *reason)
{ term x,u;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ACOS)
     return 1;
  if(!equals(ARG(0,u),x))
      { set_chainrule_errmsg();
        return 1;
      }
  return difacos2(t,arg,next,reason);
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difacos2(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ACOS)
     return 1;
  p = ARG(0,u);
  if(equals(p,x))
     { *next = tnegate(make_fraction(one,sqrt1(sum(one,tnegate(make_power(x,two))))));
       strcpy(reason,"d/dx arccos x =      $-1/�(1-x^2)$");
     }
  else
     { *next = tnegate(make_fraction(diff(p,x),sqrt1(sum(one,tnegate(make_power(p,two))))));
       strcpy(reason,"d/dx arccos u =      $-(du/dx)/�(1-u^2)$");
     }
  HIGHLIGHT(*next);
  return 0;
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difasec(term t, term arg, term *next, char *reason)
{ term x,u;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ASEC)
     return 1;
  if(!equals(ARG(0,u),x))
      { set_chainrule_errmsg();
        return 1;
      }
  return difasec2(t,arg,next,reason);
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difasec2(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ASEC)
     return 1;
  p = ARG(0,u);
  if(equals(p,x))
     { *next = make_fraction(one,product(abs1(x),sqrt1(sum(one,tnegate(make_power(x,two))))));
       strcpy(reason,"d/dx arcsec x =      $1/(|x|�(1-x^2))$");
     }
  else
     { *next = make_fraction(diff(p,x),product(abs1(u),sqrt1(sum(one,tnegate(make_power(p,two))))));
       strcpy(reason,"d/dx arccos u =      $(du/dx)/(|u|�(1-u^2)$");
     }
  HIGHLIGHT(*next);
  return 0;
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difacsc(term t, term arg, term *next, char *reason)
{ term x,u;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ACSC)
    return 1;
  if(!equals(ARG(0,u),x))
      { set_chainrule_errmsg();
        return 1;
      }
  return difasec2(t,arg,next,reason);
}
/*_______________________________________________________________________*/
MEXPORT_TRIGCALC int difacsc2(term t, term arg, term *next, char *reason)
{ term x,u,p;
  if(FUNCTOR(t) != DIFF)
     return 1;
  x = ARG(1,t);
  u = ARG(0,t);
  if(FUNCTOR(u) != ACSC)
     return 1;
  p = ARG(0,u);
  if(equals(p,x))
     { *next = tnegate(make_fraction(one,product(abs1(x),sqrt1(sum(one,tnegate(make_power(x,two)))))));
       strcpy(reason,"d/dx arcsec x =        $-1/(|x|�(1-x^2))$");
     }
  else
     { *next = tnegate(make_fraction(diff(p,x),product(abs1(u),sqrt1(sum(one,tnegate(make_power(p,two)))))));
       strcpy(reason,"d/dx arccos u =        $-(du/dx)/(|u|�(1-u^2)$");
     }
  HIGHLIGHT(*next);
  return 0;
}

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