Assignment 1
Assignment 1
Assignment 1 on
logic, discrete structures and
construction techniques
1
General information
Date posted: Thursday, 15 February, 2024.
Date due: Thursday, 7 March, 2024, by 23:59.
Weight: 10% of the overall grade.
Introduction
You should find one partner and between the two of you should designate a team leader who
will submit the assignment electronically. There are seven (7) problems in this assignment.
The total weight of the assignment is 100 points.
Ground rules
1. This is an assessment exercise. You may not seek any assistance while expecting to
receive credit. You must work strictly within your team and seek no assistance
for this assignment (e.g. from the teaching assistants, fellow classmates
and other teams or external help). You should not discuss the assignment during
tutorials. I am available to discuss clarifications in case you need any.
3. You must prepare this assignment in LATEX, by using a compiler on your local
machine (see Resources on course website). Submissions not prepared using LATEXwill
not be accepted.
4. If there is any problem in the team (such as lack of contribution, etc.), you must contact
me as soon as the problem appears.
2
5. Make sure you have an up-to-date VPN client on your local machine and you are able
to access our electronic submissions system.
6. Late submissions will not be accepted, and no submissions will be accepted by email.
3
PROBLEM 1: Propositional logic (5 pts)
You are shown a set of four cards placed on a table, each of which has a number on one
side and a color on the other side. The visible faces of the cards show the numbers 9 and
11, and the colors blue, and yellow.
Which card(s) must you turn over in order to test the truth of the proposition that “If
the face of a card is blue, then it has a prime number on the other side”? Explain your
reasoning by deciding for each card whether or not it should be turned over and why.
4
PROBLEM 2: Predicate logic (14 pts)
Part 1 (8 pts)
Consider types Object, and the binary relation Orbits over the domain of all celestial objects,
which is codified by clause object/1 in Prolog (available in solar.pl):
1. (2 pts) Construct a formula in predicate logic to define a planet, where planet is defined
as an object whose mass is greater than 0.33 × 1024 KG, and which it orbits around the
sun. For all practical purposes, you may ignore the 1024 KG factor.
Use the formula for Planet to construct a formula that defines the binary relation
is satellite of in terms of the binary relation Orbits. A satellite is an object that
orbits around a planet.
For Questions 2 and 3, you must a) include your interaction with the Prolog
interpreter in your main submission, and b) extend solar.pl with rules so
that we can run and assess your code.
?- is_planet(pluto).
false
?- is_planet(mars).
true
?- is_planet(P).
P = mercury;
P = venus;
5
P = earth;
P = mars;
P = jupiter;
P = saturn;
P = uranus;
P = neptune;
false
?is_satellite_of(moon, Planet).
Planet = earth;
false
is_satellite_of(S, mars).
S = deimos;
S = phobos;
false
?- obtain_all_satellites(earth, L).
L = [moon]
?- obtain_all_satellites(mars, L).
L = [deimos, phobos]
?- obtain_all_satellites(venus, L).
[]
?- obtain_all_satellites(saturn, L).
L = [atlas, calypso, helene]
6
Part 2: Categorical propositions (2 pts)
In the domain of all integers, let number (x ) denote the statement “x is a number”, and
composite(x ) denote the statement “x is a composite.” Formalize the following sentences
and indicate their corresponding formal type.
∀s : S | s ∈ P
1. Prove formally that negating A is logically equivalent to obtaining O (and vice versa).
2. Prove formally that negating E is logically equivalent to obtaining I (and vice versa).
7
PROBLEM 3: Temporal logic (22 pts)
Part 1 (16 pts)
8
Part 2 (6 pts)
1. (2 pts) Formalize and visualize the following requirement: “If none of ϕ or ψ are
invariants, then starting from time = i + 2, χ will eventually become true and it will
remain true up to and including the moment τ first becomes true. Note that there
exists no guarantee that τ ever becomes true.”
2. (2 pts) Describe the visualize the following requirement: (¬α ∨ ¬β) → ⃝3(γ U δ)
(⃝τ ∧ ⃝32χ) → ⃝2 (ϕ W ψ)
9
PROBLEM 4: Unordered structures (14 pts)
Consider the following set:
Languages = {Ruby, Go, Lisp, Rust, C , Groovy, Python, Clojure, {Lua, Groovy, C }}
2. (1 pt) Describe in detail (a) what the expression Favorites : PLanguages signifies and
(b) how it should be interpreted. (c) What could be any legitimate value for variable
Favorites?
3. (1 pt) What does the expression Favorites = PLanguages signify and (b) Is semanti-
cally equivalent to Favorites : PLanguages?
6. (1 pt) What is the difference between the following two variable declarations and are
the two variables atomic or non-atomic?
(a) λ1 : Languages
(b) λ2 : PLanguages
7. (1 pt) In the expression Library = {C , Ruby, Go}, where the variable is used to hold
any collection that can be constructed from Languages, what is the type of the variable?
10
is-memberp Returns true if its first argument is found to be a member in the set
provided by the second argument. Returns nil (false) otherwise.
equal-setsp Returns true if its two arguments are two identical sets. Returns nil
(false) otherwise. You may assume that neither argument (set) contains any
redundancies.
11
PROBLEM 5: Ordered structures (15 pts)
Consider the Queue Abstract Data Type (ADT), Q, defined over some generic type T and
defined using two stacks, Σ1 and Σ2 , where a Stack ADT is implemented as a list, Λ. (Hint:
This description implies that the only available operations are those defined for a list.)
2. (3 pts) (PROGRAMMING) Use Common LISP to define two stacks (stack1 and
stack2) as global variables to hold the collection, and implement functions enqueue
and dequeue. Place your code in file queue-adt.lisp, and include your interaction
with the language environment to demonstrate the behavior of your code.
12
NewList = [a] .
?- cons([], [], NewList).
NewList = [[]] .
13
PROBLEM 6: Binary relations, functions and orderings
(20 pts)
Part 1 (6 pts)
1. (2 pts) Consider the binary relation R: ”is of type” in the domain of types in the Java
API. Prove that R is a partial order.
3. (2 pts) Create a Hasse Diagram to visualize V , R, and identify maximal and minimal
elements.
14
Part 2 (6 pts)
1. (2 pts) Consider the binary relation ⊆: ”is subset of” in the domain of sets. Prove
that ⊆ is a partial order.
2. (2 pts) Given the set V2 = {a, b, c}, prove that (P (V2 ), ⊆) is a poset.
3. (2 pts) Create a Hasse Diagram to visualize (P (V2 ), ⊆), and identify maximal and
minimal elements.
Part 3 (8 pts)
Consider (V1 , R) and (P (V2 ), ⊆) from parts 1 and 2 respectively. Assume the following
mapping, captured by variable map:
NavigableMap 7→ {c},
TreeMap 7→ ∅}
Is map a function? Discuss in detail (in plain english and formally) all applicable prop-
erties (total vs. partial function, injectivity, surjectivity, bijection, order preserving, order
reflecting, order embedding, isomorphism).
15
PROBLEM 7: Construction techniques (10 pts)
Define a function compress : lists(T) → lists(T) that accepts a list argument (of some generic
type T) and returns a list without any subsequent redundancies, e.g.
16
What to submit
Your main submission consists of a .tex file and its corresponding .pdf compilation. All
code should (1) be embedded in your main submission file and (2) be included as supporting
documentation in separate files, and placed in a folder called /code. All demonstrations of
interactions with a language environment should be embedded in your main submission file.
Place all the above files (.tex, .pdf, and the /code folder) into a folder that is named after
you and your partner, where the name of the person to submit goes first, e.g. if Lisa Gerrard
and Nick Cave were partners and Lisa were the one to submit, then the folder is called
/gerrard-cave. Zip your folder and submit it at the Electronic Assignment Submission
portal at
(https://fis.encs.concordia.ca/eas)
under Assignment 1.
END OF ASSIGNMENT.
17