简体   繁体   中英

inconsistent formulaes in the list python

So the question relates to List of lists that store different propositional modal formulaes. I am capable of removing duplicates but I don't know how to find inconsistances. So for example:

Initial List of lists:

[[('not', ('box', 'p')), ('box', 'p'), ('not', 'q'), ('q'), ('diamond', 'r')],
 [('not', 'p'), 'q'], ['or', ('p', 'q')],
 ['not',('or', ('p', 'q'))],['r', 'q']]

The above sample list of lists has some problems I would like to simply find them and print out a message. For example 1st list has box p and negated box p I would like it to be detected. Also it has not q and q .

Similarly, 2nd list has not (p or q) and (p or q) . Can anyone suggest a solution to this problem, it could be something easy but I don't seem to be able to think of it.

Ideally, is it possible to mark a sublist as closed? Perhaps assign status closed?

This is the solution to the problem I presented in the question. Works correctly, in case someone can improve it or make it shorter (or faster) please do post your proposition.

def inconsistent(psi):
for i in range(0,len(psi)):
    for j in range(0,len(psi[i])):
        main = psi[i]
        form = psi[i][j]
        if form[0] == 'not':
            notform = form[1]
            if form and notform in main:
                print "inconsistent: ", psi[i][j]
        else:
            notform = ('not', psi[i][j])
            if form and notform in main:
                print "inconsistent: ", psi[i][j]
            else:
                print "consistent: ", psi[i][j]


test = [[('not', ('box', 'p')), ('box', 'p'), ('not', 'q'), ('q'), ('diamond', 'r')], [('or', ('p', 'q')),('not',('or',('p','q')))],['not',('or', ('p', 'q'))],['r', 'q']]

inconsistent(test);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM