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 #4

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

Lab 4 #4

BertLisser opened this issue Oct 8, 2018 · 0 comments

Comments

@BertLisser
Copy link

BertLisser commented Oct 8, 2018

Exercise 3

crossCheckEls :: Ord a => Set a -> Set a -> Bool
crossCheckEls set1 set2 = subSet setIntersection set1 && subSet setIntersection set2
    where
        setIntersection = intersectionSet set1 set2

must be changed in

testIntersectionSet :: Ord a => Set a -> Set a -> Bool
testIntersectionSet set1 set2 = subSet setIntersection set1 && subSet setIntersection set2
    where
        setIntersection = intersectionSet set1 set2


crossCheckEls is not needed.
Exercise 5

-- Generates a list of tuples and their inverse to make in symmetrical, then
-- sorts that lits and removes any duplicates.
symClos :: Ord a => Rel a -> Rel a
symClos [] = []
symClos (x:xs) = sort( nub( swap x : x : symClos xs))

is too expensive.
Better

symClos' :: Ord a => Rel a -> Rel a
symClos' [] = []
symClos' ls@(x:xs) =  (swap x) : ls
symClos :: Ord a => Rel a -> Rel a
symClos xs = sort( nub(symClos' xs))

exercise 7

{-
    Our test is not complete. We check if transitiveness is correct but we are
    unable to check if the trClos function does not generate any additional elements.
    The odd case would be that [(1,2),(2,3)] would produce [(1,2),(2,3),(1,3)] but
    [(1,2),(2,3),(1,3),(4,5)] would also be transitive. This goes for some more
    properties that we were unable to properly define in our test. We are now checking
    that the input is a proper transitive.
-}

Good remark.
But there are simple properties which can be tested

 R ⊂ (trClose R) 
Transitivity: all  ((a,b) ∈ R , (c,d) ∈ R) b==c  -> (a,d)  ∈ R
trClose.trClose R == trClose R

You can define your test (minimality) by testing if the found relation minus one element is still transitive. If true than it is not minimal.

exercise 8
Forgotton type declaration

-- Tests if symmetry and transitivity is equal for certain sets.
testSymTrEquality (Set xs) (Set ys) = trClos (symClos (zippedSet)) == symClos (trClos (zippedSet))
    where
        zippedSet = zip xs ys
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