Pātuhitia tēnei: The hidden mathematical logic of stories