A special function is a function that typically cannot be computed using a finite number of elementary functions such as sum, product, composition of finitely many polynomials, rational functions, trigonometric and exponential functions, and their inverse functions. The derivatives of such functions are similar. Because of their importance in many applications like the Gaussian function in statistics, hence we must have a very accurate computation of such functions. We cannot use finite difference here, as we simply cannot afford the inaccuracy. There are special techniques to compute the special functions, such as continued fraction. The special functions and their first order functions are discussed below.

Gaussian Derivative Function

The Gaussian Derivative Function is defined as 
\( \displaystyle f(x)=a\,exp\Big(-\frac{(x-b)^2}{2c^2}\Big) \)

				
					val G: Gaussian G = new Gaussian(1, 0, 1); // standard Gaussian
val dG: DGaussian dG = new DGaussian(G);
double x=-0.5;
System.out.println(String.format(dG/dx(%f) = %f", x' dG.evaluate(x)));
x = 0;
System.out.println(String.format(dG/dx(%f) = %f", x' dG.evaluate(x)));
x = 0.5;
System.out.println(String.format(dG/dx(%f) = %f", x' dG.evaluate(x)));

				
			

The output is:

				
					dG/dx(-0.500000) = 0.176033
dG/dx(0.000000) = -0.000000 
dG/dx(0.500000) = -0.176033
				
			

Error Derivative Function

The Error Derivative Function is defined as

\( \displaystyle erz\,z=\frac{2}{\pi}\int^{z}_{0}e^{-t^2}dt \)

 

				
					val E: Erf E = new Erf();
val dE: DErf dE = new DErf();
double z = 0.5;
System.out.println(String.format("erf(%f) = %f", z, E.evaluate(z)));
System.out.println(String.format("dErf/dz(%f) = %f", z, dE.evaluate(z)));
				
			

The output is:

				
					erf(0.500000) = 0.520500
dErf/dz(0.500000) = 0.878783
				
			

Beta Derivative Function

The Beta Derivative Function is also called as the Euler integral of the first kind. It is defined for any real number: \( x,y>0 \).

\( \displaystyle B(x,y)=\int^{1}_{0}t^{x-1}(1-t)^{y-1}dt \)

				
					val B: Beta B = new Beta();
val dB: DBeta dB = new DBeta();
double x = 1.5;
double y = 2.5;
System.out.println(String.format("Beta(%f) = %f", x, B.evaluate(x, y)));
System.out.println(String.format("dBeta/dz(%f) = %f", x, dB.evaluate(x, y)));
				
			

The output is:

				
					Beta(1.500000) = 0.196350
dBeta/dz(1.500000) = -0.239473
				
			

Regularized Incomplete Beta derivative Function

The Incomplete Beta Function is a generalization of the Beta Function and is defined as

\( \displaystyle B(x;p,q)=\int^{x}_{0}t^{p-1}(1-t)^{q-1}dt \)

When \( x=1 \), the incomplete beta function coincides wit the beta function.

The regularized incomplete beta function or just the regularized beta function in short is defined in terms of the incomplete beta function and the complete beta function. Mathematically

\( \displaystyle I_x(p,q)=\frac{B(x;p,q)}{B(p,q)} \)

The regularized beta function is the cumulative distributive function of the beta distribution.

				
					val I: betaRegularized I = new BetaRegularized(p, q);
val dI: DBetaRegularized dI = new DBetaRegularized(p, q);
double p = 0.5;
double q = 2.5;

double x = 1;
System.out.println(String.format("BetaRegularized(%f) = %f", x, I.evaluate(x)));
System.out.println(String.format("dBetaRegularized/dz(%f) = %f", x, dI.evaluate(x)));
				
			

The output is:

				
					BetaRegularized(1.000000) = 1.000000
dBetaRegularized/dz(1.000000) = 0.000000
				
			

Gamma Derivative Function

The Gamma function is an extension of the factorial function to the real and complex numbers, with its argument shifted down by 1. For real numbers, it is defined as

\( \displaystyle\Gamma(z)=\int^{\infty}_{0}x^{z-1}e^{-x}dx \)

 

				
					val G: Gamma G = new GammaLanczosQuick();
val dG: DGAmma dG = new DGamma();
double z = 0.5;
System.out.println(String.format("Gamma(%f) = %f", x, G.evaluate(z)));
System.out.println(String.format("dGamma/dz(%f) = %f", x, dG.evaluate(z)));
				
			

The output is:

				
					Gamma(0.500000) = 1.772454
dGamma/dz(0.500000) = -3.480231
				
			

Polynomial Derivative Function

A polynomial is not exactly a special function. There is a closed form solution to differentiate a ployniomial.

\( \displaystyle p(x)=a_nx^n+…a_1x+a_0 \)

\( \displaystyle \frac{dp}{dx}=na_nx^{n-1}+…a_2x+a_1 \)

				
					val p: Polynomial p = new Polynomial(1, 2, 1); // x^2 + 2x + 1
val dp: DPolynomial dp = new Dpolynomial(p); // 2x + 2
double x = 1;
System.out.println(String.format("dp/dx(%f) = %f", x, dp.evaluate(x)));
				
			

The output is:

				
					dp/dx(1.000000) = 4.000000