Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download
Views: 24
Kernel: Python 2 (SageMath)

Please copy this code into your own CoCalc notebook so that you can work with it independently.

def implication(a,b): # returns a->b return (not a) or b def f(a,b,c): # returns (a or b)->c return implication(a or b, c) def g(a,b,c): # returns (a and b)->(c->a) return f(not a, not b, implication(c,a)) def printTruthTable(func): # This function prints truth tables for sentences in 3 variables # func is the function defining the desired sentence print 'abc|sentence' for a in [True,False]: for b in [True,False]: for c in [True,False]: print a, b, c, '|', func(a,b,c) # Main body print 'Truth table for (a or b)->c' print printTruthTable(f) print 'Truth table for (a and b)->(c->a)' print printTruthTable(g)
Truth table for (a or b)->c abc|sentence True True True | True True True False | False True False True | True True False False | False False True True | True False True False | False False False True | True False False False | True None Truth table for (a and b)->(c->a) abc|sentence True True True | True True True False | True True False True | True True False False | True False True True | False False True False | True False False True | False False False False | True None