generalized quad_form to handle fvar and var