In this assignment you will define Python functions that represent various constructs. For this assignment, you will submit
a single Python source file a1.py
.
Your file may not import any modules or employ any external library functions associated with integers and sets (unless the problem statement explicitly permits this). Solutions to each of the programming problem parts below should fit on one or two lines. You will be graded on the correctness, concision, and mathematical legibility of your code. The different problems and problem parts rely on each other; carefully consider whether you can use functions you define in one part within subsequent parts.
divides()
that takes two positive integer arguments and returns True
only if the first argument divides the second argument.
prime()
that takes a single argument and returns True
only if the argument is a prime
positive integer. You may use the range()
, len()
, and divides()
functions.
factors
that takes a single positive integer argument and returns the
set of factors of that number.
primeFactors
that takes a single positive integer argument and returns the
set of prime factors of that number.
anotherPrime
that takes a set of prime numbers and returns a new prime that
is distinct from all the others in the list. To accomplish this, compute the product p
of all the prime
numbers in the set, then return a prime factor that belongs to the set of factors
of p+1
.
generatePrimes
that takes a single input n
and returns a set
of n
distinct prime numbers. Hint: use recursion and another function you have already implemented.
implies()
that takes two arguments and correctly implements the logical operator implies.
forall
, exists
,
and/or list comprehensions. Solutions that are more than one or two lines in length will receive no credit.
product(X,Y)
that takes two sets as arguments and returns the set product of the sets.
relation(R,X,Y)
that takes three arguments and returns True
only if the
first argument R
is a relation between the second and third arguments X
and Y
.
function(R,X,Y)
that takes three arguments and returns True
only if the
first argument R
is a function from X
to Y
.
injection(R,X,Y)
that takes three arguments and returns True
only if the
first argument R
is an injection from X
to Y
.
surjection(R,X,Y)
that takes three arguments and returns True
only if the
first argument R
is a surjection from X
to Y
.
bijection(R,X,Y)
that takes three arguments and returns True
only if the
first argument R
is a bijection from X
to Y
.
transitive(R,X)
that takes two arguments and returns True
only if the
first argument R
is a transitive relation on X
.
lte(R)
that takes one argument and returns True
only if the
relation R
is a subset of the relation represented by the relational operator <=
.