Private function to hold the common objective function used by 
    all backwards solvers for the P-NTU method.
    These methods are really hard on on floating points (overflows and divide
    by zeroes due to numbers really close to 1), so if the function fails,
    mpmath is imported and tried.

def _NTU_from_P_objective(NTU1, R1, P1, function, **kwargs):
    '''Private function to hold the common objective function used by 
    all backwards solvers for the P-NTU method.
    These methods are really hard on on floating points (overflows and divide
    by zeroes due to numbers really close to 1), so if the function fails,
    mpmath is imported and tried.
    '''
    try:
        P1_calc = function(R1, NTU1, **kwargs)
    except :
        try:
            import mpmath
        except ImportError:  # pragma: no cover
            raise Exception('For some reverse P-NTU numerical solutions, the \
intermediary results are ill-conditioned and do not fit in a float; mpmath must \
be installed for this calculation to proceed.')
        globals()['exp'] = mpmath.exp
        P1_calc = float(function(R1, NTU1, **kwargs))
        globals()['exp'] = math.exp
    return P1_calc - P1