import tensorflow as tf

        return tf.sqrt(tf.clip_by_value(x, clip_low, x))


def argus_integral_phalf(m_low, m_high, m0, c):
    """
    Only valid for argus_pdf with p=0.5! Otherwise need to do numerical
    integral.
    """
    def F(m_bound, name=None):
        with tf.name_scope(name, "argus_integral_phalf_primitive"):
            a = tf.minimum(m_bound, m0)
            x = 1 - tf.pow(a / m0, 2)
            primitive = -0.5 * m0 * m0 * (tf.exp(c * x) * tf.sqrt(x) / c + 0.5 / tf.pow(-c, 1.5) * tf.sqrt(pi) * tf.erf(gradsafe_sqrt(-c * x)))
            # We have to safeguard the sqrt, because otherwise the analytic
            # derivative blows up for x = 0
            return primitive

    area = tf.sub(F(m_high, name="F2"), F(m_low, name="F1"), name="argus_integral_phalf")
    return area


def argus_pdf_phalf_WN(m, m0, c, m_low, m_high):
    """
    WN: with normalization
