Skip to content

Lab 4 #3

@BertLisser

Description

@BertLisser

Ex. 6

trClos :: Ord a => Rel a -> Rel a
trClos xs = keepSearching (sort.nub) xs 

keepSearching :: Ord a => Rel a -> Rel a -> Rel a
keepSearching rel1 rel2 = if (nub(rel1++(rel1@@rel2)) == nub(rel1++rel2))
  then nub(rel1++rel2)
  else keepSearching (rel1++(rel1@@rel2)) rel2

Too expensive. It does too much steps. Better:

trClos :: Ord a => Rel a -> Rel a
trClos xs = keepSearching xs xs

keepSearching :: Ord a => Rel a -> Rel a
keepSearching rel1 = if ((sort.nub)(rel1++(rel1@@rel1)) == rel1)
  then rel1
  else keepSearching ((sort.nub) (rel1++(rel1@@rel1))) 

Ex. 7

-- Test  trClos
prop_trClos :: Ord a => Rel a -> Bool
prop_trClos r = let rclos = trClos r
                    transitiveChecks :: [Bool]
                    transitiveChecks = [ ((a, c) `elem` rclos) | (a, b) <- rclos, (c, d) <- rclos, b == c ]
                in  (nub r) `isSublist` (nub rclos) -- Check if r is subset of rclos
                 && foldr (&&) True transitiveChecks -- Check transitive property of rclos

must become

prop_trClos :: Ord a => Rel a -> Bool
prop_trClos r = let rclos = trClos r
                    transitiveChecks :: [Bool]
                    transitiveChecks = [ ((a, d) `elem` rclos) | (a, b) <- rclos, (c, d) <- rclos, b == c ]
                in  (nub r) `isSublist` (nub rclos) -- Check if r is subset of rclos
                 && foldr (&&) True transitiveChecks -- Check transitive property of rclos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions