def gegenbauer(alpha, n, x):
    """Return nth order Gegenbauer polynomial with weight function (1-x**2)**(alpha-0.5).

    The difference between this and scipy.special.gegenbauer is that here one
    passes the value for which the polynomial is evaluated. This makes it compatible
    with sympy.
    """
    if n == 0:
        return 1
    elif n == 1:
        return 2*alpha*x
    else:
        return (2*x*(n + alpha - 1)*gegenbauer(alpha, n - 1, x) - (n + 2*alpha - 2)*gegenbauer(alpha, n - 2, x))/n