def f1(precision: float, recall: float) -> float:
    """Compute F1, returning 0.0 if undefined."""
    if precision and recall:
        return 2 * precision * recall / (precision + recall)
    else:
        return 0.0