pow(y*b+pow(y,2)*x+a,-2)*pow(y,2))*
pow(1+pow(a*x+b+y*pow(x,2),2)*pow(y*b+pow(y,2)*x+a,-2),-1);
*/
+ /*
d = pow(1+pow(a*x+b+y*pow(x,2),2)*pow(y*b+pow(y,2)*x+a,-2),-1)
*pow(y*b+pow(y,2)*x+a,-1)*(a+2*y*x)
+pow(y,2)*(-a*x-b-y*pow(x,2))*
pow(pow(y*b+pow(y,2)*x+a,2)+pow(a*x+b+y*pow(x,2),2),-1);
+ */
+ d = pow(y,2)*pow(pow(b+y*pow(x,2)+x*a,2)+pow(y*b+pow(y,2)*x+a,2),-1)*
+ (-b-y*pow(x,2)-x*a)+
+ pow(pow(b+y*pow(x,2)+x*a,2)+pow(y*b+pow(y,2)*x+a,2),-1)*
+ (y*b+pow(y,2)*x+a)*(2*y*x+a);
result += check_diff(e, x, d);
return result;
ex function::diff(symbol const & s) const
{
exvector new_seq;
-
- if (serial == function_index_Order) {
-
+
+ if (serial==function_index_Order) {
// Order Term function only differentiates the argument
return Order(seq[0].diff(s));
-
} else {
-
// Chain rule
+ ex arg_diff;
for (unsigned i=0; i!=seq.size(); i++) {
- new_seq.push_back(mul(pdiff(i), seq[i].diff(s)));
+ arg_diff = seq[i].diff(s);
+ // We apply the chain rule only when it makes sense. This is not
+ // just for performance reasons but also to allow functions to
+ // throw when differentiated with respect to one of its arguments
+ // without running into trouble with our automatic full
+ // differentiation:
+ if (!arg_diff.is_zero())
+ new_seq.push_back(mul(pdiff(i), arg_diff));
}
}
return add(new_seq);
{
if (x.info(info_flags::numeric)) {
// trap integer arguments:
- if ( x.info(info_flags::integer) ) {
+ if (x.info(info_flags::integer)) {
// gamma(n+1) -> n! for postitive n
- if ( x.info(info_flags::posint) ) {
+ if (x.info(info_flags::posint)) {
return factorial(ex_to_numeric(x).sub(numONE()));
} else {
return numZERO(); // Infinity. Throw? What?
}
}
// trap half integer arguments:
- if ( (x*2).info(info_flags::integer) ) {
+ if ((x*2).info(info_flags::integer)) {
// trap positive x=(n+1/2)
// gamma(n+1/2) -> Pi^(1/2)*(1*3*..*(2*n-1))/(2^n)
- if ( (x*2).info(info_flags::posint) ) {
+ if ((x*2).info(info_flags::posint)) {
numeric n = ex_to_numeric(x).sub(numHALF());
numeric coefficient = doublefactorial(n.mul(numTWO()).sub(numONE()));
coefficient = coefficient.div(numTWO().power(n));
}
return gamma(x).hold();
}
-
+
static ex gamma_evalf(ex const & x)
{
BEGIN_TYPECHECK
{
GINAC_ASSERT(diff_param==0);
- return psi(exZERO(),x)*gamma(x); // diff(log(gamma(x)),x)==psi(0,x)
+ return psi(x)*gamma(x); // diff(log(gamma(x)),x)==psi(x)
}
static ex gamma_series(ex const & x, symbol const & s, ex const & point, int order)
// Psi-function (aka polygamma-function)
//////////
+/** Evaluation of polygamma-function psi(x).
+ * Somebody ought to provide some good numerical evaluation some day... */
+static ex psi1_eval(ex const & x)
+{
+ if (x.info(info_flags::numeric)) {
+ // do some stuff...
+ }
+ return psi(x).hold();
+}
+
+static ex psi1_evalf(ex const & x)
+{
+ BEGIN_TYPECHECK
+ TYPECHECK(x,numeric)
+ END_TYPECHECK(psi(x))
+
+ return psi(ex_to_numeric(x));
+}
+
+static ex psi1_diff(ex const & x, unsigned diff_param)
+{
+ GINAC_ASSERT(diff_param==0);
+
+ return psi(exONE(), x);
+}
+
+static ex psi1_series(ex const & x, symbol const & s, ex const & point, int order)
+{
+ throw(std::logic_error("Nobody told me how to series expand the psi function. :-("));
+}
+
+unsigned function_index_psi1 = function::register_new("psi", psi1_eval, psi1_evalf, psi1_diff, psi1_series);
+
+//////////
+// Psi-functions (aka polygamma-functions) psi(0,x)==psi(x)
+//////////
+
/** Evaluation of polygamma-function psi(n,x).
* Somebody ought to provide some good numerical evaluation some day... */
-static ex psi_eval(ex const & n, ex const & x)
+static ex psi2_eval(ex const & n, ex const & x)
{
+ // psi(0,x) -> psi(x)
+ if (n.is_zero())
+ return psi(x).hold();
if (n.info(info_flags::numeric) && x.info(info_flags::numeric)) {
// do some stuff...
}
return psi(n, x).hold();
}
-
-static ex psi_evalf(ex const & n, ex const & x)
+
+static ex psi2_evalf(ex const & n, ex const & x)
{
BEGIN_TYPECHECK
TYPECHECK(n,numeric)
return psi(ex_to_numeric(n), ex_to_numeric(x));
}
-static ex psi_diff(ex const & n, ex const & x, unsigned diff_param)
+static ex psi2_diff(ex const & n, ex const & x, unsigned diff_param)
{
- GINAC_ASSERT(diff_param==0);
+ GINAC_ASSERT(diff_param<2);
+ if (diff_param==0) {
+ // d/dn psi(n,x)
+ throw(std::logic_error("cannot diff psi(n,x) with respect to n"));
+ }
+ // d/dx psi(n,x)
return psi(n+1, x);
}
-static ex psi_series(ex const & n, ex const & x, symbol const & s, ex const & point, int order)
+static ex psi2_series(ex const & n, ex const & x, symbol const & s, ex const & point, int order)
{
- throw(std::logic_error("Nobody told me how to series expand the psi function. :-("));
+ throw(std::logic_error("Nobody told me how to series expand the psi functions. :-("));
}
-REGISTER_FUNCTION(psi, psi_eval, psi_evalf, psi_diff, psi_series);
+unsigned function_index_psi2 = function::register_new("psi", psi2_eval, psi2_evalf, psi2_diff, psi2_series);
} // namespace GiNaC