A zairja (Arabic: زايرجة; also transcribed as zairjah, zairajah, zairdja, zairadja, and zayirga) was a device used by medieval Arab astrologers to generate ideas by mechanical means. The name may derive from a mixture of the Persian words zaicha ("horoscope; astronomical table") and daira ("circle").
Ibn Khaldun described it as: "a branch of the science of letter magic, practiced among the authorities on letter magic, is the technique of finding out answers from questions by means of connections existing between the letters of the expressions used in the question. They imagine that these connections can form the basis for knowing the future happenings they want to know." He suggests that rather than being supernatural it works "from an agreement in the wording of question and answer ... with the help of the technique called the technique of 'breaking down'" (i.e. algebra). By combining number values associated with the letters and categories, new paths of insight and thought were created.
According to Ibn Khaldun the most detailed treatment of it is a pseudographical work "Za'irajah of the World" attributed to as-Sabti, which contains operating instructions in hundreds of lines of verse, beginning:
Select a star rise. Figure out its signs.
Reverse its root. Straighten it out with the cycle.
Someone will perceive those things. He will achieve his purpose
And be given their letters in whose arrangement the evidence lies...
A manuscript in Rabat recounts Ibn Khaldun's introduction to the machine by Al-Marjānī in 1370 (772 AH), and claims that it was a traditional and ancient science. When Ibn Khaldun expressed skepticism, the pair asked the instrument how old it was, and was told by the machine it was invented by the prophet Idris (identified with the Biblical Enoch).
It has been suggested that Catalan-Majorcan mystic, Ramon Llull in his travels and studies of Arab culture, became familiar with the zairja, and used it as a prototype for his invention of the Ars Magna.
In "Scrambling T-R-U-T-H: Rotating Letters as a Material Form of Thought", David Link provides a clear description and a full history of the device with a representation of the Arabic letters involved.
- Ibn Khaldūn. 1958 The Muqaddimah: An introduction to history. Translated from the Arabic by Franz Rosenthal. 3 vols. New York: Princeton. Chapter 6 section 28
- Charles Lohr (1984) Christianus arabicus, cuius nomen Raimundus Lullus. Freiburger Zeitschrift für Philosophie und Theologie 31 [1–2]: 57– 88
- Dominique Urvoy (1990) La place de Ramon Llull dans la pensée Arabe. Catalan Review. International Journal of Catalan Culture 4 [1–2]: 201–220
- D. Urvoy (1980) Penser l’Islam. Les présupposés Islamiques de l’“art” de Llull, Paris, 1980
- Armand Llinares (1980), References et influences Arabes dans le Libre de contemplacio. Estudios Lulianos 24 
- Mind as Mosaic, The Robot in the Machine, Bruce H. Hinrichs, pp. 196–197