Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The given code starts by initializing some sets and relations f , g , h , and r . Block 3 tests if the relation

The given code starts by initializing some sets and relations f, g, h, and r.Block 3 tests if the relation g on D1 is symmetric. Run the code and observe the output.In Block 4 write a test to determine if relation h on D2 is anti-symmetric. Your code should output any pairs showing that h is not anti-reflexive on D2.In Block 5 write a test to determine if relation f on D1 is transitive. Your code should output any triples showing that f is not transitive on D1.In Block 6 write a test to determine if relation r on D1 is transitive. Your code should output any triples showing that r is not transitive on D1.
main.py
# Block 3: Tests whether relation g on domain D1 is symmetric
# Run the code and observe the output. You do not need to add any code in Block 3
# Assume that g on domain D1 is symmetric until proven otherwise
gIsSymmetric = True
for x in D1:
for y in D1:
if (x <= y): # We only need to check each pair once, so we will check only when x <= y
if ((g(x,y)==True and g(y,x)==False) or (g(x,y)==False and g(y,x)==True)):
gIsSymmetric = False # An x, y in the domain is found where g(x,y) and g(y,x) are not the same
# The flag gIsAntiReflexive can never be set back to true.
print('The pair ('+ str(x)+','+ str(y)+') shows that g is not symmetric')
if (gIsSymmetric):
print('The relation g on domain D1 is symmetric.')
else:
print('The relation g on domain D1 is not symmetric.')
print('')
# Block 4: Tests whether relation h on domain D2 is anti-symmetric
# Assume that h on domain D2 is symmetric until proven otherwise
# Use the following line if a pair is reached showing that h is not anit-symmetric on domain D2:
# print('The pair ('+ str(x)+','+ str(y)+') shows that h is not anti-symmetric')
hIsAntiSymmetric = True
# Put your code here to test if h on domain D2 is anti-symmetric
if (hIsAntiSymmetric):
print('The relation h on domain D2 is anti-symmetric.')
else:
print('The relation h on domain D2 is not anti-symmetric.')
print('')
# Block 5: Tests whether relation f on domain D1 is transitive
# Assume that f on domain D1 is transitive until proven otherwise
# Note that each triple (x,y,z) must be tested in every possible order
# Use the following line if a triple is reached showing that f is not transitive on domain D1:
# print('The triple ('+ str(x)+','+ str(y)+','+ str(z)+') shows that f is not transitive')
fIsTransitive = True
# Put your code here to test if f on domain D1 is transitive
if (fIsTransitive):
print('The relation f on domain D1 is transitive.')
else:
print('The relation f on domain D1 is not transitive.')
print('')
# Block 6: Tests whether relation r on domain D1 is transitive
# Assume that r on domain D1 is transitive until proven otherwise
# Note that each triple (x,y,z) must be tested in every possible order
# Use the following line if a triple is reached showing that r is not transitive on domain D1:
# print('The triple ('+ str(x)+','+ str(y)+','+ str(z)+') shows that r is not transitive')
rIsTransitive = True
# Put your code here to test if r on domain D1 is transitive
if (rIsTransitive):
print('The relation r on domain D1 is transitive.')
else:
print('The relation r on domain D1 is not transitive.')
print('')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions