def timeCounterfactualsOfHigherComplexity(n = 1):
	letters = ["p", "q", "r", "s"]
	connectives = ["~", ">", "&", "|"]
	# begin the universe
	S = init(letters)
	# choose a formula, update with it as a law
	S = updateLaw(S, randomClassicalFormula(n))
	# choose a formula, update it normally
	S = updateFormula(S, randomClassicalFormula(n))
	# "If it had been the case that \psi" is a retraction of ~\psi then update with \psi
	S = ifItHadBeenTheCase(S, randomClassicalFormula(n))
def test():
    language = ["p", "q", "r", "s"]
    s0 = worldgen(language)
    s1 = updateFormula(s0, "r")
    s2 = updateLaw(s1, "(r)>((p)|(q))")
    situation = {"p": True}
    # pprint("Result 1:")
    # pprint(Forceable(situation, [s2[5][meta][name], s2[4][meta][name], s2[6][meta][name], s2[7][meta][name]], s2))
    # pprint("Result 2:")
    # pprint(Forceable(situation, ["w_5", "w_4", "w_6", "w_7"], s2))
    w0 = {meta: {name: "w0", FS: True, US: True}, values: {"p": True, "q": False, "r": False, "s": True}}
    w1 = {meta: {name: "w1", FS: True, US: True}, values: {"p": False, "q": True, "r": False, "s": False}}
    w2 = {meta: {name: "w2", FS: True, US: True}, values: {"p": False, "q": False, "r": True, "s": True}}
    cogstate = [w0, w1, w2]
    pprint(getAllBases(w0, cogstate))
def checkRandomImplication(cogstate):
  	# generate a random law and update with it:
	law="("+choice(alphabet)+")>("+choice(alphabet)+")"
	#print "  updating with the law "+law
	cogstate = updateLaw(cogstate,law)

	# generate a random fact and update with it:
	fact=choice(alphabet)
	#print "  updating with the fact "+fact
	cogstate = updateFormula(cogstate,fact)

	# generate a random non-trivial implication and check it:
	imantecedent=choice(alphabet)
	restralph=list(alphabet)
	restralph.remove(imantecedent)
	imconsequent=choice(restralph)
	#print "  checking the implication "imantecedent+"->"imconsequent+":"
	cogstateNew = updateLaw(cogstate, imantecedent)
	result = supports(cogstateNew,imconsequent)
def checkRandomCounterfactual(cogstate):
	# generate a random law and update with it:
	law="("+choice(alphabet)+")>("+choice(alphabet)+")"
	#print "  updating with the law "+law
	cogstate = updateLaw(cogstate,law)

	# generate a random fact and update with it:
	fact=choice(alphabet)
	#print "  updating with the fact "+fact
	cogstate = updateFormula(cogstate,fact)

	# generate a random non-trivial counterfactual and check it:
	cfantecedent=choice(alphabet)
	restralph=list(alphabet)
	restralph.remove(cfantecedent)
	cfconsequent=choice(restralph)
	#print "  checking the counterfactual "+cfantecedent+"~>"+cfconsequent+":"
	cogstateNew = ifItHadBeenTheCase(cogstate, cfantecedent)
	result=supports(cogstateNew,cfconsequent)
from subprocess import call
from texoutput import *

# Start the tex file
out = texheader("Hansson's Hamburger puzzle", "The Factual Counterfactual Counter")

# Need propositional letters for "seeing a man walking with a hamburger",
# "snackbar A is open" and "snackbar B is open".
alphabet = ["p", "q", "r"]

# Now we generate the universe
W = worldgen(alphabet)
out += texify(W)

# Update with the fact that we see the man
W = updateFormula(W, "r")
out += texify(W)

# Update with the law that if we see a man with a hamburger, he must have
# got it at one of the snackbars
W = updateLaw(W, "(r)>((p)|(q))")
out += texify(W)

# Update since we see A is open
W = updateFormula(W, "p")
out += texify(W)

# Compute the counterfactual
W = ifItHadBeenTheCase(W, "~(p)")
out += texify(W)