Professional Documents
Culture Documents
Assignment 2A - SP23
Assignment 2A - SP23
Islamabad Campus
Department of Computer Science
the solution files of some students are same then I will reward zero marks to all
those students.
6. The deadline for this assignment is May 29, 2023. This deadline will not be extended.
ii)
iii)
ii)
Question # 2A(Designing a function from a given real life scenario)
A town in Islamabad charges each household a minimum of Rs.75 for upto 4000 cubic feet(ft3) of water every
6 months. In addition, each household has to pay 60 paisa for every 100 ft3 of water in excess of 4000 ft3.
Express the water bill f(x) as a function of number of cubic feet of water x used for 6 months.
Question # 2B(Writing alternative definitions using Predicate logic)
a) Write the definition of “one-to-one” using logical notation (i.e., use , ∃, etc.).
b) Use De Morgan’s laws of logic to negate the definition of “one-to-one.”
c) Write the definition of “onto” using logical notation (i.e., use , ∃, etc.).
d) Use De Morgan’s laws of logic to negate the definition of “onto.”
Question # 3 (Computing functional value and prove its properties)
Let f be the function from X = {0, 1, 2, 3, 4} to X defined by
f (x) = 4x mod 5.
i. Write f as a set of ordered pairs and draw the arrow diagram of f.
ii. Is f one-to-one? Is f onto?
Question # 4 (Design a function and prove its properties)
Let X = {a, b, c}. Define a function S from P(X) to the set of bit strings of length 3 as follows:
Let Y ⊆ X. If a ∈ Y, set s1 = 1; if a Y, set s1 = 0. If b ∈ Y, set s2 = 1; if b Y, set s2 = 0. If c ∈ Y, set s3 = 1;
if c Y, set s3 = 0. Define S(Y) = s1s2s3.
i. What is the value of S({a, c})?
ii. What is the value of S(∅)?
iii. What is the value of S(X)?
iv. Prove that S is one-to-one.
v. Prove that S is onto.
Question # 5 (Computing functional value)
One-to One?
ii) Show that the function defined by
is One-to One.
iii) Draw the graph of the piecewise-defined functions defined by
Determine f ∘ g
vii) Consider the following two piecewise functions defined by
Question # 7
Rewrite each sum using the summation notation.
1. S(2,2) 2. S(5,2)
C. The gcd of two non-zero positive numbers can be defined recursively as follows:
D. Consider the following function f, invited by Johm McCarthy (one of the father of Artificial
Intelligence).
F. Square pyramidal numbers Sn are positive integers that can be represented by pyramidal shapes, where the base
is square. The first four square pyramidal numbers are 1, 5, 14, and 30; see below figure.
G. Triangular pyramidal numbers Tn (or tetrahedral numbers) are positive integers that can be represented
by triangular pyramidal shapes. The first four tetrahedral numbers are 1, 4, 10, and 20; see below figure.
Define recursive formula for Tn/