Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 4 #3

Open
BertLisser opened this issue Oct 10, 2018 · 0 comments
Open

Lab 4 #3

BertLisser opened this issue Oct 10, 2018 · 0 comments

Comments

@BertLisser
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant