astronomical observations and to support the Almohad project of building new colleges. He was hoping to find physical laws of astronomical movements instead of only the mathematical laws known at the time but this research was unsuccessful. During his stay in Marrakesh he likely met Ibn Tufayl, a renowned philosopher and the author of Hayy ibn Yaqdhan who was also the court physician in Marrakesh. Averroes and ibn Tufayl became friends despite the differences in their philosophies. In 1169 Ibn Tufayl introduced Averroes to the Almohad caliph Abu Yaqub Yusuf. In a famous account reported by historian Abdelwahid al-Marrakushi the caliph asked Averroes whether the heavens had existed since eternity or had a beginning. Knowing this question was controversial and worried a wrong answer could put him in danger, Averroes did not answer. The caliph then elaborated the views of Plato, Aristotle and Muslim philosophers on the topic and discussed them with Ibn Tufayl. This display of knowledge put Averroes at ease; Averroes then explained his own views on the subject, which impressed the caliph. Averroes was similarly impressed by Abu Yaqub and later said the caliph had "a profuseness of learning I did not suspect". After their introduction, Averroes remained in Abu Yaqub's favor until the caliph's death in 1184. When the caliph complained to Ibn Tufayl about the difficulty of understanding Aristotle's work, Ibn Tufayl recommended to the caliph that Averroes work on explaining it. This was the beginning of Averroes's massive commentaries on Aristotle; his first works on the subject were written in 1169. In the same year, Averroes was appointed qadi (judge) in Seville. In 1171 he became qadi in his hometown of Córdoba. As qadi he would decide cases and give fatwas (legal opinions) based on the Islamic law (sharia). The rate of his writing increased during this time despite other obligations and his travels within the Almohad empire. He also took the opportunity from his travels to conduct astronomical researches. Many of his works produced between 1169 and 1179 were dated in Seville rather than Córdoba. In 1179 he was again appointed qadi in Seville. In 1182 he succeeded his friend Ibn Tufayl as court physician and later the same year he was appointed the chief qadi of Córdoba, a prestigious office that had once been held by his grandfather. In 1184 Caliph Abu Yaqub died and was succeeded by Abu Yusuf Yaqub. Initially,