You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- the symmetric closure of a set can be reached by including the reverse of each relation in the set, we do this by adding the reverse, followed by removing any duplicates and sorting these two items and the symmetric closure of the tail.
symClos :: Ord a => Rel a -> Rel a
symClos [] = []
symClos ((x,y):xs) = sort $ nub ((x,y):(y,x):(symClos xs))
Less expensive
symClos' :: Rel a -> Rel a
symClos' [] = []
symClos' ((x,y):xs) = (x,y):(y,x):(symClos' xs)
symClos :: Ord a => Rel a -> Rel a
symClos xs = (sort . nub) (symClos' xs)
Ex 6
-- helper function that finds all of the missing transitive relations in a set, one layer deep. It also sorts and removes duplicates to maintain set properties
trClosFunc :: Ord a => Rel a -> Rel a
trClosFunc a = nub $ sort (a ++ (a @@ a))
-- the transitive closure of a set can be found by finding missing layers until adding a missing layer does not change the set, because if adding the next layer equals adding the empty set, we have no more missing items to insert into the set. If no items are missing, this means we are done.
trClos :: Ord a => Rel a -> Rel a
trClos a = fp' trClosFunc a
It does a step too much. Less expensive
trClos :: Ord a => Rel a -> Rel a
trClos x= fp' trClosFunc ((sort.nub) x)
For the readability don't take the same name for the type and argument.
The text was updated successfully, but these errors were encountered:
Ex .5
Less expensive
Ex 6
It does a step too much. Less expensive
For the readability don't take the same name for the type and argument.
The text was updated successfully, but these errors were encountered: