Question

Write a function in python that takes a set A and a relation R(x, y) on A (as a python function such that R(x, y) returns true if and only if the relation xRy holds), and returns True if and only if the relation R is reflexive. Here is the function signature you need to use.

def is reflexive(A, R): You can test your code as follows. s = {1,2,3} def y(x, y): return x == y def n(x, y): return x == y

0 0
Add a comment Improve this question Transcribed image text
Answer #1


ANSWER:-

CODE:-

def y(x, y):
    return x == y
def n(x, y):
    return x == y and x != 3

def is_reflexive(A, R):
    setA = []
    for i in A:
        setA.append(i)
    s = []
    for i in setA:
        for j in setA:
            if R(i,j):
                s.append((i,j))
    for item in s:
        if item[0] == item[1]:
            setA.remove(item[0])
    if len(setA) == 0:
        return True
    return False

s = {1,2,3}
is_reflexive(s,y)
is_reflexive(s,n)

NOTE:- If you need any modifications in the code,please comment below.Please give positive rating.THUMBS UP.

         THANK YOU!!!

OUTPUT:-

>>> is_reflexive (s, y) True >>> is_reflexive (s, n) False >>> |

CODE SCREENSHOT:-

def y(x, y): return x == y def n(x, y): return x == y and x != 3 def is reflexive (A, R): seta = [] for i in A: setA.append(i

Add a comment
Know the answer?
Add Answer to:
Write a function in python that takes a set A and a relation R(x, y) on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT