Boolean Logic and Sets (Vocabulary from Lecture video)
Classroom logistics and expectations
Be on time and complete check-in; the code is written on the board for students who still need to check in.
If you have an issue, tell the instructor in class and then send a Discord direct message (DM).
Please ensure you are in the class Discord server and that your display name is clear (start properly, spell correctly, and include a hello). The instructor is still missing a few people in the class channel.
After joining Discord, send a DM to introduce yourself: e.g., "Hello, this is [Name]. I'm in your competition/section."
If you want to join a challenge or have questions about it, ask in class or via Discord.
Blackboard announcements will exist, but Discord is the main channel for communication.
If you aren’t in the channel, the instructor cannot contact you; this could be because you didn’t create an account or you used an odd name.
Do not display bones on camera or on your desk; keep phones out of sight unless you have a real, important reason and you’ve informed the instructor beforehand.
Put phones away in a bag or backpack; even in pockets, you can grab your phone without realizing it—this class emphasizes professionalism.
The instructor takes professionalism seriously: the aim is to help you become good students and, later, professionals.
Classroom rules (referenced in syllabus) include punctuality and attendance policies; late arrivals are treated as absences.
Absences: you can miss up to 3 days without penalty; more than 3 absences incur a penalty.
By Friday, you should have computers and be ready to start working with Python; the goal is to connect logic and programming, leveraging prior exposure in Elements of Computer Programming I.
Some students have already done Elements One; you’ll build on that foundation.
About devices and activities: keep phones away, no headphones during class; you’ll have about 50 minutes of class time (not very long), so stay focused.
On Friday, the plan is to start using Python to implement and explore logical concepts discussed in class.
ZyBooks is a reading and exercise resource; students have been reading and working on exercises; the instructor asked what parts of programming you’ve seen (variables, inputs, etc.).
Expect a discussion and updates in Discord; materials from Monday’s slides are posted in Blackboard and later updated with today’s slides; skills check will be posted next week; exam preparation will begin after that.
The current focus includes truth tables and logical implications, which are foundational for conditional statements used in programming.
Friday’s activities will reinforce logic topics with practical Python coding; the aim is to tie logic to programming (two birds with one stone).
Tutoring: students are encouraged to seek tutoring for more practice with truth tables and logical statements; bring examples to tutoring sessions.
Important real-world reminder about AI and coding: AI tools (e.g., GPT) can produce faulty or “hallucinated” code; do not rely solely on AI for programming tasks—understand the logic, verify correctness with truth tables and reasoning, and test code thoroughly.
Logic fundamentals: implications, converses, inverses, and contrapositives
A conditional statement is of the form s o g, meaning "if s is true, then g is true."
Converse: g o s (flip the directions of the implication).
Inverse:
eg s o
eg g (negate both antecedent and consequent without flipping).Contrapositive:
eg g o
eg s (flip and negate both sides).Why study all forms? They are related and used to analyze logical implications and to reason about real-world rules.
Example: door and force
- If I apply force to the door, the door opens. This is an implication: ext{force} o ext{door opens}.
- If I do not apply force, the door might still open due to another cause (automatic door, someone else, etc.). This reflects how the original implication can fail in real-world scenarios if the antecedent is not the sole cause.
Truth table for implication p o q:
p | q | p → q | |
---|---|---|---|
T | T | T | |
T | F | F | |
F | T | T | |
F | F | T |
Key observations:
Contrapositives and real-world intuition:
Truth-table practice and intuition:
Real-world guidance for logic practice:
Morgan’s laws (De Morgan’s-like relationships for conjunctions and disjunctions):
Important caution about equivalence proofs:
Common pitfalls:
Quick practice ideas:
Heuristic about AI coding and logic:
Operators, arity, and order of operations in logic
- Arity: the number of arguments (inputs) an operator takes.
- Binary (arity = 2): ext{AND} igl(
ightarrow ext{conjunction}igr), ext{ OR }, ext{ IMPLICATION }, ext{ XOR }, ext{ etc.} - Unary (arity = 1): ext{NOT}
- Binary (arity = 2): ext{AND} igl(
- Examples of arity in logic:
- NOT (¬): unary, arity 1. If you pass T, NOT(T) = F; if F, NOT(F) = T.
- AND (∧), OR (∨), XOR (⊕), IMPLICATION (→): binary, arity 2.
- For a binary operator, you pass two inputs and get one output. Example: if you pass T and T to AND, you get T; pass T and F to AND, you get F.
- Friday lab plan:
- Implement and verify these binary operators in Python; confirm that Python evaluates these operators correctly for combinations of inputs.
- Notation reminder for operators:
- AND: ∧ or sometimes implied by juxtaposition (e.g., p q means p ∧ q in some contexts).
- OR: ∨; in some contexts XOR is denoted by ⊕ or a circled plus.
- NOT: ¬ or not in plain language.
- IMPLICATION: →; by condition (also called the conditional). If p then q.
- Order of operations in this course (memory aid):
- Parentheses first, then NOT, then AND, then XOR, then OR, then IMPLICATION (and by condition).
- The order matters for evaluating expressions with multiple operators; practice truth tables to see how different orders affect results.
- Practice tip:
- Treat sets, logic, and programming together: build expressions, evaluate their truth tables, and then implement them in code to see that the results match.
Sets: fundamentals, membership, and Venn diagrams
- What is a set?
- A set is a collection of elements (objects) where order does not matter and all elements are unique.
- Notation: a set is a collection such that elements can be described by a predicate or by listed members.
- Membership and examples:
- An element x belongs to a set S is written as x ∈ S; if x ∉ S, then x is not in S.
- Examples from the lecture:
- A set of four-legged animals might include wolves, dogs, cows, etc. Each member is a distinct animal.
- Cows can be categorized into subtypes (e.g., Jersey cows, Holstein cows); subtypes are still elements within the broader cow set, and each individual cow is unique.
- Defining sets by properties and prerequisites (examples from the course):
- Set: Computational Thinking I students. A student is in this set if they (i) are registered for the class, (ii) are BSU students, and (iii) meet any major or course prerequisites stated.
- Implications within set definitions:
- If you are a computer science student at BSU, then you are a BSU student (CS at BSU implies BSU student).
- If you are in Elements One, you are in the Computational Thinking I set (or you might have taken Elements One previously). The relationship may be inclusive (OR) rather than exclusive (XOR): you could be in Elements One now and have taken it before (e.g., you passed with a grade that you want to improve).
- Note on membership logic: being “in” a set can be described by a conjunction of properties; being “not in” a set is described by negating those properties.
- Venn diagrams:
- Used to represent sets, subsets, and intersections.
- Example: two sets with an overlap; the overlap region represents elements that belong to both sets (the intersection, corresponding to the logical AND).
- If one set is “short basketball players” and another is “basketball players,” the overlap are players who are both in the general set and in the subset (short players).
- Practical implications for data and CS:
- Understanding sets underpins data organization, queries, and database operations.
- Set theory foundations are used in data mining, data science, and database systems to retrieve needed data efficiently.
Practical notes and study guidance
Practice with real-world examples and truth tables to build intuition before coding.
Always prove equivalences with truth tables rather than relying on intuition alone.
Use tutoring and self-made examples to reinforce understanding of logical operators and their arities.
Remember the connections between logic and programming: conditionals drive program flow; correctness depends on proper logical reasoning.
Quick glossary recap:
- Implication: s o g
- Converse: g o s
- Inverse:
eg s o
eg g - Contrapositive:
eg g o
eg s - NOT (unary):
eg p - AND (binary): p \, ∧ \, q
- OR (binary): p \, ∨ \, q
- XOR (binary): p \, ⊕ \, q
- De Morgan’s laws: ¬(p ∧ q) ≡ (¬p ∨ ¬q) and ¬(p ∨ q) ≡ (¬p ∧ ¬q)
- Arity: number of inputs an operator takes (e.g., NOT has arity 1; AND, OR, IMPLICATION have arity 2).
- Sets: unordered collections of unique elements; membership defined by x ∈ S.
- Venn diagrams: visual tool to represent sets, intersections, and subsets.
Reading and assignments mentioned:
- ZyBooks readings and exercises discuss variables and inputs in programming.
- On Friday, prepare to explore logic with Python, building a computational bridge between theory and practice.
- Keep up with Blackboard updates and Discord materials; practice truth tables and set concepts repeatedly to master them.
Final study tip: truth tables are your best friends for logic. Create your own examples, verify equivalences, and then test them by implementing small programs in Python to observe the same outcomes.
Note on exam readiness:
- Expect questions about De Morgan’s laws, arity of operators, truth tables, and the relationships among implications (s → g), contrapositive, inverse, and converse.
- You might be asked to determine whether two statements are equivalent or to prove equivalence via truth tables.
- You will also encounter set-based questions and Venn diagram interpretations (e.g., intersection corresponds to logical AND).
Additional logistical reminders:
- Friday’s session will include Python practice; ensure you have the software downloaded and can access the course materials in Discord/Blackboard.
- The exam and skills checks are on the horizon; stay engaged, practice regularly, and seek tutoring when needed.
Equations and expressions included in this note use LaTeX formatting for precision:
- Implication: s \to g
- Converse: g \to s
- Inverse: \neg s \to \neg g
- Contrapositive: \neg g \to \neg s
- Morgan’s laws: \neg(p \land q) \equiv (\neg p \lor \neg q) and \neg(p \lor q) \equiv (\neg p \land \neg q)
- Truth table example for p \to q with four rows (TT, TF, FT, FF) and outputs (T, F, T, T).
- Arity examples: NOT has arity 1; AND, OR, IMPLICATION have arity 2.