Keywords

1 Introduction

The Indian Civilization was an ardent contributor to the ancient understanding of science and technology. The astonishing foresight and vision of ancient scientists remain unparalleled. They augmented the conversations and thoughts about philosophy and science, often revealing structured explanations for phenomena that were way ahead of their time. Ancient India was a land of scholars, sages, seers, and scientists. Research has revealed outstanding examples of genius inventions such as the mathematical digit “zero”. Aryabhata created a symbol for zero and its integration into the place-value system enabled one to write large numbers using only ten symbols. Binary numbers involve the most rudimentary understanding of computer science, and it was first described by the Pingala in Chandahśāstra, a Sanskrit treatise on prosody. Another instance in relation to computer science is the chakravala method, which evolved as a cyclic algorithm to obtain integer solutions for intermediate quadratic equations. Research has suggested the presence of explanations and origins of theories such as the atomic theory and heliocentric theory in Ancient Indian texts long before the rest of the world documented it. A similar observation can be made regarding the knowledge of metallurgy, surgery, rocket science, and medicine.

In this regard, it is worth mentioning the achievement of Panini, who has gained the reputation of being the pioneer in grammars and languages. He was hailed as a Sanskrit grammarian who worked on phonetics, phonology, and morphology, thereby providing a complete and comprehensive grammar for Sanskrit. Incidentally, the word “Sanskrit” means “complete” or “perfect” and it was thought of as the divine language, or language of the gods. The Sanskrit language was indicative of the Vedic period in India, and was used in nearly all scientific and literary documents of the time. In several contexts, Panini has been identified as the world’s first programmer, owing to his outstanding contribution in defining a structured grammar for languages. Today, linguists and programmers around the world have identified the merits of his grammar used in the Sanskrit language, which in many ways helps present day understanding of Natural Language Processing and Artificial Intelligence (Fig. 1).

Fig. 1
figure 1

An artist’s interpretation of Panini

Panini’s work is largely compiled in his treatise called Astadhyayi, whose name indicates the presence of eight chapters, each subdivided into quarter chapters. Panini gives formal production rules and definitions to describe Sanskrit grammar. Panini’s constructions of the Sanskrit language using a grammar were vastly similar to a mathematical function, which integrated 1700 basic elements such as nouns, verbs, etc. [1].

There has been considerable speculation about the possibility of the presence of rules in ancient Indian logic and grammar that can aid advancement in cognitive and computer science. The significance of the context-sensitive grammars of Panini was understood only when the Chomsky normal form was introduced in the nineteenth century. Formally, Panini’s grammar, Ashtadhyayi is studied together with the dhatupatha (a list of verbal roots arranged into sublists), and the ganapatha (a list of various classes of morphs). Ashtadhyayi provides a structure for the analysis of sentences, which has been described as a machine generating words and sentences of Sanskrit [2].

Sanskrit’s phonology, morphology, and syntax are described in Ashtadhayayi in a collection of 4000 sutras, which define its structure as a rule-based system. Each sutra is a reference to a rule, which can be definitions, theorems (linguistic facts), and meta-theorems (rules regarding rules). Since Ancient India followed a mechanism of oral propagation of tradition, it was important to make the 4000 sutras as concise as possible, consisting of only three words each, achieved through various optimizations. Hence, it is generally agreed that the Paninian system is based on a principle of economy, an Occam’s razor. This makes the structure to be of special interest to cognitive scientists [2]. Traditionally, a sutra is defined as the most concise of statements which uses as few letters as possible. The Grammar follows a principle of the following form:

iko yan aci

Each sutra can be analogous to a production rule that defines a grammar. Therefore, it is only fitting to observe that the Panini system advocates the use of only three tokens in a production rule, achieved through employing several algebraic devices such as prefixes and suffixes. Panini took the idea of providing a context for action in terms of its relations to agents and situation, given by the karaka theory. The following semantic notions capture the various aspects of action, which have been used for optimizations [3]:

  1. a.

    Apadana: that which is fixed when departure takes place

  2. b.

    Sampradana: the recipient of the object

  3. c.

    Karana: the main cause of the effect; instrument

  4. d.

    Adhikarana: the basis, location

  5. e.

    Karman: what the agent seeks most to attain; deed, object

  6. f.

    Kartr: one who is independent; the agent

Here, any sentence is optimized to only three tokens, using prefixes, suffixes, recursion, and context. However, in a regular C compiler, there is no upper limit on the number of tokens in a statement. Therefore, in this study, an attempt has been made to employ these ideas to reduce the number of tokens in a production rule that defines a grammar for programming languages. Hence, LEX and YACC tools were used to define a limited functionality compiler for C programming language, which was designed using grammar production rules influenced by these optimizations.

2 Methodology

  1. A.

    Understanding

    1. 1.

      To analyze the sutra style of grammar which is highly optimized using prefixes and suffixes

    2. 2.

      To ponder over the present grammar of programming languages such as C and CUDA-C

  2. B.

    Design

    1. 1.

      To develop a C compiler using YACC for the new Panini inspired grammar

    2. 2.

      To develop a matrix multiplication program in C, with the new compiler

  3. C.

    Validation

    1. 1.

      To compile and run the program against a conventional compiler and the Panini compiler

    2. 2.

      To compare, prorate, and analyze the results obtained

      (Fig. 2).

      Fig. 2
      figure 2

      Design of compiler design of a conventional CUDA-C compiler b optimized Panini CUDA-C compiler

3 Experimental Results

A C program for matrix multiplication was compiled and executed over a conventional C compiler, and then with a compiler optimized using Panini grammar and time taken was 44.1537 s and 26.4922 s, respectively, for input size 2000. When executed on NVIDIA Tesla K40, the time taken to execute matrix multiplication on a CUDA compiler was 1.01 s. Through proration, we can reduce the time taken to 0.6059 s (Table 1).

Table 1 Experimental results for optimization using Panini compiler

4 Conclusion

  1. i.

    It can be concluded that using Panini’s optimizations in the grammar of a compiler can bring about a marked speed enhancement of nearly 40–50%.

  2. ii.

    When implemented for CUDA compilers, it can revolutionize fast data technologies for next generation GPU systems.

  3. iii.

    Panini has indeed proved himself to be the world’s first programmer.