Menu
Theme
Bachelor of Science in Computer Science
Course Content

Logic

Discrete Structures

Habari Class! Welcome to the World of Logic!

Mko poa? I hope you are all settled in and ready for an exciting journey. Forget everything you think you know about 'logic'. Today, we're not just talking about arguing with your friends until you win. We are diving into Discrete Structures, and Logic is the foundation, the concrete slab on which everything else is built.

Think of it like this: You want to give someone directions from the Nairobi CBD to Kasarani. You have to give them clear, unambiguous steps: "Take the matatu at Tom Mboya street. IF it uses Thika Road, THEN you will get there faster. Pay your fare AND get your change." Every part of that instruction is a logical step. That, my friends, is what we are learning today – the art and science of perfect reasoning. Tuanze!

Part 1: The Building Blocks - Propositions

Everything in logic starts with a simple idea: a proposition. A proposition is just a statement that can be definitively declared as either TRUE or FALSE, but not both. It's not a question, not a command, not an opinion. It's a statement of fact.

  • Example of a proposition: "Nairobi is the capital city of Kenya." (This is TRUE).
  • Example of another proposition: "The Maasai Mara is in Coast Province." (This is FALSE).
  • NOT a proposition: "Where are you going?" (This is a question).
  • NOT a proposition: "Come here." (This is a command).
  • NOT a proposition: "Chapati is the best food." (This is an opinion).

In logic, we like to keep things simple. So, we use letters like p, q, and r to represent our propositions. For example:

p: It is raining in Mombasa.

q: I am a student at a Kenyan university.

Part 2: Logical Operators - The Connectors

Now, what if we want to combine these simple statements? Just like in English we use words like 'and', 'or', and 'not', in logic we use operators. Let's look at the main ones.

1. Negation (NOT)

This is the simplest one. It just flips the truth value of a proposition. The symbol is ¬ or ~.

If p is "Safaricom network is available,"

then ¬p is "Safaricom network is not available."

The truth table is very straightforward:


+---+---+
| p | ¬p|
+---+---+
| T | F |
| F | T |
+---+---+

2. Conjunction (AND)

This is the "strict parent" operator. It's only true if BOTH propositions are true. The symbol is .

Imagine your parent tells you: "You will get your pocket money if you clean your room AND you pass your CAT."

Let p: You clean your room.
Let q: You pass your CAT.

You only get the money (p ∧ q is True) if you do both things. If you do only one, or neither, you get nothing!


+---+---+-------+
| p | q | p ∧ q |
+---+---+-------+
| T | T |   T   |
| T | F |   F   |
| F | T |   F   |
| F | F |   F   |
+---+---+-------+

3. Disjunction (OR)

This is the "easy-going friend" operator. It's true if AT LEAST ONE of the propositions is true. The symbol is .

A friend asks what you're having for lunch: "I will have ugali OR rice."

Let p: You have ugali.
Let q: You have rice.

The statement is true if you have ugali, if you have rice, or if you have both! The only time it's false is if you have neither.


+---+---+-------+
| p | q | p ∨ q |
+---+---+-------+
| T | T |   T   |
| T | F |   T   |
| F | T |   T   |
| F | F |   F   |
+---+---+-------+

4. Implication (IF... THEN)

Sasa, pole pole on this one. It can be tricky. This represents a promise or a condition. The symbol is . We say "if p, then q".

Let's use a classic Kenyan promise: "IF you get an A in Discrete Structures, THEN I will buy you a new phone."

p: You get an A.
q: I will buy you a new phone.

Let's think about when the promise is broken. The only time I have lied is if you get an A (p is True), and I do not buy you a phone (q is False). In all other cases, the promise holds.

  • T → T: You get an A, I buy you a phone. Promise kept. (True)
  • T → F: You get an A, I don't buy you a phone. Promise BROKEN! (False)
  • F → T: You don't get an A, but I buy you a phone anyway. I'm generous! The promise wasn't broken. (True)
  • F → F: You don't get an A, I don't buy you a phone. The condition was never met, so promise not broken. (True)

+---+---+-------+
| p | q | p → q |
+---+---+-------+
| T | T |   T   |
| T | F |   F   |  <-- The only False case!
| F | T |   T   |
| F | F |   T   |
+---+---+-------+

Part 3: Truth Tables - The Ultimate Guide to Truth

A truth table is our best tool for figuring out the final truth value of a complex logical statement. It shows every possible combination of inputs. Let's build one for a more complex statement, like (p ∧ q) ∨ ¬r.

Step 1: List all variables (p, q, r). With 3 variables, we have 23 = 8 rows.
Step 2: Fill in the T/F values for the variables. A good trick is to alternate F/T in the last column (r), then in pairs in the next (q), then in groups of four in the first (p).
Step 3: Solve for the operations in parentheses first, one by one. First, we'll do ¬r, then (p ∧ q).
Step 4: Solve for the final operator, combining our results from Step 3.


Step-by-step construction for (p ∧ q) ∨ ¬r

+---+---+---+ | Step 1 & 2: Base columns
| p | q | r |
+---+---+---+
| T | T | T |
| T | T | F |
| T | F | T |
| T | F | F |
| F | T | T |
| F | T | F |
| F | F | T |
| F | F | F |
+---+---+---+

+---+---+---+------+---------+ | Step 3: Solve ¬r and (p ∧ q)
| p | q | r |  ¬r  | (p ∧ q) |
+---+---+---+------+---------+
| T | T | T |   F  |    T    |
| T | T | F |   T  |    T    |
| T | F | T |   F  |    F    |
| T | F | F |   T  |    F    |
| F | T | T |   F  |    F    |
| F | T | F |   T  |    F    |
| F | F | T |   F  |    F    |
| F | F | F |   T  |    F    |
+---+---+---+------+---------+

+---+---+---+------+---------+--------------------+ | Step 4: Solve the final OR
| p | q | r |  ¬r  | (p ∧ q) | (p ∧ q) ∨ ¬r     |
+---+---+---+------+---------+--------------------+
| T | T | T |   F  |    T    |         T          | <-- (T ∨ F) is T
| T | T | F |   T  |    T    |         T          | <-- (T ∨ T) is T
| T | F | T |   F  |    F    |         F          | <-- (F ∨ F) is F
| T | F | F |   T  |    F    |         T          | <-- (F ∨ T) is T
| F | T | T |   F  |    F    |         F          | <-- (F ∨ F) is F
| F | T | F |   T  |    F    |         T          | <-- (F ∨ T) is T
| F | F | T |   F  |    F    |         F          | <-- (F ∨ F) is F
| F | F | F |   T  |    F    |         T          | <-- (F ∨ T) is T
+---+---+---+------+---------+--------------------+

Image Suggestion: A vibrant and colorful infographic poster titled 'Build Your Truth Table!'. It shows the 4 steps above, with each step having a clear icon (Step 1: three lightbulbs labeled p, q, r. Step 2: a calendar grid being filled. Step 3: two puzzle pieces. Step 4: the puzzle pieces connecting). The style is modern, clean, and educational, with Kenyan-themed colors like green, red, and black accents.

Part 4: So What? Why is This Important?

You might be thinking, "This is interesting, but will I ever use it?" Absolutely! Logic is the engine of the modern world.

  • Programming: Every `if-else` statement, every `for` or `while` loop is pure logic. `if (user_is_logged_in AND user_has_permissions) { ... }`. That's a conjunction!
  • Computer Hardware: The physical chips in your phone and laptop are made of millions of tiny switches called "logic gates".

ASCII Art: Simple Logic Gates

     p ----\
            >O---- ¬p         (NOT Gate)
     q ----/


     p ----\
            )---- p ∧ q      (AND Gate)
     q ----/


     p ----\
            )---- p ∨ q      (OR Gate)
     q ----)

  • Databases: When you search for something, you are using logic. "Find all students from Nairobi County `AND` whose grade is `> 80`."
  • Everyday Life: It helps you think clearly, structure arguments, and avoid fallacies. When a politician makes a promise, you can now analyze it like an implication (p → q) and see if they've broken their promise!

Image Suggestion: A dynamic digital art piece showing a brain made of glowing circuit lines. From the brain, connections flow out to different real-world applications: a programmer writing code on a laptop, a complex database query on a screen, and a person making a decision at a crossroads with signs like 'Take Boda' or 'Take Matatu'. The style should be futuristic and inspiring.

Let's Wrap It Up!

Today, we've learned that logic is not about arguing, but about building solid, truthful statements. We've seen that simple propositions (statements that are T/F) can be connected with powerful operators like AND, OR, NOT, and IF...THEN. And we learned that the mighty truth table is our guide to finding the truth in any complex statement.

This is the language that computers speak. It's the framework for good reasoning. Master this, and you are on your way to mastering a huge part of computer science and critical thinking. Sawa? You've got this!

Pro Tip

Take your own short notes while going through the topics.

Previous Sets
KenyaEdu
Add KenyaEdu to Home Screen
For offline access and faster experience