00001 // This is core/vnl/vnl_beta.h 00002 #ifndef vnl_beta_h_ 00003 #define vnl_beta_h_ 00004 //: 00005 // \file 00006 // \brief implementation of the beta function, also called the Euler integral of the first kind 00007 // \author Gamze Tunali 00008 00009 #include "vnl_gamma.h" 00010 00011 #if 1 // implementation via vnl_log_gamma 00012 //: Computation of beta function in terms of gamma function. 00013 // Actually, this implementation refers to vnl_log_gamma, 00014 // since this involves just a single call to std::exp instead of three. 00015 template <class T> 00016 inline double vnl_beta(T x, T y) {return vcl_exp(vnl_log_gamma(x)+vnl_log_gamma(y)-vnl_log_gamma(x+y)); } 00017 #else // implementation via vnl_gamma; less efficient since it needs 3x vcl_exp 00018 //: Computation of beta function in terms of gamma function. 00019 template <class T> 00020 inline double vnl_beta(T x, T y) {return (vnl_gamma(x)*vnl_gamma(y))/vnl_gamma(x+y); } 00021 #endif 00022 00023 //: Computation of the log beta function in terms of the log gamma function. 00024 // vnl_log_beta is just the std::log (natural logarithm) of the beta function. 00025 template <class T> 00026 inline double vnl_log_beta(T x, T y) {return vnl_log_gamma(x)+vnl_log_gamma(y)-vnl_log_gamma(x+y); } 00027 00028 #endif