Tamil grammar in silicon

Part 1 · Nouns as verses, and one bit operation

Tamil has had written grammars for about two thousand years, and I've wondered how precise they are. Precise enough to run on a chip? I'm finding out, starting with nouns.

Take one word, மரம், a tree. It turns into மரத்தில், மரங்கள், மரத்துக்கு and thirty more. That spread is its declension: each case takes its own ending, in singular and plural, and many endings come in variants. Can a chip compute them all straight from the grammar, storing nothing?

Why a lookup table is the problem

ThamizhiMorph, the open analyser I compare against, covers about 44,000 noun stems, roughly 1.5 million stem-and-case slots. Its lexicon spells out 1,609 suffix endings, since a suffix changes shape with the sound before it. The plural alone is written six ways. That is a lookup table, and I'd like the chip to need none.

My bet is that the table was never data. The grammarians wrote the rules down as verses, and these forms can be derived from them axiomatically.

Axiom one: place of articulation

Axiom one, Tolkāppiyam, பிறப்பியல், verses 7 to 9:

ககார ஙகாரம் முதல் நா அண்ணம்.
சகார ஞகாரம் இடை நா அண்ணம்.
டகார ணகாரம் நுனி நா அண்ணம்.

Each pairs a consonant with its nasal at one place in the mouth. I read that as a field layout and built an encoding on it that I call TLP1 (Tamil Linear Phonemic): one byte per sound, place of articulation in the bottom three bits, in the traditional order these verses open. க் is 0x40 and ங் is 0x50: same place bits.

மரம் + கள் → மரங்கள் is then a computation. In TLP1, ம் is 0x54 and க் is 0x40, and the bottom three bits are the place. 7 is binary 111, a mask for exactly those three bits. ~7 flips every bit of it, giving 11111000, a mask for everything except the place. Clear the nasal's place with & ~7, take the next consonant's place with & 7, and combine them with an OR: (0x54 & ~7) | (0x40 & 7) = 0x50, which is ங். Two masks and an OR. For ச் instead of க், the same expression gives 0x51, which is ஞ்.

The bits of ம், க் and the result ங்: the class bits come from ம், the place bits from க்
The bits of ம், க் and the result ங்: the class bits come from ம், the place bits from க் Open full size

Axiom two: ல் and ள்

Axiom two, Naṉṉūl 227:

ல ள வேற்றுமையில் ற டவும் அல்வழி
அவற்றோடு உறழ்வும் வலிவரினாம் மெலி
மேவின் ன ணவும் இடைவரின் இயல்பும்
ஆகும் இருவழியானும் என்ப

In case joins, when a hard consonant follows, ல் and ள் become ற் and ட். In அல்வழி joins the original and changed forms can alternate. Before a nasal, they become ன் and ண்; before ய், ர், ல், வ், ழ் or ள், they remain unchanged. They sit at the same place bits as the sounds they become, so கல் + கள் → கற்கள் (கல்கள் also stands) is "keep the place bits, change the class bits". In TLP1, ல் is 0x65, and (0x65 & 7) | 0x40 = 0x45, which is ற். The & 7 keeps the place, and 0x40 supplies the hard-consonant class.

A request

Before part two, a request. If you know Tolkāppiyam or Naṉṉūl, or work on Tamil computation, please check that I've read these verses correctly and that the bit operations follow from them. Everything is at github.com/Ramaseshanr/tamil-grammar-silicon, and I would rather be corrected now.

Part two: how a stem meets its ending, and what is actually on the chip.