The mind as a state machine