drsBoundRef r ld@(DRS lu _) (DRS gu gc)
  | r `elem` lu           = True
  | r `elem` gu           = True
  | hasAntecedent r ld gc = True
  | otherwise             = False
  where hasAntecedent :: DRSRef -> DRS -> [DRSCon] -> Bool
        hasAntecedent r' ld' = any antecedent
          where antecedent :: DRSCon -> Bool
                antecedent (Rel _ _)     = False
                antecedent (Neg d1)      = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Imp d1 d2)   = (r' `elem` drsUniverse d1 && isSubDRS ld' d2)
                  || (isSubDRS ld' d1 && drsBoundRef r' ld' d1)
                  || (isSubDRS ld' d2 && drsBoundRef r' ld' d2)
                antecedent (Or d1 d2)    = (isSubDRS ld' d1 && drsBoundRef r' ld' d1)
                  || (isSubDRS ld' d2 && drsBoundRef r ld' d2)
                antecedent (Prop _ d1)   = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Diamond d1)  = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Box d1)      = isSubDRS ld' d1 && drsBoundRef r' ld' d1

---------------------------------------------------------------------------
-- | Returns the list of all free 'DRSRef's in a 'DRS'.
---------------------------------------------------------------------------
drsBoundRef r ld@(DRS lu _) (DRS gu gc)
  | r `elem` lu           = True
  | r `elem` gu           = True
  | hasAntecedent r ld gc = True
  | otherwise             = False
  where hasAntecedent :: DRSRef -> DRS -> [DRSCon] -> Bool
        hasAntecedent r' ld' = any antecedent
          where antecedent :: DRSCon -> Bool
                antecedent (Rel _ _)     = False
                antecedent (Neg d1)      = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Imp d1 d2)   = (r' `elem` drsUniverse d1 && isSubDRS ld' d2)
                  || (isSubDRS ld' d1 && drsBoundRef r' ld' d1)
                  || (isSubDRS ld' d2 && drsBoundRef r' ld' d2)
                antecedent (Or d1 d2)    = (isSubDRS ld' d1 && drsBoundRef r' ld' d1)
                  || (isSubDRS ld' d2 && drsBoundRef r ld' d2)
                antecedent (Prop _ d1)   = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Diamond d1)  = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Box d1)      = isSubDRS ld' d1 && drsBoundRef r' ld' d1

---------------------------------------------------------------------------
-- | Returns the list of all free 'DRSRef's in a 'DRS'.
---------------------------------------------------------------------------
drsBoundRef r ld@(DRS lu _) (DRS gu gc)
  | r `elem` lu           = True
  | r `elem` gu           = True
  | hasAntecedent r ld gc = True
  | otherwise             = False
  where hasAntecedent :: DRSRef -> DRS -> [DRSCon] -> Bool
        hasAntecedent r' ld' = any antecedent
          where antecedent :: DRSCon -> Bool
                antecedent (Rel _ _)     = False
                antecedent (Neg d1)      = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Imp d1 d2)   = (r' `elem` drsUniverse d1 && isSubDRS ld' d2)
                  || (isSubDRS ld' d1 && drsBoundRef r' ld' d1)
                  || (isSubDRS ld' d2 && drsBoundRef r' ld' d2)
                antecedent (Or d1 d2)    = (isSubDRS ld' d1 && drsBoundRef r' ld' d1)
                  || (isSubDRS ld' d2 && drsBoundRef r ld' d2)
                antecedent (Prop _ d1)   = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Diamond d1)  = isSubDRS ld' d1 && drsBoundRef r' ld' d1
                antecedent (Box d1)      = isSubDRS ld' d1 && drsBoundRef r' ld' d1

---------------------------------------------------------------------------
-- | Returns the list of all free 'DRSRef's in a 'DRS'.
---------------------------------------------------------------------------