Answered step by step
Verified Expert Solution
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 rBlock tests if the relation g on D is symmetric. Run the code and observe the output.In Block write a test to determine if relation h on D is antisymmetric. Your code should output any pairs showing that h is not antireflexive on DIn Block write a test to determine if relation f on D is transitive. Your code should output any triples showing that f is not transitive on DIn Block write a test to determine if relation r on D is transitive. Your code should output any triples showing that r is not transitive on D
main.py
# Block : Tests whether relation g on domain D is symmetric
# Run the code and observe the output. You do not need to add any code in Block
# Assume that g on domain D is symmetric until proven otherwise
gIsSymmetric True
for x in D:
for y in D:
if x y: # We only need to check each pair once, so we will check only when x y
if gxyTrue and gyxFalse or gxyFalse and gyxTrue:
gIsSymmetric False # An x y in the domain is found where gxy and gyx are not the same
# The flag gIsAntiReflexive can never be set back to true.
printThe pair strx stry shows that g is not symmetric'
if gIsSymmetric:
printThe relation g on domain D is symmetric.
else:
printThe relation g on domain D is not symmetric.
print
# Block : Tests whether relation h on domain D is antisymmetric
# Assume that h on domain D is symmetric until proven otherwise
# Use the following line if a pair is reached showing that h is not anitsymmetric on domain D:
# printThe pair strx stry shows that h is not antisymmetric'
hIsAntiSymmetric True
# Put your code here to test if h on domain D is antisymmetric
if hIsAntiSymmetric:
printThe relation h on domain D is antisymmetric.
else:
printThe relation h on domain D is not antisymmetric.
print
# Block : Tests whether relation f on domain D is transitive
# Assume that f on domain D is transitive until proven otherwise
# Note that each triple xyz must be tested in every possible order
# Use the following line if a triple is reached showing that f is not transitive on domain D:
# printThe triple strx stry strz shows that f is not transitive'
fIsTransitive True
# Put your code here to test if f on domain D is transitive
if fIsTransitive:
printThe relation f on domain D is transitive.
else:
printThe relation f on domain D is not transitive.
print
# Block : Tests whether relation r on domain D is transitive
# Assume that r on domain D is transitive until proven otherwise
# Note that each triple xyz must be tested in every possible order
# Use the following line if a triple is reached showing that r is not transitive on domain D:
# printThe triple strx stry strz shows that r is not transitive'
rIsTransitive True
# Put your code here to test if r on domain D is transitive
if rIsTransitive:
printThe relation r on domain D is transitive.
else:
printThe relation r on domain D is not transitive.
print
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started