splitOffHook
  :: HasPLE a
  => Matrix a -> Maybe (PLEHook a a, Matrix a)
splitOffHook m@(Matrix nrs ncs rs)
  | nrs == 0 || ncs == 0 = Nothing
  | otherwise = Just $ case splitOffPivotNonZero m of
      Nothing ->
        ( Hook.one nrs ncs
        , Matrix nrs (ncs-1) $ fmap V.tail rs
        )
      Just (p, ((NonZero pivot, pivotBottom), (pivotTail, bottomRight))) ->
        ( PLEHook p lt ef
        , Matrix (nrs-1) (ncs-1) bottomRight'
        )
        where
          pivotRecip = recip $ Unit pivot
          pivotTail' = fmap (fromUnit pivotRecip *) pivotTail

          lt = LT.singleton pivotRecip $ fmap negate pivotBottom
          ef = EF.singletonLeadingOne nrs pivotTail'
          
          bottomRight' =
            (\f -> V.zipWith f pivotBottom bottomRight) $ \h t ->
              V.zipWith (\pv te -> te - h * pv) pivotTail' t
splitOffHook
  :: HasPLE a
  => Matrix a -> Maybe (PLEHook a a, Matrix a)
splitOffHook m@(Matrix nrs ncs rs)
  | nrs == 0 || ncs == 0 = Nothing
  | otherwise = Just $ case splitOffPivotNonZero m of
      Nothing ->
        ( Hook.one nrs ncs
        , Matrix nrs (ncs-1) $ fmap V.tail rs
        )
      Just (p, ((NonZero pivot, pivotBottom), (pivotTail, bottomRight))) ->
        ( PLEHook p lt ef
        , Matrix (nrs-1) (ncs-1) bottomRight'
        )
        where
          pivotRecip = recip $ Unit pivot
          pivotTail' = fmap (fromUnit pivotRecip *) pivotTail

          lt = LT.singleton pivotRecip $ fmap negate pivotBottom
          ef = EF.singletonLeadingOne nrs pivotTail'
          
          bottomRight' =
            (\f -> V.zipWith f pivotBottom bottomRight) $ \h t ->
              V.zipWith (\pv te -> te - h * pv) pivotTail' t
splitOffHook m@(Matrix nrs ncs rs)
  | nrs == 0 || ncs == 0 = Nothing
  | otherwise = Just $ case splitOffPivotNonZero m of
      Nothing ->
        ( Hook.one nrs ncs
        , Matrix nrs (ncs-1) $ fmap V.tail rs
        )
      Just (p, ((NonZero pivot, pivotBottom), (pivotTail, bottomRight))) ->
        ( PLEHook p lt ef
        , Matrix (nrs-1) (ncs-1) bottomRight'
        )
        where
          pivotRecip = recip $ Unit pivot
          pivotTail' = fmap (fromUnit pivotRecip *) pivotTail

          lt = LT.singleton pivotRecip $ fmap negate pivotBottom
          ef = EF.singletonLeadingOne nrs pivotTail'
          
          bottomRight' =
            (\f -> V.zipWith f pivotBottom bottomRight) $ \h t ->
              V.zipWith (\pv te -> te - h * pv) pivotTail' t