Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Remember our definitions about functions: A function f : A B is a subset of the Cartesian product A B that satisfies the following condition:

Remember our definitions about functions: A function f : A B is a subset of the Cartesian product A B that satisfies the following condition: Every element in A maps to exactly one element in B. The set A is the domain of f, and the set B is the codomain or target of f. The range or image of a function is the set of elements in B that the function can produce. The range may or may not be equal to the target, but we can say for sure that the range is a subset of the target. A function is one-to-one (injective) if for any x1 and x2 in A, x1 x2 implies that f(x1) f(x2). In other words, no element in the target is mapped to by more than one element in the domain. A function is onto (surjective) if every element in the target is mapped to by at least one element in the domain. In other words, the range of the function is the same as its target. A function is a one-to-one correspondence (bijective) if it is both injective and surjective. A function must be bijective for it to have a well-defined inverse. Given a bijective function f : A B, the inverse of f is the function f-1 : B A such that if f(a) = b, then f-1(b) = a. In this lab, well be dealing only with functions that involve finite sets. Well use Python lists to represent these. For example, suppose you have a set A = {1, 2, 3}, a set B = {4, 5}, and a function f : A B, f = {(1, 4), (2, 5), (3, 4)}. This would be represented in Python as: A = [1, 2, 3] B = [4, 5] f = [ [1, 4], [2, 5], [3, 4] ] 1. (7 pts) Write a function isFunction(A, B, f) that determines whether the relation f is a function with the domain A and target B. A, B, and f are expressed using lists, as above. For example, calling isFunction(A, B, f) with the above variable values should return True. 2. (7 pts) Write a function image(f) that returns the image of the function f. The elements of the image should be sorted in ascending order. For example, calling image(f) with the above variable values should return the list [4, 5]. Python tip: You can sort a list like this: someList = sorted(someList) 3. (7 pts) Write a function isOneToOne(A, B, f) that determines whether the function f : A B is one-to-one. For example, calling isOneToOne(A, B, f) with the above variable values should return False. 4. (7 pts) Write a function isOnto(A, B, f) that determines whether the function f : A B is onto. For example, calling isOnto(A, B, f) with the above variable values should return True. 5. (7 pts) Write a function inverse(A, B, f) that returns the inverse of the function f : A B. If no inverse exists, return None (this is the Python equivalent of Javas null). For example, calling inverse(A, B, f) with the above variable values should return None. But if you were to define your variables like this: A = [1, 2, 3] B = [4, 5, 6] f = [ [1, 4], [2, 5], [3, 6] ] then calling inverse(A, B, f) should return something like [ [4, 1], [5, 2], [6, 3] ]

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

7. It is advisable to do favors for people whenever possible.

Answered: 1 week ago

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago