0% found this document useful (0 votes)
2 views4 pages

Lab 2 - Logic of Compound Statements

The document outlines the fundamentals of propositional logic, including basic propositions, logical connectives (AND, OR, NOT), implication, and biconditional statements. It also discusses truth tables, tautology, and contradiction, providing examples and Python code snippets for practical understanding. Additionally, it includes exercises for evaluating logical expressions, generating truth tables, and verifying propositional equivalence.

Uploaded by

hungpro123b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Lab 2 - Logic of Compound Statements

The document outlines the fundamentals of propositional logic, including basic propositions, logical connectives (AND, OR, NOT), implication, and biconditional statements. It also discusses truth tables, tautology, and contradiction, providing examples and Python code snippets for practical understanding. Additionally, it includes exercises for evaluating logical expressions, generating truth tables, and verifying propositional equivalence.

Uploaded by

hungpro123b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

TON DUC THANG UNIVERSITY

Faculty of Information Technology

Lab 2: Logic of Compound Statements


Propositional Logic is a branch of logic dealing with propositions and their connectives,
and it forms the basis for many logical systems in computer science and mathematics.
Propositions are statements that can either be true or false. Connectives are used to
combine propositions to form compound statements.

1. Basic Propositions (True/False statements)


A proposition is a statement that is either True or False.
# Propositions
p = True # Proposition p is true
q = False # Proposition q is false

# Print the values of p and q


print(f"Proposition p: {p}")
print(f"Proposition q: {q}")

2. Logical Connectives
2.1. Conjunction, Disjunction, Negation
We use logical operators like AND, OR, and NOT to combine or modify propositions.
• AND (Conjunction): p and q is true if both p and q are true.
• OR (Disjunction): p or q is true if at least one of p or q is true.
• NOT (Negation): not p is true if p is false.

# AND operation (Conjunction)


p_and_q = p and q
print(f"p AND q: {p_and_q}")

# OR operation (Disjunction)
p_or_q = p or q
print(f"p OR q: {p_or_q}")

# NOT operation (Negation)


not_p = not p
print(f"NOT p: {not_p}")

1
TON DUC THANG UNIVERSITY
Faculty of Information Technology

2.2. Implication (if...then):


Implication (→) states that if p is true, then q must also be true. In Python, this can be
expressed as:
# Implication: p → q
implication = not p or q # Equivalent to: if p is true, then q must be true
print(f"p → q (Implication): {implication}")

2.3. Biconditional (if and only if)


The biconditional (↔) is true if both p and q have the same truth value (either both true
or both false).
# Biconditional: p ↔ q
biconditional = (p and q) or (not p and not q) # Equivalent to: p if and only if q
print(f"p ↔ q (Biconditional): {biconditional}")

3. Truth Tables
A truth table shows the truth values of propositions for all possible combinations. Here’s
an example of generating a truth table for p, q, p AND q, p OR q, and p → q:
# List of all possible truth values for p and q
propositions = [(True, True), (True, False), (False, True), (False, False)]

print("p | q | p AND q | p OR q | p → q")


print("--------------------------------------------")

for p, q in propositions:
p_and_q = p and q
p_or_q = p or q
implication = not p or q
print(f"{p:<5} | {q:<5} | {p_and_q:<8} | {p_or_q:<8} | {implication}")

Output:
p | q | p AND q | p OR q | p → q
--------------------------------------------
True | True | True | True | True
True | False | False | True | False
False | True | False | True | True
False | False | False | False | True

4. Tautology and Contradiction


• Tautology: A proposition that is always true.
• Contradiction: A proposition that is always false.

2
TON DUC THANG UNIVERSITY
Faculty of Information Technology

# Tautology: p OR NOT p is always true


tautology = p or not p
print(f"Tautology (p OR NOT p): {tautology}")

# Contradiction: p AND NOT p is always false


contradiction = p and not p
print(f"Contradiction (p AND NOT p): {contradiction}")

5. Exercises
Exercise 1: Evaluation
Create a Python function that checks if the following expressions hold true for given
values of p, q and r. Return True if the implication holds, otherwise return False.
1. p→q
2. ~p ^ q
3. p ^ (q ^ r)
4. p ^ (~q v r)

Exercise 2: Create a Truth Table


Write a Python function that generates a truth table for the following expressions for two
propositions, p and q.
1. ~p
2. p^q
3. pvq
4. p→q
5. ~p ^ q
6. ~p v q → ~q
7. (p v q) v (~p ^ q) → q

Exercise 3 + 4: Verify a Tautology/Contradiction


Write a function that checks if eacch of the logical expressions is a tautology (always true)
or a contradiction (always false).
1. p v ~p
2. p ^ ~p
3. (p ^ q) v (~p v (p ^ ~q))
4. (p ^ ~q) ^ (~p v q)

Exercise 5: Create a Truth Table for Biconditional


Write a function to generate a truth table for the folloing expressions.
1. p ↔ q
2. (p → r) ↔ (q → r)

3
TON DUC THANG UNIVERSITY
Faculty of Information Technology

Exercise 6: Generalized Truth Table for a Complex Expression


Write a Python function that generates a truth table for the folloing complex logical
expressions. Your function should display all possible truth values of p, q, and r along with
the result of the complex expression.
1. p ^ (q ^ r)
2. p ^ (~q v r)
3. p → (q ^ r)

Exercise 7: Verify Propositional Equivalence


Write a Python function to verify the propositional equivalence of each pair of logical
expressions:
1. ~(p → q) ≡ p ^ ~q
2. p → (q v r) ≡ (p ^ ~q) → r
These two expressions are logically equivalent, meaning they always have the same truth
value. Your task is to confirm this by generating a truth table and checking whether the
results of both expressions are always identical for all possible truth values of p, q and r.

Exercise 8: Validity of an Argument in Propositional Logic


Write a Python function that checks the validity of an argument with three premises and
a conclusion using the logical form:
• Premise 1: p → q
• Premise 2: q → r
• Premise 3: p
• Conclusion: r
The argument is valid if whenever the premises are true, the conclusion is also true.
Your function should evaluate the validity of the argument for all possible
combinations of p, q, and r.

You might also like