A mathematical explanation of creativity