Actually, in its heyday when Khayyam lived (11th-12th century), Islamic Persia wasn't all that pious and more or less tolerated heresy. That's what led to all its great discoveries -- they were on their way to having the Scientific Revolution before the West. It was the Black Plague in the 14th century that put an end to that.