2. Solve the following problems involving relations. Recall that using Python, w
ID: 668658 • Letter: 2
Question
2. Solve the following problems involving relations. Recall that using Python, we are representing relations as sets of tuples (i.e., pairs such as (1,2)) a. Implement a function isReflexive() that takes as its input two arguments: a set x and a relation R. The function should return True if the relation R is a reflexive relation on x, and it should return False otherwise isReflexive((1,2), {(1,1), (2,2), (2,1), (1,2))) True 1sReflexíve((1,2,3), {(1,2), (2,1), (3,3))) False isReflexíve({'a','b','c'), {('a','a'), ('b','b'), ('a','c'))) False == b. Implement a function isSymmetric() that takes as its input two arguments: a set x and a relation R. The function should return True if the relation R is a symmetric relation on x, and it should return False otherwise issymmetric((1,2), {(1,1), (2,2), (2,1), (1,2))) True issymmetric((1,2,3), {(1,2), (2,1), (3,3)))·True issymmetric(('a','b','c'), {('a','a'), ('b','b'), ('a','c'))) False == c. Implement a function isTransitive( that takes as its input two arguments: a set x and a relation R. The function should return True if the relation R is a transitive relation on x, and it should return False otherwise d. Implement a function isEquivalence() that takes as its input two arguments: a set x and a relation R. The function should return True if the relation R is an equivalence relation on x, and it should return False otherwise. Hint: read the notes in this section carefully and reuse functions that have already been defined ISEquivalence((1,2,3), {(1,1), (2,2), (3,3))) True isEquivalence((1,2,3), {(1,2), (2,1), (3,3))) == False isEquivalence((1,2), {(1,1), (2,2), (1,2), (2,1)))·True isEquivalence((0,3,6), {(0,3), (3,6), (0,6), (3,0), (6,3), (6,0))) == FalseExplanation / Answer
#code to check Reflexive
x.add(1)
x.add(2)
print(x)
R=set()
R.add((1,1))
R.add((1,2))
R.add((2,1))
R.add((2,2))
print(R)
{(1, 2), (1, 1), (2, 1), (2, 2)}
ifReflexive(x,R)
def ifReflexive( x,R ):
f=false
newSet=set()
for i in x
for j in x
newSet.add((i,j))
ans= x - newSet
if len(ans) ==0:
return true
else:
return false
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.