Mathematics for Computing - Logical Operators and Boolean Algebra Lab Notes
Faculty of Computing - IT1130 Mathematics for Computing
- Course Details: Year , Semester ()
- Document Context: Lab Sheet focusing on Logic and Base Conversions
Relational Expressions and Logical Operators
- Logical Operators Definition: The truth value of a Boolean expression is determined by combining the truth values of its component expressions using logical operators.
- OR (): This operator returns if at least one component expression is .
- AND (&&): This operator returns only if all component expressions are .
- NOT (): This operator inverts the truth value; becomes , and becomes .
Section 1.1 - Basic Evaluation
- Evaluation of relational assignments:
- : The condition is , so .
- : The condition is , so .
- : The condition "not equal to" is , so .
Section 1.2 - Logical Operations
Given Variables:
- (Result: , value is )
- (Result: , value is )
Evaluation Tasks:
- a \text{ && } b: Evaluates to 1 \text{ && } 0, resulting in ().
- : Evaluates to , resulting in ().
- : Evaluates to , resulting in ().
- \sim (a \text{ && } b): Evaluates to \sim (1 \text{ && } 0) = \sim (0), resulting in ().
Operator Precedence Hierarchy
Order of Operations: Unless brackets are used to modify the order, logical operators are evaluated in the following sequence:
- NOT (): Evaluated first.
- AND (&&): Evaluated second.
- OR (): Evaluated last.
Evaluation Example 1:
- Given:
- Expression: a \text{ || } b \text{ && } c
- Step 1 (AND): b \text{ && } c = 0 \text{ && } 1 = 0
- Step 2 (OR):
- Result:
Evaluation Example 2:
- Given:
- Expression: (a \text{ || } b) \text{ && } c
- Step 1 (Brackets):
- Step 2 (AND): 1 \text{ && } c = 1 \text{ && } 1 = 1
- Result:
Section 2.1 - Number Systems and Pattern Recognition
- Task: Evaluate the function for specific values of .
- Evaluations:
- For : . Output:
- For : . Output:
- For : . Output:
- For : . Output:
- Pattern Identification: The binary output consists of a string of ones where the count of ones is exactly equal to the value of .
Section 3.1 - Basic Boolean Operations
- Evaluation Q2:
- 1 \text{ && } 0: Output is .
- : Output is .
- : Output is .
Section 3.2 - Boolean Expression Evaluation
- Variables: , ,
- Evaluations Q3:
- (A \text{ && } B) \text{ || } C
- Calculation: (1 \text{ && } 0) \text{ || } 1 = 0 \text{ || } 1 = 1
- \sim (A \text{ || } B) \text{ && } C
- Calculation: \sim (1 \text{ || } 0) \text{ && } 1 = \sim (1) \text{ && } 1 = 0 \text{ && } 1 = 0
- (A \text{ && } B) \text{ || } C
Section 3.3 - Verifying Boolean Identities
- Identity Check Q4: Evaluate if (A \text{ && } (A \text{ || } B)) == A
- Trial with :
- (1 \text{ && } (1 \text{ || } 0)) = (1 \text{ && } 1) = 1.
- Since the result is , and , the equation holds true ().
- Note: It is encouraged to test other combinations of values for and to verify this Absorption Law in Boolean Algebra.
- Trial with :
Section 4.1 - Simple Decision Making Applications
- Scenario Q5: Modeling a real-life eligibility check.
- Given Data:
- (representing )
- Logic Model: (age >= 18) \text{ && } hasID
- Step-by-step Evaluation:
- evaluates to ().
- 1 \text{ && } 1 evaluates to .
- Interpretation: The output () indicates that the condition for the decision (e.g., entry or legal eligibility) has been met.
Section 4.2 - Multiple Conditions Applications
- Scenario Q6: Determining qualification based on academic performance and attendance.
- Given Data:
- Logic Model: (marks >= 50) \text{ && } (attendance >= 75)
- Step-by-step Evaluation:
- is ().
- is ().
- 1 \text{ && } 1 results in .
- Testing Variability: Students should understand how altering values (e.g., setting or ) changes the outcome, demonstrating how multiple criteria are enforced simultaneously by the AND operator.