Start New Discussion within our Software Development Community

Evaluation of formula G =((p→q) ^p)→q
and the output display the result of true false'
conclusion if it is a valid, invalid or inconsistent..
thank you for any response its a big help to my study

her's my unfinished code

import sys
p=[True,True,False,False]
q=[True,False,True,False]

a = [] 
 
def p_AND_q(p,q):
    print p,"\t", q, "\t", p and q
 
def AND(p,q):

    sys.stdout.write("p \t q");
    print "\t p and q"
    print "------------------------"
    j=0
    while(j < len(q)):
        p_AND_q(p[j],q[j])
        j = j+1
    print "Therefore formula is invalid"

Here is a way to program this using bitwise operations

def toi(ps):
    # convert to integer. Ex "0101" -> 6
    return int(ps, 2)

def tos(pi):
    # convert to string. Ex 6 -> "0101"
    assert(0 <= pi < 16)
    return bin(16 + pi)[-4:]

def and_(ps, qs):
    pi, qi = toi(ps), toi(qs)
    return tos(pi & qi)

def or_(ps, qs):
    pi, qi = toi(ps), toi(qs)
    return tos(pi | qi)

def xor(ps, qs):
    pi, qi = toi(ps), toi(qs)
    return tos(pi ^ qi)

def implies(ps, qs):
    return or_(not_(ps), qs)

def not_(ps):
    return tos(15 ^ toi(ps))

def G(ps, qs):
    return implies(xor(implies(ps, qs),ps), qs)

def main():
    ps = "0101"
    qs = "0011"

    assert( and_(ps, qs) == "0001")
    assert( or_(ps, qs) == "0111")
    assert( xor(ps, qs) == "0110")
    assert( implies(ps, qs) == "1011")
    assert( not_(ps) == "1010")
    print("G(%s, %s) = %s" % (repr(ps), repr(qs), repr(G(ps, qs))))

main()

""" my output --->
G('0101', '0011') = '0011'
"""

It seems that the value of your expression is q !

This article has been dead for over six months. Start a new discussion instead.