Logic Code

#!/usr/bin/python

def disjunct(p,q): #if pnand q are different the disjunct is true, else it is false.

print(“Disjunct: P = “,p, ” Q = “,q)

if p == 1 and q == 0:

dis = “(T)”

elif p == 0 and q == 1:

dis = “(T)”

else:

dis = “(F)”

print(“P v Q “,dis)

def conjunct(p,q): # if p and q both obtain the conjunct is true.

print(“Conjunct: P = “,p, ” Q = “,q)

if p == 1 and q == 1:

con = “(T)”

else:

con = “(F)”

print(“P & Q”,con)

def absorb(q1,r,s): # trsts for continuity between q r and s.

print(“”)

print(“Absorbtion: Q = “, q1,”R = “, r,” S = “,s)

if q1 == r:

qr = “(T)”

else:

qr = “(F)”

if r == s:

rs = “(T)”

else:

rs = “(F)”

if q1 == r and r == s:

qs = “(T)”

else:

qs = “(F)”

print(“”)

print(“Q => R “,qr)

print(“R => S “,rs)

print(“Q => S “,qs)

def syll(p,q): # uses the rules of modus ponens and tollens. if p obtains q is generated. if q is absent, p is false.

print(“”)

print(“Syllogism: P = “, p,” Q = “,q)

print(“”)

print(“P => Q”)

if p == 1 and q == 1:

r1 = “Therefore P”

elif p == 1 and q == 0:

r1 = “~P”

if q == 0: # denying consequent

print(“~Q”)

r1 = “Therefore ~P”

elif p == 1: # affirming antecedent

r1 = “Therefore Q”

print(“P = (T)”)

if p == 0:

r1 = “Therefore ~Q”

print(“~P”)

print(r1)

def main():

p = 1 # toggle these variables to vary results.

q = 1

q1 = 1 # separate variables for q and q1. run individually

r = 1

s = 0

disjunct(p, q)

conjunct(p,q)

syll(p,q)

if q1 == 1 or r == 1 or s == 1: # absorption block

absorb(q1,r,s) # will only call absorbtion if these variables have a value.

main()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s