def retractOnWorld(cogstate,worldname,proposition):
	"""
	INPUT: a triple (cognitive state, worldname, proposition)
	OUTPUT: array of worlds
	WHAT IT DOES: Definition 4 (i)
	"""
	result=[]
	world=getWorldByName(worldname,cogstate)
	for situation in sitgen(world): # s
		if Forceable(situation, proposition, cogstate):
			continue # s may not force P
		adding=False
		for basis in getAllBases(world,cogstate): # s'
			if not subset(situation,basis):
				continue # s is has to be a subset of s'
			Maximal=True
			for t in subsitgen(basis):
				if Forceable(situation, proposition, cogstate):
					continue # t may not force P
				if subset(situation,t):
					if situation != t:
						Maximal=False
			if not Maximal:
				continue # s should be a maximal subset of s'
			adding=True
		if adding:
			result.append(situation)
	return result
from propositions import propositionFromFormula
from counterfactual import ifItHadBeenTheCase

language = ['p','q','r']

s0 = worldgen(language)
s1=updateFormula(s0, "r")
s2=updateLaw(s1, "(r)>((p)|(q))")
s3=updateFormula(s1, "p")

print "\nThis is s3:"

print(texify(s3))

print "\nThe bases of w_7 in s3 are: "
pprint(getAllBases(getWorldByName("w_7",s3),s3))

prop=propositionFromFormula(s3,"p")

print "\nThe retraction of w_7 with [[p]] is:"
pprint(retractOnWorld(s3,"w_7",prop))

print "\nThe retraction of s3 with [[p]] is:"
s4=retractOnState(s3,prop)

pprint(s4)

print(texify(s4))

s5=ifItHadBeenTheCase(s3,"~(p)")