Hex is a fictional computer featuring in the Discworld novels by Terry Pratchett. First appearing in Soul Music, Hex is an elaborate, magic-powered and self-building computer (not unlike the 'shamble', a kind of magical device used by the Witches of the Discworld) and is housed in the basement of the High Energy Magic Building at the Unseen University (UU) in the twin city of Ankh-Morpork.
Hex is a computer unlike any other the Disc has ever seen, which is not particularly exceptional since previously all other "computers" on the Disc had consisted of druidic stone circles. Programmed via 'Softlore', Hex runs and evolves under the watchful eyes of wizard Ponder Stibbons, who becomes the de facto IT manager at UU because he's the only one who understands what he's talking about.
Hex has its origins in a device that briefly appeared in Soul Music, created by Ponder Stibbons and some student Wizards in the High Energy Magic building. In this form it was simply a complex network of glass tubes, containing ants. The wizards could then use punched cards to control which tubes the ants could crawl through, enabling it to perform simple mathematical functions.
By the time of the next novel, Interesting Times, Hex had become a lot more complex, and was constantly reinventing itself. Part of it is now clockwork, which interfaces with the ant-farm via a paternoster the ants can ride on that turns a significant cogwheel. Its main purposes were, in a sense, data compression and information retrieval: to analyse spells, to see if there were simpler "meta-spells" underlying them, and to help Stibbons with his study of "invisible writings" by running the spells used to bring the writings into existence. (These spells must be cast rapidly, and each one can only be used once before the universe notices they shouldn't work.)