import math


def _j_to_hsquared(func, lb, rb, g):
    """
    Transform spectral density J to square of coupling function h(x)

    This transforms the given spectral density :math:`J(\\omega)` to the square :math:`h^2(x)` of the coupling function assuming a linear dispersion relation :math:`g(x)=gx`.

    Args:
        func (types.LambdaType):
            J(omega)
        lb (float):
            Left boundary
        rb (float):
            Right boundary
        g (float):
            Constant slope of the linear dispersion relations

    Returns:
        list[float, float, types.LambdaType]:
            lb, rb, :math:`h^2`, where lb and rb are the new left and right boundaries
            for :math:`h^2`.

    """

    def h_squared(x): return func(g * x) * g / math.pi

    # change the boundaries of the interval accordingly
    lb = lb / g
    rb = rb / g
    return lb, rb, h_squared