I'm having trouble figuring out how to determine if this list is transitive or not
D1 = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21}
I have to determine if r in the domain of D1 is transitive. I have to check every possible tuple
What I have so far
def r(x, y):
R = [[9, 7], [9, 5], [9, 3], [9, 1], [7, 5], [7, 3], [7, 1], [5, 3], [3, 1]]
return([x, y] in R)
rIsTransitive = True
for a in D1:
for b in D1:
for c in D1:
for d in D1:
if(r(a, b) and b == c):
rIsTransitive = False
print('The triple (' + str(a) + ',' + str(b) + ',' + str(c) + ') shows that r is not transitive')
if (rIsTransitive):
print('The relation r on domain D1 is transitive.')
else:
print('The relation r on domain D1 is not transitive.')
print(' ')
The output should be
The triple (5,3,1) shows that r is not transitive
The relation r on domain D1 is not transitive.
My output currently
The triple (9,5,5) shows that r is not transitive
The triple (9,5,5) shows that r is not transitive
The triple (9,5,5) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The triple (9,7,7) shows that r is not transitive
The relation r on domain D1 is not transitive.