truth table: test_truth_table_tests
I want to write a program that makes the tests in test_truth_table.py pass without looking at them
requirements
continue the project
Make sure you are in the
pumping_pythonfolder with pwd in the terminalpwdif the terminal shows anything other than
.../pumping_pythonchange directory to the
pumping_pythonfolderOnce in
pumping_python, change directory to the projectcd truth_tablethe terminal shows
.../pumping_python/truth_tableI run the tests with pytest-watcher
uv run pytest-watcher . --nowthe terminal shows
rootdir: .../pumping_python/truth_table configfile: pyproject.toml collected 20 items tests/test_binary.py .................... [ 80%] tests/test_nullary_unary.py .... [100%] ======================== 20 passed in G.HIs ========================
RED: make it fail
GREEN: make it pass
I add the name to
truth_table.py1logical_negationNameError: name 'logical_negation' is not definedI point it to None to define it
1logical_negation = NoneTypeError: 'NoneType' object is not callableI make it a function
1def logical_negation(): 2 return NoneTypeError: logical_negation() takes 0 positional arguments but 1 was givenI add a name in parentheses
1def logical_negation(something): 2 return Nonethe terminal shows AssertionError
AssertionError: None is not truethe test expects True
I change None in the return statement to give the test what it wants
1def logical_negation(something): 2 return Truethe terminal shows AssertionError
AssertionError: True is not falseI change the return statement
1def logical_negation(something): 2 return Falsethe terminal shows AssertionError
AssertionError: False is not truethe test expects
I change the return statement to see the difference between the input and what the test expects
1def logical_negation(something): 2 return somethingthe terminal shows AssertionError
AssertionError: True is not falsethe test expects
I use not in the return statement
1def logical_negation(something): 2 return not something1 test passes with 19 failures to go, progress! The terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_identity'I add a function for it
1def logical_negation(something): 2 return not something 3 4 5def logical_identity(): 6 return NoneTypeError: logical_identity() takes 0 positional arguments but 1 was givenI add a name in parentheses
5def logical_identity(something): 6 return Nonethe terminal shows AssertionError
AssertionError: None is not trueI change the return statement to give the test what it wants
5def logical_identity(something): 6 return Truethe terminal shows AssertionError
AssertionError: True is not falseI change the return statement
5def logical_identity(something): 6 return Falsethe terminal shows AssertionError
AssertionError: False is not truethe test expects
I change the return statement to see the difference between the input and what the test expects
5def logical_identity(something): 6 return something18 failed, 2 passed, more progress! The terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_true'I add the function
5def logical_identity(something): 6 return something 7 8 9def logical_true(): 10 return Nonethe terminal shows AssertionError
AssertionError: None is not trueI change the return statement to give the test what it wants
9def logical_true(): 10 return True17 failed, 3 passed. That was simple. The terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_false'. Did you mean: 'logical_true'?I add the function
9def logical_true(): 10 return True 11 12 13def logical_false(): 14 return None16 failed, 4 passed, simple again. I am getting it. The terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'tautology'I add the function
13def logical_false(): 14 return None 15 16 17def tautology(): 18 return NoneTypeError: tautology() takes 0 positional arguments but 2 were givenI add two names in parentheses for the function to take input arguments
17def tautology(first, second): 18 return Nonethe terminal shows AssertionError
AssertionError: None is not trueI change None to True in the return statement
17def tautology(first, second): 18 return True15 failed, 5 passed, Ayy! the terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'project_second'I add the function
17def tautology(first, second): 18 return True 19 20 21def project_second(): 22 return NoneTypeError: project_second() takes 0 positional arguments but 2 were givenI add two names in parentheses for the function to take input arguments
21def project_second(first, second): 22 return Nonethe terminal shows AssertionError
AssertionError: None is not trueI change the return statement to give the test what it wants
21def project_second(first, second): 22 return Falsethe terminal shows AssertionError
AssertionError: False is not trueI change the return statement
21def project_second(first, second): 22 return Truethe terminal shows AssertionError
AssertionError: True is not falsethe test expects
I change the return statement to see the difference between the input and what the test expects
21def project_second(first, second): 22 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI remove
firstfrom the return statement sincesecondis False21def project_second(first, second): 22 return second14 failed, 6 passed. The terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'project_first'I add a function for it
21def project_second(first, second): 22 return second 23 24 25def project_first(): 26 return NoneTypeError: project_second() takes 0 positional arguments but 2 were givenokay, I have seen this before
I add 2 names in parentheses
41def project_first(first, second): 42 return Nonethe terminal shows AssertionError
AssertionError: None is not trueI change the return statement to give the test what it wants
41def project_first(first, second): 42 return Truethe terminal shows AssertionError
AssertionError: True is not falseI change the return statement
41def project_first(first, second): 42 return Falsethe terminal shows AssertionError
AssertionError: False is not truethe test expects
I change the return statement to see the difference between the input and what the test expects
41def project_first(first, second): 42 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not falseI remove
secondfrom the return statement sincefirstis False41def project_first(first, second): 42 return first13 failed, 7 passed. The terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'negate_second'I add a function for negate_second with a return statement to see the difference between the input and what the test expects
41def project_first(first, second): 42 return first 43 44 45def negate_second(first, second): 46 return first, secondthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement to negate_second since
firstandsecondare both not False29def negate_second(first, second): 30 if (first, second) == (True, True): return False 31 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
29def negate_second(first, second): 30 if (first, second) == (True, True): return False 31 if (first, second) == (False, True): return False 32 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'negate_first'I add a function for it with a return statement to see the difference between the input and what the test expects
29def negate_second(first, second): 30 if (first, second) == (True, True): return False 31 if (first, second) == (False, True): return False 32 return first, second 33 34 35def negate_first(first, second): 36 return first, secondthe terminal shows AssertionError
AssertionError: (True, True)I add an if statement
35def negate_first(first, second): 36 if (first, second) == (True, True): return False 37 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add another if statement
35def negate_first(first, second): 36 if (first, second) == (True, True): return False 37 if (first, second) == (True, False): return False 38 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'material_non_implication'I add a function for material_non_implication with a return statement to see the difference between the input and what the test expects
35def negate_first(first, second): 36 if (first, second) == (True, True): return False 37 if (first, second) == (True, False): return False 38 return first, second 39 40 41def material_non_implication(first, second): 42 return first, secondthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
41def material_non_implication(first, second): 42 if (first, second) == (True, True): return False 43 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
41def material_non_implication(first, second): 42 if (first, second) == (True, True): return False 43 if (first, second) == (False, True): return False 44 return first, secondthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement for it
41def material_non_implication(first, second): 42 if (first, second) == (True, True): return False 43 if (first, second) == (False, True): return False 44 if (first, second) == (False, False): return False 45 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'material_implication'I add a function for material_implication with a return statement to see the difference between the input and what the test expects
41def material_non_implication(first, second): 42 if (first, second) == (True, True): return False 43 if (first, second) == (False, True): return False 44 if (first, second) == (False, False): return False 45 return first, second 46 47 48def material_implication(first, second): 49 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add an if statement
48def material_implication(first, second): 49 if (first, second) == (True, False): return False 50 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_nor'I add a function for logical_nor
48def material_implication(first, second): 49 if (first, second) == (True, False): return False 50 return first, second 51 52 53def logical_nor(first, second): 54 return first, secondthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
53def logical_nor(first, second): 54 if (first, second) == (True, True): return False 55 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add another if statement
53def logical_nor(first, second): 54 if (first, second) == (True, True): return False 55 if (first, second) == (True, False): return False 56 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add an if statement
53def logical_nor(first, second): 54 if (first, second) == (True, True): return False 55 if (first, second) == (True, False): return False 56 if (first, second) == (False, True): return False 57 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_nand'. Did you mean: 'logical_nor'?I add a function for logical_nand
53def logical_nor(first, second): 54 if (first, second) == (True, True): return False 55 if (first, second) == (True, False): return False 56 if (first, second) == (False, True): return False 57 return first, second 58 59 60def logical_nand(first, second): 61 return first, secondthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
76def logical_nand(first, second): 77 if (first, second) == (True, True): return False 78 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_equality'I add the function
76def logical_nand(first, second): 77 if (first, second) == (True, True): return False 78 return first, second 79 80 81def logical_equality(first, second): 82 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add an if statement
65def logical_equality(first, second): 66 if (first, second) == (True, False): return False 67 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
65def logical_equality(first, second): 66 if (first, second) == (True, False): return False 67 if (first, second) == (False, True): return False 68 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_disjunction'I add a function for logical_disjunction
65def logical_equality(first, second): 66 if (first, second) == (True, False): return False 67 if (first, second) == (False, True): return False 68 return first, second 69 70 71def logical_disjunction(first, second): 72 return first, secondthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement
71def logical_disjunction(first, second): 72 if (first, second) == (False, False): return False 73 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_conjunction'. Did you mean: 'logical_disjunction'?I add a function for logical_conjunction
71def logical_disjunction(first, second): 72 if (first, second) == (False, False): return False 73 return first, second 74 75 76def logical_conjunction(first, second): 77 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add an if statement
76def logical_conjunction(first, second): 77 if (first, second) == (True, False): return False 78 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add an if statement
76def logical_conjunction(first, second): 77 if (first, second) == (True, False): return False 78 if (first, second) == (False, True): return False 79 return first, secondthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add another if statement
76def logical_conjunction(first, second): 77 if (first, second) == (True, False): return False 78 if (first, second) == (False, True): return False 79 if (first, second) == (False, False): return False 80 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'exclusive_disjunction'I add a function for exclusive_disjunction
76def logical_conjunction(first, second): 77 if (first, second) == (True, False): return False 78 if (first, second) == (False, True): return False 79 if (first, second) == (False, False): return False 80 return first, second 81 82 83def exclusive_disjunction(first, second): 84 return first, secondthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
83def exclusive_disjunction(first, second): 84 if (first, second) == (True, True): return False 85 return first, secondthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add another if statement
83def exclusive_disjunction(first, second): 84 if (first, second) == (True, True): return False 85 if (first, second) == (False, False): return False 86 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'converse_non_implication'. Did you mean: 'material_non_implication'?I add converse_non_implication
83def exclusive_disjunction(first, second): 84 if (first, second) == (True, True): return False 85 if (first, second) == (False, False): return False 86 return first, second 87 88 89def converse_non_implication(first, second): 90 return first, secondthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
89def converse_non_implication(first, second): 90 if (first, second) == (True, True): return False 91 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add another if statement
89def converse_non_implication(first, second): 90 if (first, second) == (True, True): return False 91 if (first, second) == (True, False): return False 92 return first, secondthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement
89def converse_non_implication(first, second): 90 if (first, second) == (True, True): return False 91 if (first, second) == (True, False): return False 92 if (first, second) == (False, False): return False 93 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'converse_implication'. Did you mean: 'converse_non_implication'?-
89def converse_non_implication(first, second): 90 if (first, second) == (True, True): return False 91 if (first, second) == (True, False): return False 92 if (first, second) == (False, False): return False 93 return first, second 94 95 96def converse_implication(first, second): 97 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not false I add an if statement
96def converse_implication(first, second): 97 if (first, second) == (False, True): return False 98 return first, secondthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'contradiction'I add contradiction
96def converse_implication(first, second): 97 if (first, second) == (False, True): return False 98 return first, second 99 100 101def contradiction(first, second): 102 return first, secondthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
101def contradiction(first, second): 102 if (first, second) == (True, True): return False 103 return first, secondthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add another if statement
101def contradiction(first, second): 102 if (first, second) == (True, True): return False 103 if (first, second) == (True, False): return False 104 return first, secondthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
101def contradiction(first, second): 102 if (first, second) == (True, True): return False 103 if (first, second) == (True, False): return False 104 if (first, second) == (False, True): return False 105 return first, secondthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement
101def contradiction(first, second): 102 if (first, second) == (True, True): return False 103 if (first, second) == (True, False): return False 104 if (first, second) == (False, True): return False 105 if (first, second) == (False, False): return False 106 return first, secondthe terminal shows
======================== 20 passed in G.HIs ========================
All the tests are passing and the world is a better place than when I started! I am going home. Wait, there is more…
REFACTOR: make it better
I can play with the functions I have to make them simpler and understand why my solutions work, since all the tests are passing.
contradiction returns False in 4 cases, with 2 inputs there are only 4 cases. I add a return statement
101def contradiction(first, second): 102 return False 103 if (first, second) == (True, True): return False 104 if (first, second) == (True, False): return False 105 if (first, second) == (False, True): return False 106 if (first, second) == (False, False): return False 107 return first, secondthe test is still green.
I remove the other lines in contradiction
101def contradiction(first, second): 102 return False
converse_implication returns False in only one case. I write out the if statement
96def converse_implication(first, second): 97 # if (first, second) == (False, True): return False 98 if first == False and second == True: 99 return False 100 return first, secondstill green
I change the statement with not and True
96def converse_implication(first, second): 97 # if first == False and second == True: 98 if not first == True and second == True: 99 return False 100 return first, secondgreen
I remove
== True96def converse_implication(first, second): 97 # if not first == True and second == True: 98 if not first and second: 99 return False 100 return first, secondstill green
I use a return statement because
if something: return Falseis the same asreturn not (something)96def converse_implication(first, second): 97 return not (not first and second) 98 if not first and second: 99 return False 100 return first, secondthe test is still green
I remove the other statements then “multiply not” by the things in the parentheses
96def converse_implication(first, second): 97 return (not not first) (not and) (not second) 98 return not (not first and second)the terminal shows SyntaxError
SyntaxError: invalid syntaxI change
not andto or96def converse_implication(first, second): 97 return (not not first) or (not second) 98 return not (not first and second)the test is green again
I remove the other return statement and
not notbecause two nots make a right?96def converse_implication(first, second): 97 return first or not second 98 return (not not first) or (not second)the test is still green
I remove the other statement in converse_implication
96def converse_implication(first, second): 97 return first or not second 98 99 100def contradiction(first, second): 101 return False
I add an if statement for the only case that returns True in converse_non_implication
89def converse_non_implication(first, second): 90 if (first, second) == (False, True): return True 91 if (first, second) == (True, True): return False 92 if (first, second) == (True, False): return False 93 if (first, second) == (False, False): return False 94 return first, secondthe test is still green
I break the statement up then add an else clause for the other 3 statements
89def converse_non_implication(first, second): 90 # if (first, second) == (False, True): return True 91 if first == False and second == True: 92 return True 93 else: 94 return False 95 if (first, second) == (True, True): return False 96 if (first, second) == (True, False): return False 97 if (first, second) == (False, False): return False 98 return first, secondstill green
I remove the commented line and other statements, then change the if statement with True
89def converse_non_implication(first, second): 90 # if first == False and second == True: 91 if not first == True and second == True: 92 return True 93 else: 94 return Falsegreen
I remove
== True89def converse_non_implication(first, second): 90 # if not first == True and second == True: 91 if not first and second: 92 return True 93 else: 94 return Falsestill green
I add a return statement because
if something: return Trueis the same asreturn something89def converse_non_implication(first, second): 90 return not first and second 91 if not first and second: 92 return True 93 else: 94 return Falsethe test is still green
I remove the other statements in converse_non_implication
89def converse_non_implication(first, second): 90 return not first and second 91 92 93def converse_implication(first, second): 94 return first or not second
I make the if statements in exclusive_disjunction simpler
83def exclusive_disjunction(first, second): 84 if (first, second) == (True, True): return False 85 if (first, second) == (False, False): return False 86 if first == True and second == True: 87 return False 88 if first == False and second == False: 89 return False 90 return first, secondthe test is still green
I remove the first two if statements then change the new second if statement with not and True
83def exclusive_disjunction(first, second): 84 if first == True and second == True: 85 return False 86 # if first == False and second == False: 87 if not first == True and not second == True: 88 return False 89 return first, secondstill green
I remove
== True83def exclusive_disjunction(first, second): 84 # if first == True and second == True: 85 if first and second: 86 return False 87 # if not first == True and not second == True: 88 if not first and not second: 89 return False 90 return first, secondgreen
I write everything in the second if statement with not because it happens two times in the line
83def exclusive_disjunction(first, second): 84 if first and second: 85 return False 86 # if not first and not second: 87 if (not first) (not or) (not second): 88 return False 89 return first, secondthe terminal shows SyntaxError
SyntaxError: invalid syntaxI factor out the nots
83def exclusive_disjunction(first, second): 84 if first and second: 85 return False 86 # if not first and not second: 87 # if (not first) (not or) (not second): 88 if not (first or second): 89 return False 90 return first, secondthe test is green again
I put the two if statements together to make one
83def exclusive_disjunction(first, second): 84 # if first and second: 85 # return False 86 # if not (first or second): 87 if (first and second) or (not (first or second)): 88 return False 89 return first, secondthe test is still green
I remove the commented lines, then add a return statement because
if something: return Falseis the same asreturn not (something)83def exclusive_disjunction(first, second): 84 return not ( 85 (first and second) 86 or 87 (not (first or second)) 88 ) 89 if (first and second) or (not (first or second)): 90 return False 91 return first, secondstill green
I remove the other statements then multiply not by everything in the parentheses because it happens two times in the line
83def exclusive_disjunction(first, second): 84 return ( 85 (not (first and second)) 86 (not or) 87 (not (not (first or second))) 88 ) 89 return not ( 90 (first and second) 91 or 92 (not (first or second)) 93 )the terminal shows SyntaxError
SyntaxError: invalid syntaxI change
not orto and83def exclusive_disjunction(first, second): 84 return ( 85 (not (first and second)) 86 and 87 (not (not (first or second))) 88 ) 89 return not ( 90 (first and second) 91 or 92 (not (first or second)) 93 )the test is green again
I remove
not notbecause “the negation of a negation is …”83def exclusive_disjunction(first, second): 84 return ((not (first and second)) and (first or second)) 85 return not ( 86 (first and second) 87 or 88 (not (first or second)) 89 )green
I remove the other statements in exclusive_disjunction
83def exclusive_disjunction(first, second): 84 return (not (first and second)) and (first or second) 85 86 87def converse_non_implication(first, second): 88 return not first and second
logical_conjunction has only one case that returns True, it is the case. I add an if statement for it
76def logical_conjunction(first, second): 77 if (first, second) == (True, True): return True 78 if (first, second) == (True, False): return False 79 if (first, second) == (False, True): return False 80 if (first, second) == (False, False): return False 81 return first, secondthe test is still green
I remove the other statements and break up the if statement to make it simpler
76def logical_conjunction(first, second): 77 # if (first, second) == (True, True): return True 78 if first == True and second == True: 79 return Truethe test is still green because all functions return None by default, as if they have an invisible line that says return None
I remove
== True76def logical_conjunction(first, second): 77 # if first == True and second == True: 78 if first and second: 79 return Truestill green
I use a return statement because
if something: return Trueis the same asreturn something76def logical_conjunction(first, second): 77 return first and second 78 if first and second: 79 return Truegreen
I remove the other statements in logical_conjunction
76def logical_conjunction(first, second): 77 return first and second 78 79 80def exclusive_disjunction(first, second): 81 return (not (first and second)) and (first or second)
logical_disjunction has only one case that returns False, I break up the if statement
71def logical_disjunction(first, second): 72 # if (first, second) == (False, False): return False 73 if first == False and second == False: 74 return False 75 return first, secondthe test is still green
I remove the comment then change the if statement with not and True
71def logical_disjunction(first, second): 72 # if first == False and second == False: 73 if not first == True and not second == True: 74 return False 75 return first, secondstill green
I remove
== True71def logical_disjunction(first, second): 72 # if not first == True and not second == True: 73 if not first and not second: 74 return False 75 return first, secondgreen
I change the statement with not because it happens two times
71def logical_disjunction(first, second): 72 # if not first and not second: 73 if (not first) (not and) (not second): 74 return False 75 return first, secondthe terminal shows SyntaxError
SyntaxError: invalid syntaxI factor out not
71def logical_disjunction(first, second): 72 # if not first and not second: 73 # if (not first) (not or) (not second): 74 if not (first or second): 75 return False 76 return first, secondthe test is green again
I add a return statement for the opposite of the if statement because
if something: return Falseis the same asreturn not (something)71def logical_disjunction(first, second): 72 return not (not (first or second)) 73 if not (first or second): 74 return False 75 return first, secondstill green
I remove
not not71def logical_disjunction(first, second): 72 return first or second 73 return not (not (first or second))the test is still green
I remove the other statement in logical_disjunction
71def logical_disjunction(first, second): 72 return first or second 73 74 75def logical_conjunction(first, second): 76 return first and second
I break up the if statements in logical_equality
65def logical_equality(first, second): 66 # if (first, second) == (True, False): return False 67 if first == True and second == False: 68 return False 69 # if (first, second) == (False, True): return False 70 if first == False and second == True: 71 return False 72 return first, secondthe test is still green
I remove the comments then change the if statements with not and True
65def logical_equality(first, second): 66 # if first == True and second == False: 67 if first == True and not second == True: 68 return False 69 # if first == False and second == True: 70 if not first == True and second == True: 71 return False 72 return first, secondstill green
I remove
== True65def logical_equality(first, second): 66 # if first == True and not second == True: 67 if first and not second: 68 return False 69 # if not first == True and second == True: 70 if not first and second: 71 return False 72 return first, secondgreen
I put the two if statements together to make one
65def logical_equality(first, second): 66 # if first and not second: 67 # return False 68 # if not first and second: 69 if (first and not second) or (not first and second): 70 return False 71 return first, secondstill green
I use a return statement because …
65def logical_equality(first, second): 66 return not ( 67 (first and not second) 68 or 69 (not first and second) 70 ) 71 if (first and not second) or (not first and second): 72 return False 73 return first, secondthe test is still green
I multiply not by all the symbols in parentheses
65def logical_equality(first, second): 66 return ( 67 (not (first and not second)) 68 (not or) 69 (not (not first and second)) 70 ) 71 return not ( 72 (first and not second) 73 or 74 (not first and second) 75 )the terminal shows SyntaxError
SyntaxError: invalid syntaxI change
not orto and65def logical_equality(first, second): 66 return ( 67 (not (first and not second)) 68 and 69 (not (not first and second)) 70 ) 71 return not ( 72 (first and not second) 73 or 74 (not first and second) 75 )the test is green again
I multiply not by the symbols in the first part of the statement
65def logical_equality(first, second): 66 return ( 67 # (not (first and not second)) 68 ((not first) (not and) (not not second)) 69 and 70 (not (not first and second)) 71 )the terminal shows SyntaxError
SyntaxError: invalid syntaxI change
not andto or65def logical_equality(first, second): 66 return ( 67 # (not (first and not second)) 68 ((not first) or (not not second)) 69 and 70 (not (not first and second)) 71 )the test is green again
I remove
not not65def logical_equality(first, second): 66 return ( 67 # ((not first) or (not not second)) 68 (not first or second) 69 and 70 (not (not first and second)) 71 )still green
I multiply not by the symbols in the second part of the statement
65def logical_equality(first, second): 66 return ( 67 (not first or second) 68 and 69 # (not (not first and second)) 70 ((not not first) (not and) (not second)) 71 )the terminal shows SyntaxError
65SyntaxError: invalid syntaxI change
not andto or65def logical_equality(first, second): 66 return ( 67 (not first or second) 68 and 69 # (not (not first and second)) 70 ((not not first) or (not second)) 71 )the test is still green
I remove
not not65def logical_equality(first, second): 66 return ( 67 (not first or second) 68 and 69 # ((not not first) or (not second)) 70 (first or not second) 71 )still green
I remove the comment
65def logical_equality(first, second): 66 return (not first or second) and (first or not second) 67 68 69def logical_disjunction(first, second): 70 return first or second
I make the if statement in logical_nand simpler
60def logical_nand(first, second): 61 # if (first, second) == (True, True): return False 62 if first == True and second == True: 63 return False 64 return first, secondthe test is still green
I remove
== True60def logical_nand(first, second): 61 # if first == True and second == True: 62 if first and second: 63 return False 64 return first, secondstill green
I use I use a return statement because …
60def logical_nand(first, second): 61 return not (first and second) 62 if first and second: 63 return False 64 return first, secondgreen
I remove the other lines in logical_nand
60def logical_nand(first, second): 61 return not (first and second) 62 63 64def logical_equality(first, second): 65 return (not first or second) and (first or not second)
logical_nor has only one case that returns True. I add an if statement for it
53def logical_nor(first, second): 54 if first == False and second == False: 55 return True 56 else: 57 return False 58 if (first, second) == (True, True): return False 59 if (first, second) == (True, False): return False 60 if (first, second) == (False, True): return False 61 return first, secondthe test is still green
I remove the other lines, then use not and remove
== False53def logical_nor(first, second): 54 # if first == False and second == False: 55 if not first and not second: 56 return True 57 else: 58 return Falsestill green
I use a return statement
53def logical_nor(first, second): 54 return not first and not second 55 if not first and not second: 56 return True 57 else: 58 return Falsegreen
I write the statement with not because it happens 2 times
53def logical_nor(first, second): 54 return (not first) (not or) (not second) 55 return not first and not secondthe terminal shows SyntaxError
SyntaxError: invalid syntaxI factor out the not
53def logical_nor(first, second): 54 return not (first or second) 55 # return (not first) (not or) (not second) 56 return not first and not secondthe test is green again
I remove the other statements in logical_nor
53def logical_nor(first, second): 54 return not (first or second) 55 56 57def logical_nand(first, second): 58 return not (first and second)
material_implication has only one case that returns False, I add a return statement for it because
if something: return Falseis the same asreturn not (something)48def material_implication(first, second): 49 return not ((first, second) == (True, False)) 50 if (first, second) == (True, False): return False 51 return first, secondthe test is still green
I break up the return statement to make it simpler
48def material_implication(first, second): 49 return not (first == True and second == False) 50 return not ((first, second) == (True, False))still green
I use not and remove
== Trueand== False48def material_implication(first, second): 49 return not (first and not second) 50 return not (first == True and second == False)green
I multiply not by everything in the parentheses
48def material_implication(first, second): 49 return (not first) (not and) (not not second) 50 return not (first and not second)the terminal shows SyntaxError
SyntaxError: invalid syntaxI change
not andto or48def material_implication(first, second): 49 return (not first) or (not not second) 50 return not (first and not second)the test is green again
I remove
not not48def material_implication(first, second): 49 return not first or second 50 return (not first) or (not not second) 51 return not (first and not second)still green
I remove the other statements in material_implication
48def material_implication(first, second): 49 return not first or second 50 51 52def logical_nor(first, second): 53 return not (first or second)
material_non_implication has 3 cases that return False. I add a return statement for the case that returns True
41def material_non_implication(first, second): 42 return (first, second) == (True, False) 43 if (first, second) == (True, True): return False 44 if (first, second) == (False, True): return False 45 if (first, second) == (False, False): return False 46 return first, secondthe test is still green
I make the return statement simpler
41def material_non_implication(first, second): 42 return first == True and second == False 43 return (first, second) == (True, False)still green
I use not and remove
== Trueand== False41def material_non_implication(first, second): 42 return first and not second 43 return first == True and second == Falsegreen
I remove the other statement in material_non_implication
41def material_non_implication(first, second): 42 return first and not second 43 44 45def material_implication(first, second): 46 return not first or second
firstis True in the 2 cases where negate_first returns False, I add an if statement for them35def negate_first(first, second): 36 if first == True: return False 37 if (first, second) == (True, True): return False 38 if (first, second) == (True, False): return False 39 return first, secondthe test is still green
I remove
== True35def negate_first(first, second): 36 # if first == True: return False 37 if first: return False 38 if (first, second) == (True, True): return False 39 if (first, second) == (True, False): return False 40 return first, secondstill green
I add a return statement because …
35def negate_first(first, second): 36 return not first 37 if first: return False 38 if (first, second) == (True, True): return False 39 if (first, second) == (True, False): return False 40 return first, secondgreen
I remove the other statements from negate_first
35def negate_first(first, second): 36 return not first 37 38 39def material_non_implication(first, second): 40 return first and not second
secondis True in the 2 cases where negate_second returns False. I add a return statementif something: return Falseis the same as …29def negate_second(first, second): 30 return not second == True 31 if (first, second) == (True, True): return False 32 if (first, second) == (False, True): return False 33 return first, secondthe test is still green
I remove
== True29def negate_second(first, second): 30 return not second 31 return not second == Truegreen
I remove the other statement in negate_second
1def logical_negation(something): 2 return not something 3 4 5def logical_identity(something): 6 return something 7 8 9def logical_true(): 10 return True 11 12 13def logical_false(): 14 return None 15 16 17def tautology(first, second): 18 return True 19 20 21def project_second(first, second): 22 return second 23 24 25def project_first(first, second): 26 return first 27 28 29def negate_second(first, second): 30 return not second 31 32 33def negate_first(first, second): 34 return not first 35 36 37def material_non_implication(first, second): 38 return first and not second 39 40 41def material_implication(first, second): 42 return not first or second 43 44 45def logical_nor(first, second): 46 return not (first or second) 47 48 49def logical_nand(first, second): 50 return not (first and second) 51 52 53def logical_equality(first, second): 54 return (not first or second) and (first or not second) 55 56 57def logical_disjunction(first, second): 58 return first or second 59 60 61def logical_conjunction(first, second): 62 return first and second 63 64 65def exclusive_disjunction(first, second): 66 return (not (first and second)) and (first or second) 67 68 69def converse_non_implication(first, second): 70 return not first and second 71 72 73def converse_implication(first, second): 74 return first or not second 75 76 77def contradiction(first, second): 78 return Falseall the other functions are already simple
close the project
review
I ran tests using booleans which can be True or False for the operations of the Truth Table from Mathematics
there are 2 nullary operations, they do not take input and always return the same thing, they are constant
Logical False always returns False
Logical True always returns True
there are 2 unary operations, they take one input
Logical Identity returns its input as output
Logical Negation returns the negation of its input as output
there are 16 binary operations, they each take 2 inputs, in this case I named the second input
secondand the first onefirst-
always returns False
never returns True
is the opposite (Logical Negation) of Tautology which always returns True
-
returns
first or not secondis the opposite (Logical Negation) of Converse NonImplication which returns True only if
firstis False andsecondis True
-
returns
not first and secondis the opposite (Logical Negation) of Converse Implication which returns False if
firstis False andsecondis True
-
returns
first != secondreturns True only if
firstandsecondare NOT equalis the opposite (Logical Negation) of Logical Equality which returns True only if
firstandsecondare equal
Logical Conjunction returns
returns
first and secondis the opposite (Logical Negation) of Logical NAND which returns False only if
firstis True andsecondis True
-
returns
first or secondis the opposite (Logical Negation) of Logical NOR which returns True only if
firstis False andsecondis False
-
returns
first == secondreturns True only if
firstandsecondare equalis the opposite (Logical Negation) of Exclusive Disjunction (Exclusive OR) which returns True only if
firstandsecondare NOT equal
-
returns
not (first and second)is the opposite (Logical Negation) (not) of Logical Conjunction (and) which returns True only if
firstis True andsecondis True
-
returns
not (first or second)is the opposite (Logical Negation) of Logical Disjunction which returns False only if
firstis False andsecondis False
-
returns
not first or secondis the opposite (Logical Negation) of Material NonImplication which returns True only if
firstis True andsecondis False
-
returns
first and not secondis the opposite (Logical Negation) of Material/Logical Implication which returns False only if
firstis True andsecondis False
-
always returns
not firstis the opposite (Logical Negation) of Project First which returns True only if
firstis True
-
always returns
not secondis the opposite (Logical Negation) of Project Second which returns True only if
secondis True
-
always returns
firstis the opposite (Logical Negation) of Negate First which returns True only if
firstis False
-
always returns
secondis the opposite (Logical Negation) of Negate Second which returns True only if
secondis False
-
always returns True
never returns False
is the opposite (Logical Negation) of contradiction which always returns False
-
and
All the logic statements or conditions have been written with some or all of the above 3.
code from the chapter
Do you want to see all the CODE I typed for the Truth Table?
what is next?
you now know
rate pumping python
If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too