""" Hard-problem agent by Brian Tomasik switched to Python 3 syntax and more thoroughly commented by Luke Muehlhauser For explanation and a sample run of the original code, see http://www.utilitarian-essays.com/agent-to-illustrate-hard-problem.html Most of the program defines functions and classes. Scroll to the bottom to see where the program actually "starts." """ import random # needed for generating random numbers class HardProblemAgent(): # This section defines the functions and variables called at the end of the script. def __init__(self): # This is what happens when an object of class HardProblemAgent, e.g. "Hardy" (see below), is created. print("Hi there.") # Hardy introduces himself self.currentNeuralPattern = '' # Initializing two variables. They begin with empty values. self.currentColor = '' def LookAtObject(self, wavelength): # Ignore the "self" bit in all these functions; it's a Python syntax thing. print("") print("I'm going to look at an object.") print("(Wavelength = %d.)" % wavelength) # Prints the light wavelength randomly generated near the end of the script. # Convert the wavelength value into binary, Tomasik's stand-in for a (not-human-interpretable) neural firing pattern: self.currentNeuralPattern = self.LightToNeuralPattern(wavelength) # Figure out which pre-stored word Hardy uses for talking about this kind of neural firing pattern: self.currentColor = self.NeuralPatternToWord(self.currentNeuralPattern) # Hardy says what color he sees, using the pre-stored word identified from the previous function: self.ReportSeenColor(self.currentColor) # Hardy reports some pre-stored associations he has with that color, e.g. that red is associated with firetrucks self.ReportColorAssociation(self.currentNeuralPattern) # These next several functions are the ones called above. They're pretty straightforward. def LightToNeuralPattern(self, wavelength): if wavelength >= 620 and wavelength <= 750: # red return '00' elif wavelength >= 495 and wavelength <= 570: # green ("elif" is short for "else if") return '01' elif wavelength >= 450 and wavelength < 495: # blue return '10' elif wavelength >= 380 and wavelength < 450: # purple return '11' else: return '' def NeuralPatternToWord(self, pattern): if pattern is '00': return 'red' if pattern is '01': return 'green' elif pattern is '10': return 'blue' elif pattern is '11': return 'purple' else: return 'invisible' def NeuralPatternToAssociation(self, pattern): if pattern is '00': # red return 'firetrucks' if pattern is '01': # green return 'grass' elif pattern is '10': # blue return 'ocean' elif pattern is '11': # purple return 'plums' else: return 'radio waves' def ReportSeenColor(self, colorWord): print("I see %s." % colorWord) def ReportColorAssociation(self, pattern): print("It reminds me of %s." % self.NeuralPatternToAssociation(pattern)) # This is the function called below after LookAtObject and the "sub-functions" defined above def AskHardProblem(self): print("") if self.currentColor != 'invisible': print("Cool. Now, let me see if it feels like something to see %s." % self.currentColor) print("Does it feel like something to see %s?" % self.currentColor) # Answer is yes or no; see QueryMyselfAboutQualia, below print("Answer: %s" % self.QueryMyselfAboutQualia(self.currentNeuralPattern)) print("Ok, but *why* does it feel like something to see %s?" % self.currentColor) print("This seems completely unexplained. It's clear that my brain can perceive colors, but why, when I ask myself whether there's something it feels like to perceive these inputs, do I realize that yes, there is something it's like? Hmm. Off to read more David Chalmers, I guess.") else: print("I don't see a color. Sorry.") def QueryMyselfAboutQualia(self, pattern): # Does it feel like something to have this pattern? The answer is always 'yes', because all of the following are true: # 1. There was a stimulus that provoked QueryMyselfAboutQualia in the first place, i.e. a light wavelength between 380nm and 750nm, and # 2. Whenever you're querying yourself, "thinking is happening", and # 3. Hardy's brain is telling him that the stimulus belongs to him (unless he's got a certain kind of brain damage) itFeelsLikeSomething = self.PerceivingAStimulus(pattern) and self.ThinkingGoingOn() and self.ItBelongsToMe() if itFeelsLikeSomething: return "yes" else: return "no" def PerceivingAStimulus(self, pattern): return pattern != '' # This just means "return True so long as their is any pattern/stimulus" def ThinkingGoingOn(self): return True def ItBelongsToMe(self): return True # This is where the program "starts" # Python's way of saying "Do the following, but only if this program was run directly rather than being called by another script": if __name__ == '__main__': Hardy = HardProblemAgent() # Hardy is an object of class HardProblemAgent lightWavelength = random.randrange(380, 750) # Generate a random light wavelength # This is the first thing the program "does" besides merely defining classes, objects, and variables: Hardy.LookAtObject(lightWavelength) # See above for how the LookAtObject function works Hardy.AskHardProblem() # See above for how the AskHardProblem function works