How to implement Beta Function effectively in Pymc3

I don’t know what is that math import. But you can use Theano's gamma function to build your beta

import theano.tensor as tt

def beta(a, b):
  return tt.gamma(a) * tt.gamma(b) / tt.gamma(a+b)

Since you seem interested in the log you can build a more numerically stable version with gammaln:

def betaln(a, b):
  return tt.gammaln(a) + tt.gammaln(b) - tt.gammaln(a+b)

Actually, there is already one implementation hiding in here:

from pymc3.distributions.dist_math import betaln