Ejemplo n.º 1
0
def simplifyMHAuto_improved(mhDict, sim):
    # An improved (but more complex) version of simplifyMHauto
    isLessMH_weak = (lambda M0, N0, M1, N1: Utilities.isSubList(M1, M0) and \
		     Utilities.isSubList(N1, N0))
    isLessMHspecial = (lambda x, y: (y[1] == ()) and sim.isLessMH(x, y))

    "If, given a state q, there are terms t0, t1 such that t1 \implies t0, \
     then delete those states from mhDict[q][t1] that are less \
     (wrt isLessMH_weak) than elements in mhDict[q][t0]."
    for q in mhDict.keys():
	for t0 in mhDict[q].keys():
	    for t1 in mhDict[q].keys():
		if oneTermImplies(t1, t0):
		    i = 0
		    while i < len(mhDict[q][t0]):
			j = 0
			while j < len(mhDict[q][t1]):
			    if (t0 != t1) or (i != j):
				(M0, N0) = mhDict[q][t0][i]
				(M1, N1) = mhDict[q][t1][j]
				if isLessMH_weak(M1, N1, M0, N0) or \
				   ((q[1] == ()) and sim.isLessMH((M1, N1), \
								  (M0, N0))) \
				   or ((q[1] != ()) and \
				       isLessMHspecial((M1, N1), (M0, N0))):
				    i = Utilities.deleteWithPointers(mhDict[q][t1], j, [i, j])[0]
				    j -= 1
			    j += 1
			i += 1
Ejemplo n.º 2
0
def simplifyMHAuto(mhDict, sim=None):
    # mhDict: Dictionary of (MHstate, Dictionary of (tuple(Term),
    #  List of MHstate)) mit MHstate: Pair of Tuple of State
    # sim: SimulationRelation
    "If for (M, N) and t in mhDict[(M, N)][t] there are states (M0, N0), \
     (M1, N1) s.t. M0 \subset M1 and N0 \subset N1, then delete (M1, N1) from \
     the successor list."
    for (M, N) in mhDict.keys():
        for t in mhDict[(M, N)].keys():
            i = 0
            while i < (len(mhDict[(M, N)][t]) - 1):
                j = i + 1
                while j < len(mhDict[(M, N)][t]):
                    (M0, N0) = mhDict[(M, N)][t][i]
                    (M1, N1) = mhDict[(M, N)][t][j]
                    if Utilities.isSubList(M0, M1) and \
                       Utilities.isSubList(N0, N1):
                        del mhDict[(M, N)][t][j]
                    elif Utilities.isSubList(M1, M0) and \
                         Utilities.isSubList(N1, N0):
                        del mhDict[(M, N)][t][i]
                    else:
                        j += 1
                i += 1

    "Accepting states only need maximal successors -- at this point, we use \
     the preorder defined by sim.isLessMH. Further, you may delete \
     non-maximal successors from non-accepting states in favor of greater \
     accepting successor states."
    if not (sim == None):
        
        def isLessMHspecial(x, y): # x, y: MHstate
            return (y[1] == ()) and sim.isLessMH(x, y)
            ## And not "(x[1] != () and y[1] == ()) and ...", cf. the examples
            ## FX((a | b) U (a & XGa)) and (a | b | c) U ( a & X((a | b) U (a & XGa))).
                
        for p in mhDict.keys():
            for t in mhDict[p].keys():
                if p[1] == (): # p is accepting
                    mhDict[p][t] = Utilities.maximalElements(mhDict[p][t], \
                                                             sim.isLessMH)
                else: # p is not accepting
                    mhDict[p][t] = Utilities.maximalElements(mhDict[p][t], \
                                                             isLessMHspecial)