Background in Discrete Math and Logic
Table of Contents
Abstract: This article is a collection of notes on what students of Software Engineering (undergrad or grad) should know. It is assumed that a sophomore level course in Discrete Mathematics and Logic was taken. I am refraining from describing notations. As we use these ideas in our course, I will explain the notations. [New entries will be added as I discover what the students are unclear about.]
1 Sets, Bags, Tuples and Sequences
1.1 Sets
- Sets are collections of items.
- In math, a set can be a collection of dissimilar things such as a set of an orange, an elephant, a human, and a stone.
- In CS, our sets are (almost always) of values from a given type. E.g., a set of characters.
- In a set, there is no notion of duplication. A given item is or is not in a set. Some times, we may post the question: How many times does i appear in S? The answer can only be a 0 or 1.
- In a set, there is no notion of order. So, you can jumble up a set.
- Empty sets are highly useful.
1.2 Bags
- Bags are like sets, except there is a notion of duplication.
- The Q "How many times does i appear in a bag B? The answer can be a 0, 1 or higher.
1.3 Sequences
- Sequences are like bags, except there is a notion of order.
- So, there is a first, second, …, last item of a seq Q.
- The question "How many times does i appear in a seq Q? The answer can be a 0, 1 or higher.
1.4 Tuples
- Tuples are like sequences, but need not be of like values. They can be dissimilar. In CS, these also by the names of "records", structs, and "data members" (of a class).
- In our use, there is a first, second, …, last item of a tuple T.
- Equally frequently, instead of first, second, …, we may name the "fields" of a tuple T (like "data members" of a class).
- Tuples can be empty too!
- Tuples to seq conversion is "ok" only if all items were of the same type.
- Seq to tuples conversion is as expected.
2 Tables
- Tables are sets of tuples, all of a given length. Thus, we can visualize a table as columns of rows.
3 Functions and Relations
- A relation maps elements of its domain set into elements of its range set.
- When a relation is such that no element is mapped to more than one element in the range, it becomes function.
4 Propositions
- True and False are propositions.
- For other propositions, we often use letters. These are assigned a True or False value in an interpretation.
- A formula involves these things and the and (^) or (v) not (~) symbols also. A well-formed-formula (wff) is defined synatctically.
5 Predicates
- Ex: x > 1 is a predicate. It has one free variable, x. In the programming context, think of free variables as globally scoped variables.
- Predicates can involve for-all and there-exists quantifiers.
6 A implies B (A => B)
6.1 Propositions A, B: A => B
- A implies B is often written as A => B.
- By def, same as
not A or B
. Hence,- A => A,
- (False => B) is true for arbitrary B.
- (True
> B) only if B =
True. It is false otherwise. - WhatEver => True.
6.2 Predicates A, B: A => B
- In CS, it is highly useful to use attributes of size to A and B. Suppose we already know that A => B. Consider: The size of the set of values, #A, that make A true versus the size #B of the set of values that make B true. Is #A >= #B? Assume that both of these are finite numbers.
6.3 For-All/ There-Exists P(x)
- The domain X of x is/ ought-to-be clear from the context.
for-all x: P(x)
is the and-ing of P(a) for all a in X.
7 Weaker/Stronger Predicates
- If A => B we say A is stronger than B. Assuming A ! = B. We can reverse: B is weaker than A.
- Simple example on predicates: x > 7 implies x > 1.
- Consider: P implies Q (also written as P => Q)
- We say that P is stronger than Q. Alt: Q is weaker than P.
- P and Q, in general, have free variables, x, y, z, … Consider a particular assignment A of values for each of x, y, z that make P come out True. A will also make Q True.
- In the context of programming, we can refer to this A as a "state".
- Let C(Q) be the collection of such assignment of values that make Q
come out as True.
- Let C(P) be the collection of such values that make P come out as True.
- C(P) is a subset of C(Q)
- If C(P) = C(Q), P is equivalent to Q (also written as P ⇔ Q, or P ≡ Q).