49
PANINI FOR IT PRO-S Vasu Srinivasan Samskrita Bharati

Panini for IT professionals

  • Upload
    vasya10

  • View
    638

  • Download
    5

Embed Size (px)

DESCRIPTION

Introduction to Panini's ashtadhyayi and his various schemes with comparison to modern programming concepts

Citation preview

Page 1: Panini for IT professionals

PANINI FOR IT PRO-S Vasu Srinivasan

Samskrita Bharati

Page 2: Panini for IT professionals

Audience You are a software programmer

You write code in atleast one programming language

You may or may not have written a sort() method, named after yourself

You know basics of programming concepts and theories

You may or may not be familiar with Samskritam, but may or may not know at least one Indian language

You are interested in learning Samskritam

but neither found time, resources nor patience

you got bored of watching kolaveri for 87th time and found time to watch this video

Page 3: Panini for IT professionals

About Software professional, working with computers since 8085 assembler

MS Computer Science, Russia

Twitter/Facebook: vasya10

Blogs:

vagartham.blogspot.com (samskritam)

vasya10.wordpress.com (technical)

Project: http://github.com/vasya10/samskritam-dsl

Samskrita Bharati USA volunteer since 2008

Page 4: Panini for IT professionals

What to expect?

First, as a programmer, you should have a broader interest in programming theories, instead of arguing about better languages or frameworks

Next, this presentation may kindle your latent interest in Samskritam, provide a different perspective of programming, re-align your interests and/or increase your scope of understanding languages in general

Above all, it may simply excite you for coming into contact with the thought process of someone who lived 2500+ years ago.

Page 5: Panini for IT professionals

PANINI An aphoristic introduction

Page 6: Panini for IT professionals

pANini – who, where, what, how?

He is not named after the Italian sandwich

The Italian sandwich is not named after him

Conclusion: He is neither a sandwich nor an Italian

He fits into what we likely call a “grammarian”

A grammarian is very unlike a librarian

You go to a librarian and ask for a new book

You do not go to a grammarian and ask for a new “word”

Page 7: Panini for IT professionals

pANini – who, where, what, how?

lived in gAndhAra (part of bhArata, but today’s Afghanistan) lived around 500 BC his other name is dAkShAyaNaH was killed by a tiger invented C before Dennis Ritchie did All of the above are speculations and inferences from other materials rather than his own admission. Some inferences are less accurate than others. Some speculations are actually wild unscientific guesses in the name of South East Asian studies, headed by people who pretend to know Samskritam.

Page 8: Panini for IT professionals

pANini – who, where, what, how?

pANini created a work called aShTAdhyAyI (8-Chapters)

This presentations aims to gloss over what he did and how his ideas are directly and indirectly applicable to modern programming theories

Serious aShTAdhyAyI and related studies could take a lifetime

Sometimes multiple lifetimes depending on your karma.

Page 9: Panini for IT professionals

pANini – who, where, what, how?

How did he “write” aShTAdhyAyI ?

Was there a script by his time?

Did people just memorize everything that he wrote?

There is no correct answer to any of the above

We are focusing on what he did, rather than how he did it

Page 10: Panini for IT professionals

The Script

Question

Why do you say “pANini” and not “Panini” ?

Answer

And that begins our journey into the fascinating world of aShTAdhyAyI…

Page 11: Panini for IT professionals

Pause and Think moment #1

Is Samskritam difficult?

Page 12: Panini for IT professionals

The world of phonetics – 1/3

In English, and in many western languages, the script (roman or latin) is tied to the language

You can hardly think of English without the letters A,B,C etc.

English is not a phonetic language. That is, script vs sound is always a variant

In other words, the alphabets you learn to pronounce is not necessarily what you pronounce to learn the words

Page 13: Panini for IT professionals

The world of phonetics – 2/3 Samskritam, on the other hand, is based on phonemes

Script (lipi) is only a means of expressing the sounds in written form: eg. devanAgarI is very popular script now

Few hundred years before, the granthA script was popular; in fact a lot of Samskritam works are found in granthA, telugu, kannada, malayalam, tulu and several North Indian scripts, like shArada and modi.

There are not enough alphabets in English to phonetically spell Samskritam

So scholars have come up schemes to map English alphabets cleverly to spell Samskritam words

Thus,

a = (short अ); A = (long आ) etc.

N = (ण) पाणणनि: = pANiniH

Page 14: Panini for IT professionals

The world of phonetics – 3/3

In Samskritam, any script is only a visual expression of the “predefined constant sound form”

In English, the pronunciation has to be memorized for each and every word, for each and every dialect and sometimes also based on a context

In Samskritam you have to learn only the sound forms

Once you learn a script, you can read any text ... …without any guess work

Page 15: Panini for IT professionals

Is Samskritam difficult?

To answer this, we must first agree to define difficult

In terms of learning how to pronounce, majority of the English words are case-by-case basis

(n-1) words of -tion are pronounced “-shun”.

bastion is not bashun, but bas-t-i-o-n

In Samskritam, you are productive about prounciation and reading from day 1

Not just you, it is easy to teach machines to pronounce words too

Page 16: Panini for IT professionals

So, what did pANini do?

Say True or False

discovered and/or invented Samskritam

is the first Samskritam grammarian

is the only grammarian

did not know about Vedas

ashTAdhyAyI is the only book he wrote

divided Samskritam into classical Samskritam and Vedic Samskritam

All are False

Page 17: Panini for IT professionals

what pANini actually did… described Samskritam as it was spoken in his times defined rules that allows to generate and validate Samskritam words and sentences covers the classic as well as vedic Samskritam was only a branch in a tree of Samskritam grammar tradition mentions about 10 predecessor/contemporary grammarians in his work a huge number of grammarians followed him, specifically classified as “pANinIyAH” = “belonging to pANini school” so much, that the elite say “apANinIyam na prayunjyete” (meaning, non-paninian constructs are prohibhited)

Page 18: Panini for IT professionals

Pause and Think moment #2

So Panini did this, Panini did that, whatever dude !

OK, Great!

What was the problem he was trying to solve ?

Page 19: Panini for IT professionals

The M’ dollar question

450 BCE, Greece

Archimedes, lying in his bathtub, was pondering the question

How to find the volume of an irregularly shaped object?

Page 20: Panini for IT professionals

The 10,00,000 dollar question

500 BCE (dates arbitrary), takshashila

Maharshi pANini, lying in his kusha grass, was pondering the question

How to generate an infinite number of sentences in a language using a finite set of formal rules?

Page 21: Panini for IT professionals

Panini’s work aShTAdhyAyI (8 chaptered)

unparalleled in terms of covering a grammar of a language comprehensively in so few rules (just 4000 rules)

left a legacy of grammarians from kAtyAyana (200 BCE) to nAgesha bhatta (1600 CE), including some of the greatest minds – patanjali, bhartruhari, bhattoji dikshita and more.

academicians, scholars still pondering over understanding pANini’s work in completeness

laid the basics of modern western linguistics (India had a very mature and refined linguistics field by the time bhartruhari itself ~ 600 CE)

influenced pretty much everything about classical Samskritam, including interpretation of upanishads, vedas etc by various aachaaryaa-s

so much influence, that we only “hear” about other grammar works, much less studied

Page 22: Panini for IT professionals

RULES AND SCHEMES Panini’s rules and schemes

Page 23: Panini for IT professionals

The Rules

If Panini wrote grammar for English

But

Cut

Gut

Hut

Nut

Rut

Rule: when u is followed by t, pronounce as a

except when preceded by p

Another example: i after e, except after c

Put

What about OUT?

Page 24: Panini for IT professionals

The Schemes - Introduction

In order to define a formal language, one has to define the “symbols” of the medium

In math, symbols like ∑,Ω, ∆, ∂, ∏ all mean something

In classical physics Ω means ohm, but in particle physics it is used for Omega baryons

In math, expressions like f(x), y(x), a2 mean something – no comprehendo scheme, no comprehendo nothing!

𝑥 + 𝑎 𝑛 = 𝑛

𝑘𝑥𝑘𝑎𝑛−𝑘

𝑛

𝑘=0

Page 25: Panini for IT professionals

Panini’s Schemes

A scheme, in Panini’s terms, is a set of algorithms applied to transform a source entity to a desired target entity

Panini has several innovative schemes to his credit

the first and one of the most strikingly brilliant schemes – is called mAheshvara sUtrANi

Page 26: Panini for IT professionals

Pause and Think moment #3

How did you all learn A,B,C?

How is A,B,C arranged?

Page 27: Panini for IT professionals

Scheme: mAheshvara sutrANi

IAST Devanāgarī

1. a i u ṇ

2. ṛ ḷ k

3. e o ṅ

4. ai au c

5. ha ya va ra ṭ

6. la ṇ

7. ña ma ṅa ṇa na ṃ

8. jha bha ñ

9. gha ḍha dha ṣ

10. ja ba ga ḍa da ś

11. kha pha cha ṭha tha ca ṭa ta v

12. ka pa y

13. śa ṣa sa ṛ

14. ha ḹ

१. अ इ उ ण | २. ऋ ऌ क | ३. ए ओ ङ | ४. ऐ औ च | ५. ह य व र ट | ६. ल ण | ७. ञ म ङ ण ि म | ८. झ भ ञ | ९. घ ढ ध ष | १०. ज ब ग ड द श | ११. ख फ छ ठ थ च ट त व | १२. क प य | १३. श ष स र | १४. ह ल |

Page 28: Panini for IT professionals

mAhesvara sUtrANi: Non-inclusive upper-bound sets

The last letter of each line is called ‘it’ (इत)

1. Cannot start a set with an (इत) letter

2. Start from any letter from any line

3. You can stop only at an (इत)

4. Skip all intermediate (इत) letters

5. For the “value-set”, skip that (इत) letter also

pANini’s 2 in-your-face rules for creating a set:

1. aadirantyena sahetA 2. tasya lopaH

Page 29: Panini for IT professionals

Examples of NIUB sets

• अण = अ इ उ ण • अक = अ इ उ ऋ ऌ क • इक = इ उ ऋ ऌ क • अच = अ इ उ ऋ ऌ ए ओ ऐ औ च

• हल = ह य व र ल ञ म ङ ण ि झ भ घ ढ ध ज ब ग ड द ख फ छ च ट त क प श स (ह) ल

• चय = च ट त क प य (the first vertical in क ख ग घ scheme)

• These are called pratyAhAra

Page 30: Panini for IT professionals

Scheme: Types of Aphorisms (sUtram)

Six types of sUtram

Definition (samjna)

Interpreting (paribhASha)

Rule (vidhiH)

Restriction (niyama)

Extension (atidesha)

Header (adhikAra)

There are other sub types, but this is the major classification

These 6+ types of sUtram-s cover a majority of the known concepts of modern programming

Page 31: Panini for IT professionals

Programming concepts and sUtram types Type of sUtra Programming equivalent

Definition Define a function, variable or a value

#define, final static, const

Interpreting Meta rules, Annotations

(@Column, @Id in Hibernate)

DOCTYPE, <META> tags in html, MIME types (pdf, jpg etc.) in

contents

Rules if-then-else condition (or select-case)

If (this condition) then action1 else action2

Restriction Scoping (Restrict or narrow scope of other rules)

Natural numbers start from 1;

Odd numbers are those when divided by 2 yield 1 as remainder

Extension,

Casting

Applying one “concept” to something else

Like Scala traits, “apply a behaviour” to another class

Class casting (Like integer to double, integer to boolean etc.)

Header Constitute a topic

package, namespace

Negation Negation of given general rule in specific circumstances

Page 32: Panini for IT professionals

Pause and Think moment #4

• What is a language?

• Set of sentences

• Sentence = Set of words

• Word = Set of letters

• Letter = A form of sound

• Sound = Vibration of air molecules as perceived by ears

Page 33: Panini for IT professionals

Scheme: Word Generation

Panini’s only formula for word generation

word = prefix0..n + root/stem + affix0..n + suffix

Page 34: Panini for IT professionals

Scheme: Application of Affixes

Affixes is an innovative scheme used by pANini (very likely his predecessors too)

Just like the modifiers in a programming language, but way more functional and versatile

For eg, you have primitive types like int, double etc. but you modify its characterstics with const, final, static, transient etc.

Affixes also have a similarity to Hungarian-notation syntax (iIndex, dPrice, sText, dtToday); Here the prefix indicates the type of variable, while Panini-s indicators indicate a specific function in a specific context

Page 35: Panini for IT professionals

The Affix and the Marker

pANini defines a separate set of “it-s” (markers) for the affixes scheme

Some examples of affix markers: any consonant at the end of an affix

ञञ ट ड when in the beginning of an affix

च छ ज झ ञ ट ठ ड ढ ण

the letters ल श क ख ग घ ङ in non derivative compound related affixes

The marker’s functionality is to provide a modification indicator and then disappear

Page 36: Panini for IT professionals

The Panini Affix Markup Language

For IT pro-s, the marker functionality should have rung a striking similarity with something they work everyday (HTML! and XML!)

In a markup-languge, the tags like body, head, title, etc. tell the browser what to do with the content, but the tags themselves are not displayed by the browser

Similarly, the affix delivers a certain content enclosed in the “it” tags, indicates what to do with the content, but those tags don’t serve any purpose thereafter, and disappear

Each affix also acts like a functional programming closure – it provides a specific function based on the content

Page 37: Panini for IT professionals

Examples of Affixes

As stand-alone words, affixes do not make any sense and feel arbitrary

But in Panini’s technical terms they are extremely well defined, purely technical and fully functional

Each affix can find a parallel to one or more programming principle

Examples: कतवा लयप नतङ सप शति शािच णणच घञ

pANini defines over~500 with various functional characterstics

Page 38: Panini for IT professionals

Scheme: Functional abstraction of affixes Let us take some affixes: लप आप छाप टाप डाप लयप

What is common in all of this? प

Lets write a simple script to get all the affixes with letter ‘p’

List affixes = [lup, aap, chaap, taap, daap, lyap, dak, tuk, shatrun … ] p-affixes = affixes.collect it.contains(‘p’) assert p_affixes = [lup, aap, chaap, taap, daap, lyap]

So how does Panini express this?

पित (pit)

प इत यसय तत

similarly ककत ङङत णणत शशत etc.

Page 39: Panini for IT professionals

Scheme: Rules

Procedural programming

def ticketPrice = 50

if (age < 2) ticketPrice = 0

else if (age < 12) ticketPrice = ticketPrice / 2

Functional programming

get_ticket_price (function c, ticketPrice, discount)

if (c.evalute() == true) return ticketPrice * discount

get_ticket_price((age < 2), ticketPrice, 0) get_ticket_price((age < 12), ticketPrice, 0.5)

value = f(g(age), price, discount)

Page 40: Panini for IT professionals

Scheme: Panini’s rules

For all the sandhi rules, Panini uses a general formula:

z = f(x,[y0 | y1]), where z = 1st vibhakti x = 6th vibhakti y0 = 7th vibhakti

y1 = 3rd vibhakti

When y0 follows, x = z

When y1 follows or precedes, x = z

Page 41: Panini for IT professionals

Scheme: Technical Terms

ashTAdhyAyI is full of “technical terms” like the affixes, defintions and rules, which in normal Samskritam do not mean anything

For eg. the word “guNa” has several meanings in Samskritam: virtue, quality, character, strings, efficiency, tendency, kind, times

But none of them are used here. In Panini’s world guNa means transformation of a to a, i to e, u to o, r to ar. That’s it!

So Panini defines a set of technical terms exclusive for his own domain. Those who know the domain, have the key.

Do you follow where I am getting at?

Panini created a DSL – Domain Specific Language

Page 42: Panini for IT professionals

Scheme: Anuvrtti (“Borrow-over”)

• at beach

• people

• while lifeguards watching

• playing while on sand

• volleyball etc. are games

• also bands

• for the kids

• ice-cream etc. from shop

• not babies

• in summer only

Imagine a scenario at a beach:

Page 43: Panini for IT professionals

Scheme: Anuvrtti

One word used only once, the following sUtram-s borrow from the previous sUtram appropriately

Hmm, where have we heard this before?

Page 44: Panini for IT professionals

Scheme: Anuvrtti (contd)

DRY ! Don’t Repeat Yourself ! Panini establishes himself as “Reuse Specialist” and “Supreme kanjoos commander of the universe” ! What is considered a best programming practice in modern days is implicit in Panini’s work end-to-end. So much so that, Patanjali – another extra-ordinary genius says There is not a single extra letter in ashtadhyayI, what to say about a whole sUtram?

Page 45: Panini for IT professionals

Scheme: Casting

In OOP you have heard about casting one object to another

Double temperature = 25.20 Integer temp = (Integer) temperature //now temp behaves like an integer object, not double

By casting, we transposed the properties of one object to another

Panini uses an affix “वत” to do such transformations

लोटो शलङवत means all affixes लोट behave like शलङ under certain conditions

Page 46: Panini for IT professionals

Summary

Affixes form the central part in Panini’s algorithmic approach to solving his problems

More than 500 affixes and several of them are a parallel to modern programming theories and principles

Functions of several affixes or approaches do not even find a parallel in programming

For eg. the last 3 sections of aShTAdhyAyI contains rules in such a way that “each rule thinks that it is the last rule”, so once applied, further rules wont apply.

Page 47: Panini for IT professionals

Well, obviously…

So it kinda looks like we are retrofitting modern theories back into Panini’s approach and claim that all this was already done by Panini. That does not sound fair!

Yes, we mapped only a few functions.

What if some of the techniques used by Panini could radically change how we write programs? What if they could deliver maximum benefit with minimum effort?

Page 48: Panini for IT professionals

Research on Panini

Discovery of Panini and his successors’ works by Western academicians has laid to the fundamentals of modern linguistics (Noam Chomsky etc)

It spawned many modern theories and institutions; In fact there are proposals that Norman-Backus form must be renamed to Norman-Backus-Panini form

Just search for Panini in academics or in your local University library, there are all kinds of theories and thesis on ashTAdhyAyI and similar works

Entire books have been written focusing on just one pratyaya of Panini alone

Research on Panini has been happening ever since he did his work – and it is still fresh!

Page 49: Panini for IT professionals

धनयवाद: Thank you for your time !