Untitled

 avatar
unknown
plain_text
a year ago
5.7 kB
13
Indexable
def Excersice3and4():
    def check(expr):
        results = []
        for p in propositions:
            for q in propositions:
                if (expr):
                    results.append(True)
                else:
                    results.append(False)
        
        if all(results):
            print("is a tautology.")
        elif not any(results):
            print("is a contradiction.")
        else:
            print(f"Expression {expr} is neither a tautology nor a contradiction.")
    print("Exercise 3-1: ")
    check(p or not q)
    print("Exercise 3-2: ")
    check(p and not p)
    print("Exercise 3-3: ")
    check((p and q) or (not p or (p and not q)))
    print("Exercise 3-4: ")
    check((p and not q) and (not p or q))

def Excersice5():
    def generatra_biconditional_truth_table_1():
        print("p | q | r | p <-> q")
        print("------------------------------------------------")
        for p in propositions:
            for q in propositions:
                p_bi_q = (p and q) or (not p and not q)
                print(f"{p}\t{q}\t{p_bi_q}")
    def generate_biconditional_truth_table_2():
        print("p    |    q     |  r | (p -> r) <-> (q -> r)")
        print("------------------------------------------------")
        for p in propositions:
            for q in propositions:
                for i in propositions:
                    p_r = not p or r
                    q_r = not q or r
                    result = (p_r and q_r) or ( not p_r and not q_r)
                    print(f"{p}\t{q}\t{r}\t{result}")
    print("Truth table for Exercise 5-1:")
    generatra_biconditional_truth_table_1()
    print("Truth table for Exercise 5-2:")
    generate_biconditional_truth_table_2()
def Excercise6():
    def truthTableForEx1():
        print("p | q | r | q and r | p and (q and r)")
        print("---------------------------------------------------")
        for p in propositions:
            for q in propositions:
                for r in propositions:
                    q_and_r = q and r
                    result = p and (q_and_r)
                    print(f"{p}\t{q}\t{r}\t{q_and_r}\t{result}") 
    def truthTableForEx2():
        print("p | q | r | not q or r | p and (not q or r)")
        print("---------------------------------------------------")
        for p in propositions:
            for q in propositions:
                for r in propositions:
                    notq_or_r = not q or r
                    result = p and (notq_or_r)
                    print(f"{p}\t{q}\t{r}\t{notq_or_r}\t{result}")
    def truthTableForEx3():
        print("p | q | r | q and r | not p or (q and r)")
        print("---------------------------------------------------")
        for p in propositions:
            for q in propositions:
                for r in propositions:
                    q_and_r = q and r
                    result = not p or (q_and_r)
                    print(f"{p}\t{q}\t{r}\t{q_and_r}\t{result}")
    print("Truth Table For Excercise 6-1:")
    truthTableForEx1()
    print("Truth Table For Excercise 6-2:")
    truthTableForEx2()
    print("Truth Table For Excercise 6-3:")
    truthTableForEx3()

def Excercise7():
    def Ex1():
        result = []
        print("p | q | ~(~p or q) | p and not q")
        print("---------------------------------------------------")
        for p in propositions:
            for q in propositions:
                exp1 = not (not p or q)
                exp2 = p and not q
                if exp1 == exp2:
                    result.append(True)
                print(f"{p}\t{q}\t{exp1}\t{exp2}")
        if all(result):
            print("The two expressions are logically equivalent.")
        else:
            print("The two expressions are not logically equivalent.")
    def Ex2():
        result = []
        print("p | q | r | not p or (q or r) | not (p and not q) or r")
        print("---------------------------------------------------")
        for p in propositions:
            for q in propositions:
                for r in propositions:
                    exp1 = not p or (q or r)
                    exp2 = not (p and not q) or r
                    if exp1 == exp2:
                        result.append(True) 
                    print(f"{p}\t{q}\t{r}\t{exp1}\t{exp2}")
        if all(result):
            print("The two expressions are logically equivalent.")
        else:
            print("The two expressions are not logically equivalent.")
    print("Result for excercise 7-1: ")
    Ex1()
    print("Result for excercise 7-2: ")
    Ex2()
def Excercise8():
    print("The result for Exercise 8: ")
    def check_argument_validity():
        propositions = [True, False]
        valid = True
        print("p | q | r | p → q | q → r | Conclusion (r)")
        print("---------------------------------------------------")
        for p in propositions:
            for q in propositions:
                for r in propositions:
                    premise1 = not p or q  
                    premise2 = not q or r  
                    premise3 = p           
                    conclusion = r        
                    
                    if premise1 and premise2 and premise3 and not conclusion:
                        valid = False
                    
                    print(f"{p}\t{q}\t{r}\t{premise1}\t{premise2}\t{conclusion}")
        
        if valid:
            print("The argument is valid.")
        else:
            print("The argument is not valid.")
            
    check_argument_validity()


Editor is loading...
Leave a Comment