Relations: Problems and Proofs input-output pairs

Here are some sample input-output pairs for you to try out and compare your work on the Relations: Proofs and Programs learning module.

Option 1: Relation Properties

relation1 = [(0,0), (0,1), (1,1), (2,1), (2,2)]
pairs2dict(relation1)
{0: [0, 1], 1:[1], 2: [1, 2]}

relation2 = {0: [1, 2], 1: [3, 4], 2: [2,3], 3: [ ], 4: [ ]}
relation3 = {'Jerry': ['George', 'Elaine'], 'Elaine':['Kramer']} 

dict2pairs(relation2)
[(0,1), (0,2), (1,3), (1,4), (2,2), (2,3)]

dict2pairs(relation3)
[('Jerry', 'George'), ('Jerry', 'Elaine'), ('Elaine', 'Kramer')] 
# All these functions should work regardless of whether the relation
# uses integers, strings, or whatever. 

is_reflexive(relation1)
True

is_reflexive(relation2)
False

is_symmetric(relation1)
False

is_symmetric(relation3)
False

is_antisymmetric(relation1)
True

is_antisymmetric(relation2)
True

is_transitive(relation1)
True     # Draw the digraph to see if you can tell why. 

is_transitive(relation2)
False

Option 2: Equivalence Relations

See above for sample input-output pairs for reflexivity, symmetry, and transitivity and the definitions of relation1, relation2, and relation3.

is_equivalence_relation(relation1)
False   # Not symmetric

relation4 = {0:[0,1,2], 1:[0,1,2], 2:[0,1,2], 3:[3]}

is_equivalence_relation(relation4)
True

class_of(relation1, 0)
'Error: The relation is not an equivalence relation'

class_of(relation4, 1)
[0,1,2]

class_of(relation4, 3)
[3] 

Option 3: Partial and total orderings

See above for sample input-output pairs for reflexivity, antisymmetry, and transitivity and the definitions of relation1, relation2, and relation3.

is_partial_ordering(relation1)
True

is_partial_ordering(relation3)
False

is_minimal_element(relation1, 0)
True

is_minimal_element(relation1, 1)
False

is_minimal_element(relation1, 2)
True

is_minimal_element(relation3, 'Jerry')
'Whoa there bro -- that's not a partial order'