Skip to content

Commit

Permalink
Added derivative, printing.Also added the functions to mpc and mpfr
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMaxx committed Feb 6, 2016
1 parent cf0f856 commit 3868fad
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 0 deletions.
21 changes: 21 additions & 0 deletions symengine/complex_mpc.cpp
Expand Up @@ -664,12 +664,26 @@ class EvaluateMPC : public Evaluate {
mpc_sinh(t.get_mpc_t(), static_cast<const ComplexMPC &>(x).i.get_mpc_t(), MPFR_RNDN);
return complex_mpc(std::move(t));
}
virtual RCP<const Basic> csch(const Basic &x) const {
SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
mpc_class t(static_cast<const ComplexMPC &>(x).i.get_prec());
mpc_sinh(t.get_mpc_t(), static_cast<const ComplexMPC &>(x).i.get_mpc_t(), MPFR_RNDN);
mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
return complex_mpc(std::move(t));
}
virtual RCP<const Basic> cosh(const Basic &x) const {
SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
mpc_class t(static_cast<const ComplexMPC &>(x).i.get_prec());
mpc_cosh(t.get_mpc_t(), static_cast<const ComplexMPC &>(x).i.get_mpc_t(), MPFR_RNDN);
return complex_mpc(std::move(t));
}
virtual RCP<const Basic> sech(const Basic &x) const {
SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
mpc_class t(static_cast<const ComplexMPC &>(x).i.get_prec());
mpc_cosh(t.get_mpc_t(), static_cast<const ComplexMPC &>(x).i.get_mpc_t(), MPFR_RNDN);
mpc_ui_div(t.get_mpc_t(), 1, t.get_mpc_t(), MPFR_RNDN);
return complex_mpc(std::move(t));
}
virtual RCP<const Basic> tanh(const Basic &x) const {
SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
mpc_class t(static_cast<const ComplexMPC &>(x).i.get_prec());
Expand All @@ -689,6 +703,13 @@ class EvaluateMPC : public Evaluate {
mpc_asinh(t.get_mpc_t(), static_cast<const ComplexMPC &>(x).i.get_mpc_t(), MPFR_RNDN);
return complex_mpc(std::move(t));
}
virtual RCP<const Basic> acsch(const Basic &x) const {
SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
mpc_class t(static_cast<const ComplexMPC &>(x).i.get_prec());
mpc_ui_div(t.get_mpc_t(), 1, static_cast<const ComplexMPC &>(x).i.get_mpc_t(), MPFR_RNDN);
mpc_atanh(t.get_mpc_t(), t.get_mpc_t(), MPFR_RNDN);
return complex_mpc(std::move(t));
}
virtual RCP<const Basic> acosh(const Basic &x) const {
SYMENGINE_ASSERT(is_a<ComplexMPC>(x))
mpc_class t(static_cast<const ComplexMPC &>(x).i.get_prec());
Expand Down
16 changes: 16 additions & 0 deletions symengine/derivative.cpp
Expand Up @@ -115,6 +115,12 @@ static RCP<const Basic> diff(const CLASS &self, \
self.get_arg()->diff(x));
}

static RCP<const Basic> diff(const ACsch &self,
const RCP<const Symbol> &x) {
return mul(div(minus_one, mul(sqrt(add(one, pow(self.get_arg(), i2))),
abs(self.get_arg()))), self.get_arg()->diff(x));
}

static RCP<const Basic> diff(const ASinh &self,
const RCP<const Symbol> &x) {
return mul(div(one, sqrt(add(pow(self.get_arg(), i2), one))),
Expand All @@ -133,11 +139,21 @@ static RCP<const Basic> diff(const CLASS &self, \
self.get_arg()->diff(x));
}

static RCP<const Basic> diff(const Sech &self,
const RCP<const Symbol> &x) {
return mul(mul(mul(minus_one,sech(self.get_arg())),tanh(self.get_arg())), self.get_arg()->diff(x));
}

static RCP<const Basic> diff(const Cosh &self,
const RCP<const Symbol> &x) {
return mul(sinh(self.get_arg()), self.get_arg()->diff(x));
}

static RCP<const Basic> diff(const Csch &self,
const RCP<const Symbol> &x) {
return mul(mul(mul(minus_one,csch(self.get_arg())),coth(self.get_arg())), self.get_arg()->diff(x));
}

static RCP<const Basic> diff(const Sinh &self,
const RCP<const Symbol> &x) {
return mul(cosh(self.get_arg()), self.get_arg()->diff(x));
Expand Down
18 changes: 18 additions & 0 deletions symengine/eval_mpc.cpp
Expand Up @@ -179,11 +179,23 @@ class EvalMPCVisitor : public BaseVisitor<EvalMPCVisitor> {
mpc_sinh(result_, result_, rnd_);
}

void bvisit(const Csch &x) {
apply(result_, *(x.get_arg()));
mpc_sinh(result_, result_, rnd_);
mpc_ui_div(result_, 1, result_, rnd_);
}

void bvisit(const Cosh &x) {
apply(result_, *(x.get_arg()));
mpc_cosh(result_, result_, rnd_);
}

void bvisit(const Sech &x) {
apply(result_, *(x.get_arg()));
mpc_cosh(result_, result_, rnd_);
mpc_ui_div(result_, 1, result_, rnd_);
}

void bvisit(const Tanh &x) {
apply(result_, *(x.get_arg()));
mpc_tanh(result_, result_, rnd_);
Expand All @@ -200,6 +212,12 @@ class EvalMPCVisitor : public BaseVisitor<EvalMPCVisitor> {
mpc_asinh(result_, result_, rnd_);
}

void bvisit(const ACsch &x) {
apply(result_, *(x.get_arg()));
mpc_ui_div(result_, 1, result_, rnd_);
mpc_asinh(result_, result_, rnd_);
}

void bvisit(const ACosh &x) {
apply(result_, *(x.get_arg()));
mpc_acosh(result_, result_, rnd_);
Expand Down
16 changes: 16 additions & 0 deletions symengine/eval_mpfr.cpp
Expand Up @@ -161,11 +161,21 @@ class EvalMPFRVisitor : public BaseVisitor<EvalMPFRVisitor> {
mpfr_sinh(result_, result_, rnd_);
}

void bvisit(const Csch &x) {
apply(result_, *(x.get_arg()));
mpfr_csch(result_, result_, rnd_);
}

void bvisit(const Cosh &x) {
apply(result_, *(x.get_arg()));
mpfr_cosh(result_, result_, rnd_);
}

void bvisit(const Sech &x) {
apply(result_, *(x.get_arg()));
mpfr_sech(result_, result_, rnd_);
}

void bvisit(const Tanh &x) {
apply(result_, *(x.get_arg()));
mpfr_tanh(result_, result_, rnd_);
Expand All @@ -181,6 +191,12 @@ class EvalMPFRVisitor : public BaseVisitor<EvalMPFRVisitor> {
mpfr_asinh(result_, result_, rnd_);
}

void bvisit(const ACsch &x) {
apply(result_, *(x.get_arg()));
mpfr_ui_div(result_, 1, result_, rnd_);
mpfr_asinh(result_, result_, rnd_);
};

void bvisit(const ACosh &x) {
apply(result_, *(x.get_arg()));
mpfr_acosh(result_, result_, rnd_);
Expand Down
3 changes: 3 additions & 0 deletions symengine/number.h
Expand Up @@ -133,10 +133,13 @@ class Evaluate {
virtual RCP<const Basic> asec(const Basic &) const = 0;
virtual RCP<const Basic> acsc(const Basic &) const = 0;
virtual RCP<const Basic> sinh(const Basic &) const = 0;
virtual RCP<const Basic> csch(const Basic &) const = 0;
virtual RCP<const Basic> cosh(const Basic &) const = 0;
virtual RCP<const Basic> sech(const Basic &) const = 0;
virtual RCP<const Basic> tanh(const Basic &) const = 0;
virtual RCP<const Basic> coth(const Basic &) const = 0;
virtual RCP<const Basic> asinh(const Basic &) const = 0;
virtual RCP<const Basic> acsch(const Basic &) const = 0;
virtual RCP<const Basic> acosh(const Basic &) const = 0;
virtual RCP<const Basic> atanh(const Basic &) const = 0;
virtual RCP<const Basic> acoth(const Basic &) const = 0;
Expand Down
3 changes: 3 additions & 0 deletions symengine/printer.cpp
Expand Up @@ -438,10 +438,13 @@ std::vector<std::string> init_str_printer_names() {
names[ACOT] = "acot";
names[ATAN2] = "atan2";
names[SINH] = "sinh";
names[CSCH] = "csch";
names[COSH] = "cosh";
names[SECH] = "sech";
names[TANH] = "tanh";
names[COTH] = "coth";
names[ASINH] = "asinh";
names[ACSCH] = "acsch";
names[ACOSH] = "acosh";
names[ATANH] = "atanh";
names[ACOTH] = "acoth";
Expand Down
8 changes: 8 additions & 0 deletions symengine/real_double.cpp
Expand Up @@ -80,10 +80,18 @@ class EvaluateDouble : public Evaluate {
SYMENGINE_ASSERT(is_a<T>(x))
return number(std::sinh(static_cast<const T &>(x).i));
}
virtual RCP<const Basic> csch(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<T>(x))
return number(std::csch(static_cast<const T &>(x).i));
}
virtual RCP<const Basic> cosh(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<T>(x))
return number(std::cosh(static_cast<const T &>(x).i));
}
virtual RCP<const Basic> sech(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<T>(x))
return number(std::sech(static_cast<const T &>(x).i));
}
virtual RCP<const Basic> tanh(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<T>(x))
return number(std::tanh(static_cast<const T &>(x).i));
Expand Down
12 changes: 12 additions & 0 deletions symengine/real_mpfr.cpp
Expand Up @@ -737,12 +737,24 @@ class EvaluateMPFR : public Evaluate {
mpfr_sinh(t.get_mpfr_t(), static_cast<const RealMPFR &>(x).i.get_mpfr_t(), MPFR_RNDN);
return real_mpfr(std::move(t));
}
virtual RCP<const Basic> csch(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<RealMPFR>(x))
mpfr_class t(static_cast<const RealMPFR &>(x).i.get_prec());
mpfr_csch(t.get_mpfr_t(), static_cast<const RealMPFR &>(x).i.get_mpfr_t(), MPFR_RNDN);
return real_mpfr(std::move(t));
}
virtual RCP<const Basic> cosh(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<RealMPFR>(x))
mpfr_class t(static_cast<const RealMPFR &>(x).i.get_prec());
mpfr_cosh(t.get_mpfr_t(), static_cast<const RealMPFR &>(x).i.get_mpfr_t(), MPFR_RNDN);
return real_mpfr(std::move(t));
}
virtual RCP<const Basic> sech(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<RealMPFR>(x))
mpfr_class t(static_cast<const RealMPFR &>(x).i.get_prec());
mpfr_sech(t.get_mpfr_t(), static_cast<const RealMPFR &>(x).i.get_mpfr_t(), MPFR_RNDN);
return real_mpfr(std::move(t));
}
virtual RCP<const Basic> tanh(const Basic &x) const override {
SYMENGINE_ASSERT(is_a<RealMPFR>(x))
mpfr_class t(static_cast<const RealMPFR &>(x).i.get_prec());
Expand Down

0 comments on commit 3868fad

Please sign in to comment.