In Welsh mythology, Math fab Mathonwy (Welsh pronunciation: [ˈmaːθ ˈvaːb maˈθɔnʊɨ]), also called Math ap Mathonwy (Math, son of Mathonwy) was a king of Gwynedd who needed to rest his feet in the lap of a virgin unless he was at war, or he would die. The story of Math is the fourth of the Four Branches of the Mabinogi.
Math's nephew Gilfaethwy had become obsessed with Goewin, Math's footholder. The magician Gwydion (Gilfaethwy's brother), devised a plan to make Goewin available. Gwydion told his uncle about an animal that was new to Wales, called pigs, and how he could get them from their owner, Pryderi of Dyfed. He took a band of men, including his brother, to Ceredigion, where they disguised themselves as bards to gain audience with King Pryderi.
Gwydion was a skilled cyfarwydd (storyteller) and regaled the court with his tales. Having charmed the king, he offered to trade the pigs for some horses and dogs, which he had conjured through magic. Pryderi agreed to the trade and Gwydion and his men took the pigs back home to Gwynedd, but his trickery was revealed and Pryderi waged war against Gwynedd. While Math went to battle, Gilfaethwy raped Goewin.
The war ended when Gwydion killed Pryderi in single combat. Upon his return to his castle, King Math went to rest his feet in Goewin's lap, but could not, as she was no longer a virgin. He took her as his wife to save her honour, and then as punishment, banished his nephews, turning them into a breeding pair of deer for a year. He then turned them into wild boars for the next year and wolves the year after that. They had three children over the three years: Hyddwn, Hychddwn, and Bleiddwn.
After their punishment was over, Math asked their advice as to who should be his next virgin foot-holder. Gwydion suggested his sister, Arianrhod. However, Arianrhod was not a virgin, and when asked to step over Math's rod in order to prove her virginity she immediately gave birth to a son. Abandoning the child she fled in shame, letting drop a "lump of flesh" which was borne away by Gwydion and concealed in a chest. When Gwydion later opens the chest he discovered the lump of flesh to be a second child.