{"id":61507,"date":"2023-12-01T18:16:37","date_gmt":"2023-12-01T23:16:37","guid":{"rendered":"https:\/\/languagelog.ldc.upenn.edu\/nll\/?p=61507"},"modified":"2023-12-01T18:16:37","modified_gmt":"2023-12-01T23:16:37","slug":"implementing-pa%e1%b9%87inis-grammar","status":"publish","type":"post","link":"https:\/\/languagelog.ldc.upenn.edu\/nll\/?p=61507","title":{"rendered":"Implementing P\u0101\u1e47ini's grammar"},"content":{"rendered":"<p>[Here's the conclusion to the hoped for trifecta on things Indian &#8212; see the preface <a href=\"https:\/\/languagelog.ldc.upenn.edu\/nll\/?p=61486\">here<\/a>.\u00a0 It comes in the form of a guest post by Arun Prasad]<\/p>\r\n<div>The cornerstone of traditional Sanskrit grammar is\u00a0P\u0101\u1e47ini's <i>A\u1e63\u1e6d\u0101dhy\u0101y\u012b<\/i>, which in around 4,000 short rules defines a comprehensive system for generating valid Sanskrit expressions. It continues to prompt vigorous discussion to this today, some of which has featured in Language Log <a href=\"https:\/\/languagelog.ldc.upenn.edu\/nll\/?p=57378\">before<\/a>.<\/div>\r\n<div>\u00a0<\/div>\r\n<div>As a professional software engineer and amateur Sanskritist, my lens is more pragmatic: if we could implement the <i>A\u1e63\u1e6d\u0101dhy\u0101y\u012b <\/i>in code and generate an exhaustive list of Sanskrit words, we could create incredibly valuable tools for Sanskrit students and scholars.<\/div>\r\n<div>\u00a0<\/div>\r\n<div>To that end, I have implemented just over 2,000 of the\u00a0<i>A\u1e63\u1e6d\u0101dhy\u0101y\u012b<\/i>'s rules in code, with an online demo <a href=\"https:\/\/ambuda-org.github.io\/vidyullekha\/\">here<\/a>. These rules span all major sections of the text that pertain to morphology, including: derivation of verbs, nominals, secondary roots, primary nominal bases, and secondary nominal bases; compounding; accent; and sandhi.<\/div>\r\n<p><!--more--><\/p>\r\n<div>Implementing P\u0101\u1e47ini's grammar in code is an obvious idea, but actually doing so is challenging for several reasons.<\/div>\r\n<div>\u00a0<\/div>\r\n<div>The first is that a core difficulty of using the grammar is in how the user decides which rule to apply next in the derivation. I wish to make clear that I've avoided this critical point of theory by manually ordering rules in whatever way would produce valid output, which is why I say that I'm <i>implementing<\/i> P\u0101\u1e47ini's grammar and not <i>simulating<\/i> it. One consolation of this approach is that the resulting program is much simpler and much faster.<\/div>\r\n<div>\u00a0<\/div>\r\n<div>The second is that it is not always obvious (to amateurs like me, anyway) which outputs are correct and which are not. Thankfully, the traditional grammatical literature comments meticulously on each rule in the grammar and provides extensive examples and counterexamples. These examples become our <i>unit tests<\/i> and <i>integration tests<\/i> to help check for program correctness.<\/div>\r\n<div>\u00a0<\/div>\r\n<div>The third is that the <i>A\u1e63\u1e6d\u0101dhy\u0101y\u012b<\/i>'s rules are deeply interconnected, such that an innocuous change in one part of the grammar can have major effects elsewhere. This is where the main merits of a fast program reveal themselves: a faster program can be checked against more examples than slower programs, which means that software bugs can be found more easily and more cheaply. This extensive test suite also means that if we wish to change a certain design decision in the overall program, we can do so with assurance that the overall system will not break.<\/div>\r\n<div>\u00a0<\/div>\r\n<div>A journey through the\u00a0<i>A\u1e63\u1e6d\u0101dhy\u0101y\u012b <\/i>at this minute level has been a great joy (as long as I'm not stuck on a strange bug). P\u0101\u1e47ini's grammar is meticulous and exhaustive, and it's a rich source of information on the Sanskrit idiom of the time, both in the rules themselves and in the commentary upon them. I've also become increasingly humbled at the thought of those pandits who are in full command of the rules of the grammar.<\/div>\r\n<div>\u00a0<\/div>\r\n<div>In the long term, I hope that this program will become \"morphologically complete\" and generate all valid word forms that the grammar allows. In addition to its pedagogical value, I believe such a program could become an invaluable tool for anyone who wishes to further explore P\u0101\u1e47ini's wondrous system.<\/div>\r\n<p>Since this is Language Log and not Software Slog, I've kept the implementation details light. But I'll briefly say that this is a Rust project with bindings to WebAssembly and Python. The code is free and open-source, and it can be found on GitHub <a href=\"https:\/\/github.com\/ambuda-org\/vidyut\/tree\/main\/vidyut-prakriya\">here<\/a>.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><b>Selected readings<\/b><\/p>\r\n<ul>\r\n<li>\"<a title=\"Permanent link to Sanskrit is far from extinct\" href=\"https:\/\/languagelog.ldc.upenn.edu\/nll\/?p=61486\" rel=\"bookmark\">Sanskrit is far from extinct<\/a>\" (11\/29\/23)<\/li>\r\n<li>\"<a title=\"Permanent link to Spelling and intuition\" href=\"https:\/\/languagelog.ldc.upenn.edu\/nll\/?p=61499\" rel=\"bookmark\">Spelling and intuition<\/a>\" (11\/30\/23)<\/li>\r\n<li>\"<a title=\"Permanent link to \" href=\"https:\/\/languagelog.ldc.upenn.edu\/nll\/?p=57378\" rel=\"bookmark\">'In P\u0101\u1e47ini We Trust'<\/a>\" (12\/15\/22)<\/li>\r\n<\/ul>\r\n","protected":false},"excerpt":{"rendered":"<p>[Here's the conclusion to the hoped for trifecta on things Indian &#8212; see the preface here.\u00a0 It comes in the form of a guest post by Arun Prasad] The cornerstone of traditional Sanskrit grammar is\u00a0P\u0101\u1e47ini's A\u1e63\u1e6d\u0101dhy\u0101y\u012b, which in around 4,000 short rules defines a comprehensive system for generating valid Sanskrit expressions. It continues to prompt [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[60,199,196,51],"tags":[],"class_list":["post-61507","post","type-post","status-publish","format-standard","hentry","category-computational-linguistics","category-grammar","category-language-and-computers","category-morphology"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=\/wp\/v2\/posts\/61507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=61507"}],"version-history":[{"count":4,"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=\/wp\/v2\/posts\/61507\/revisions"}],"predecessor-version":[{"id":61515,"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=\/wp\/v2\/posts\/61507\/revisions\/61515"}],"wp:attachment":[{"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=61507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=61507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/languagelog.ldc.upenn.edu\/nll\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=61507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}