# The Lumber Room

"Consign them to dust and damp by way of preserving them"

## The “most natural” definition of the div and mod functions

with one comment

[incomplete: must add examples and more discussion]

Most programming languages include a “remainder” or “modulo” function, and also an integer division (“quotient”) function. Given two integers $D$ and $d$, let’s call the results of these functions $r$ and $q$ respectively.

For positive $D$ and $d$, it is clear what $q$ and $r$ should be: $q = \left\lfloor D/d \right\rfloor$ is the largest integer $n$ such that $nd \le D$, and $r = D - qd$ is the remainder which therefore satisfies $0 \le r < d$.

What should we do when, as frequently happens, $D$ is negative, or (as less frequently happens) $d$ is negative?

For negative $D$ and positive $d$, there are two choices when $D$ lies between two multiples of $d$ (i.e. $q_1 d < D < q_2 d$):

(1) Set $q$ to the lesser value, so that $0 \le r < d$ continues to hold, or
(2) Set $q$ to the greater (and therefore smaller in magnitude) value.

There are very good reasons why (1) is preferable to (2): it ensures that the function $a \bmod m$ is always positive no matter what the value of $a$, so that, for example, $a \equiv b \pmod m \iff (a \bmod m) = (b \bmod m)$.

And indeed that is what the more recent programming languages do. There is a table on Wikipedia: C, C++, Java, Go(!), OCaml(!), PHP, all have the “bad” behaviour, while Maple, Mathematica, Microsoft Excel, Perl, Python, Ruby have the “good” behaviour. Some languages have separate functions for both behaviours (e.g. Haskell has quotRem and divMod functions, similarly Common Lisp, Fortran, MATLAB).

There’s also the question of what to do when $d$ is negative, which turns out not to matter much (as long as it’s consistent with the above). One defintion is to continue to have $q$ be the lesser value, and the other is to continue to insist that $r \ge 0$. Both are fine, though sometimes the latter is nicer.

These are elaborated in The Euclidean Definition of the Functions div and mod by Raymond T. Boute, ACM Transactions on Programming Languages and Systems, Vol 14, No. 2, April 1992.

Written by S

Mon, 2015-01-12 at 09:30:35

Viṣṇu, appearing before Bali as Vāmana, transformed into Trivikrama, filling the universe, covering all the earth and the heavens in two steps.

The verse that opens the Pūrva-pīṭhikā of Daṇḍin’s Daśakumāracarita plays on this imagination, and on the word daṇda / daṇḍin. Here’s the verse (in Sragdharā metre of pattern GGGGLGG—LLLLLLG—GLGGLGG):

May the leg of Trivikrama,
pole for the parasol that is the universe,
stem of the lotus that is Brahma’s seat,
mast of the ship that is the earth,
rod of the streaming banner that is the river of the Gods,
axle-rod around which the zodiac turns,
pillar of victory over the three worlds,
rod of death for the enemies of the Gods,
favour you with blessings.

jyotiścakr’-âkṣa-daṇḍas tribhuvana-vijaya-stambha-daṇḍo ‘ṅghri-daṇḍaḥ
śreyas traivikramas te vitaratu vibudha-dveṣiṇāṃ kāla-daṇḍaḥ //

ब्रह्माण्डच्छत्रदण्डः शतधृतिभवनाम्भोरुहो नालदण्डः
क्षोणीनौकूपदण्डः क्षरदमरसरित्पट्टिकाकेतुदण्डः ।
ज्योतिश्चक्राक्षदण्डस्त्रिभुवनविजयस्तम्भदण्डोऽङ्घ्रिदण्डः
श्रेयस्त्रैविक्रमस्ते वितरतु विबुधद्वेषिणां कालदण्डः ॥

[The Mānasataraṃgiṇī-kāra, agreeing with Santillana and von Dechend the authors of Hamlet’s Mill, considers the “pole” or “axis” motif central to the conception of Vishnu (e.g. matsya‘s horn, Mount Meru as the rod on kūrma, nṛsiṃha from the pillar, etc.: see here), sees much more depth in this poem, and that Daṇḍin was remembering this old motif.]

The translation above is mildly modified from that of Isabelle Onians in her translation (“What Ten Young Men Did”) of the Daśa-kumāra-carita, published by the Clay Sanskrit Library:

Pole for the parasol-shell that is Brahma’s cosmic egg,
Stem for Brahma’s lotus seat,
Mast for the ship that is the earth,
Rod for the banner that is the rushing immortal river Ganges,
Axle rod for the rotating zodiac,
Pillar of victory over the three worlds—
May Vishnu’s leg favor you with blessings—
Staff that is the leg of him who as Trivikrama reclaimed those three worlds in three steps,
Rod of time, death itself, for the demon enemies of the gods.

Ryder, in his translation (“The Ten Princes”), takes some liberties and manages verse in couplets:

May everlasting joy be thine,
Conferred by Vishnu’s foot divine,

Which, when it trod the devils flat,
Became the staff of this and that:

The staff around which is unfurled,
The sunshade of the living world;

The flagstaff for the silken gleam
Of sacred Ganges’ deathless stream;

The mast of earth’s far-driven ship,
Round which the stars (as axis) dip;

The lotus stalk of Brahma’s shrine;
The fulcrumed staff of life divine.

For another verse that fully gets into this “filling the universe” spirit, see The dance of the bhairava on manasa-taramgini.

Written by S

Sun, 2014-08-17 at 23:36:42

## Sanskrit and German

[Originally posted to linguistics.stackexchange.com as an answer to a question by user Manishearth, who asked: “I’ve heard many times that learning German is easier for those who speak Sanskrit, and vice versa. Is there any linguistic basis for this? What similarities exist between the two languages that may be able to explain this?”]

This is an answer not to the part about whether it is easier to learn German after Sanskrit (I don’t know), but rather, a few more assorted points re. “What similarities exist between the two languages”, or even more generally, “Why would people make such a claim?”

As Cerberus [another user] noted, most of these claims come from people whose familiarity, outside of Indian languages, is with mainly English, and perhaps a bit of French (or rarely, Spanish or Italian). So even though many similarities noted between Sanskrit and German are in fact those shared by many members of the Indo-European family, the claim just means that among the few languages considered, German’s similarities are remarkable.

[My background: I have a reasonable familiarity with Sanskrit; not so much with German. For impressions about German I’ll rely on the Wikipedia articles, and, (don’t lynch me) Mark Twain’s humorous essay The Awful German Language — of course I know it’s unfair and not a work of linguistics, but as examples of what the average English speaker might find unusual in German, it is a useful document.]

With that said, some similarities:

### Cases

German apparently has four cases; Sanskrit has eight cases (traditional Sanskrit grammar counts seven, not counting the vocative as distinct). As Cerberus [another user] notes, “Sanskrit and German have several functional cases, whereas French/Spanish/Italian/Portuguese/Dutch/English/etc. do not. Those are the languages one might be inclined to compare Sanskrit with”.

### Compound words

Although English does have short compound words (like bluebirdhorseshoepaperback or pickpocket), German has a reputation for long compound words. (Twain complains that the average German sentence “is built mainly of compound words constructed by the writer on the spot, and not to be found in any dictionary — six or seven words compacted into one, without joint or seam — that is, without hyphens”) He mentions Stadtverordnetenversammlungen and Generalstaatsverordnetenversammlungen; Wikipedia mentions Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz and Donaudampfschiffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft. But these are nothing compared to the words one routinely finds in ornate Sanskrit prose. See for example this post. Sanskrit like German allows compounds of arbitrary length, and compounds made of four or five words are routinely found in even the most common Sanskrit texts.

### Verb appearing late

It appears that German words tend to come later in the sentence than English speakers are comfortable with. I notice questions on this SE showing that German has V2 word order, not SOV. However, many English speakers seem to find late verbs in German worth remarking on. One of my favourite sentences from Hofstadter goes

“The proverbial German phenomenon of the “verb-at-the-end”, about which droll tales of absentminded professors who would begin a sentence, ramble on for an entire lecture, and then finish up by rattling off a string of verbs by which their audience, for whom the stack had long since lost its coherence, would be totally nonplussed, are told, is an excellent example of linguistic pushing and popping.”

Twain too, says “the reader is left to flounder through to the remote verb” and gives the analogy of

“But when he, upon the street, the (in-satin-and-silk-covered-now-very-unconstrained-after-the-newest-fashioned-dressed) government counselor’s wife met,”

and also

“In the daybeforeyesterdayshortlyaftereleveno’clock Night, the inthistownstandingtavern called `The Wagoner’ was downburnt. When the fire to the onthedownburninghouseresting Stork’s Nest reached, flew the parent Storks away. But when the bytheraging, firesurrounded Nest itself caught Fire, straightway plunged the quickreturning Mother-stork into the Flames and died, her Wings over her young ones outspread.”

Well, this is exactly typical Sanskrit writing. Those sentences might have been translated verbatim from a Sanskrit text. Sanskrit technically has free word order (i.e., words can be put in any order), and this is made much use of in verse, but in prose, usage tends to be SOV.

Of Sanskrit’s greatest prose work, Kādambarī, someone named Albrecht Weber wrote in 1853 that in it,

“the verb is kept back to the second, third, fourth, nay, once to the sixth page, and all the interval is filled with epithets and epithets to these epithets: moreover these epithets frequently consist of compounds extending over more than one line; in short, Bāṇa’s prose is an Indian wood, where all progress is rendered impossible by the undergrowth until the traveller cuts out a path for himself, and where, even then, he has to reckon with malicious wild beasts in the shape of unknown words that affright him.” (“…ein wahrer indischer Wald…”)

(This is unfair criticism: personally, I have been lately reading the Kādambarī with the help of friends more experienced in Sanskrit, and I must say the style is truly enjoyable.) Now, the fact that this was a German Indologist writing for the Journal of the German Oriental Society somewhat goes against the claim of Sanskrit and German being similar. But one could say: for someone familiar with Sanskrit’s long compounds and late verbs that even Germans find difficult, the same features in German will pose little difficulty.

In Sanskrit, as it appears to be in German, an adjective takes the gender, case, and number of whatever it is describing. (Twain: “would rather decline two drinks than one German adjective”)

### Gender of nouns has to be learned

By and large, it is so in Sanskrit as well. Twain notes that in German “a tree is male, its buds are female, its leaves are neuter; horses are sexless, dogs are male, cats are female — tomcats included, of course; a person’s mouth, neck, bosom, elbows, fingers, nails, feet, and body are of the male sex, and his head is male or neuter according to the word selected to signify it, and not according to the sex of the individual who wears it — for in Germany all the women either male heads or sexless ones; a person’s nose, lips, shoulders, breast, hands, and toes are of the female sex; and his hair, ears, eyes, chin, legs, knees, heart, and conscience haven’t any sex at all”. (He goes on to write a “Tale of the Fishwife and its Sad Fate.”) It does not seem quite so bad in Sanskrit, but yes, gender of words needs to be learned. (In Sanskrit there exists a word for “wife” in each of the three genders.) However this is a feature common to many languages (including, say, languages like Hindi or French that have only two genders) so I shouldn’t list it among similarities.

### Spelling

This is something quite trivial, and linguists often don’t even consider orthography a part of the language proper, but spelling seems to be a pretty big deal to Indians learning other languages. The writing systems of most Indian languages are phonetic, in the sense that the spelling deterministically reflects the pronunciation and vice-versa. There are no silent letters, no wondering about a word spelled in a particular way is pronounced. Indian learners of English often complain about the ad-hoc inconsistent spelling of English; it seems a bigger deal than it should be. From this point of view, the fact that it is claimed that for German, “After one short lesson in the alphabet, the student can tell how any German word is pronounced without having to ask” means that that aspect of German is easier to learn.

### The harmony of sound and sense

This is extremely subjective and will be controversial, and perhaps I will seem biased, but to me, in Sanskrit, it seems possible to pick words whose sounds match the desired feeling, better than in other languages. I have seen people who knew many languages say the same thing, and also Western translators from Sanskrit etc., so it is interesting for me to see Twain make a similar remark about German. Anyway, this is subjective, so I’ll not dwell on this much.

### Non-similarities

There are of course many; e.g. Sanskrit does not have articles (the, etc.) unlike German. It also has very few prepositions (has only a few ones like “without”, “with”, “before”), as the work of prepositions like “to”, “from”, or “by” is handled by case. The difficulty of German prepositions does not seem to be present in Sanskrit.

## TL;DR version

Some alleged difficulties of learning German, such as cases, long compounds, and word order, are present to a far greater extent in Sanskrit, so in principle someone who knows Sanskrit may be able to pick them up more easily than someone trying to learn German without this knowledge. However, this may not be saying anything more than that knowing one language helps you learn others.

Written by S

Tue, 2014-07-01 at 20:25:02

Posted in language, sanskrit

Tagged with , ,

## Colliding balls approximate pi

Found via G+, a new physical experiment that approximates $\pi$, like Buffon’s needle problem: The Pi Machine.

Roughly, the amazing discovery of Gregory Galperin is this: When a ball of mass $M$ collides with one of ball $m$, propelling it towards a wall, the number of collisions (assuming standard physics idealisms) is $\pi \lfloor\sqrt{M/m}\rfloor$, so by taking $M/m = 10^{2n}$, we can get the first $n+1$ digits of $\pi$. Note that this number of collisions is an entirely determinstic quantity; there’s no probability is involved!

Here’s a video demonstrating the fact for $M/m = 100$ (the blue ball is the heavier one):

The NYT post says how this discovery came about:

Dr. Galperin’s approach was also geometric but very different (using an unfolding geodesic), building on prior related insights. Dr. Galperin, who studied under well-known Russian mathematician Andrei Kolmogorov, had recently written (with Yakov Sinai) extensively on ball collisions, realized just before a talk in 1995 that a plot of the ball positions of a pair of colliding balls could be used to determine pi. (When he mentioned this insight in the talk, no one in the audience believed him.) This finding was ultimately published as “Playing Pool With Pi” in a 2003 issue of Regular and Chaotic Dynamics.

The paper, Playing Pool With π (The number π from a billiard point of view) is very readable. The post has, despite a “solution” section, essentially no explanation, but the two comments by Dave in the comments section explain it clearly. And a reader sent in a cleaned-up version of that too: here, by Benjamin Wearn who teaches physics at Fieldston School.

Now someone needs to make a simulation / animation graphing the two balls in phase space of momentum. :-)

I’d done something a while ago, to illustrate The Orbit of the Moon around the Sun is Convex!, here. Probably need to re-learn all that JavaScript stuff, to make one for this. Leaving this post here as a placeholder.

Or maybe someone has done it already?

Written by S

Mon, 2014-06-23 at 23:03:18

Posted in mathematics, unfinished

## The Indian theory of aesthetic appreciation (rasa)

Here’s a great, simple write-up aimed at a Western audience, from the Clay Sanskrit Library edition of Kālidāsa’s The Recognition of Shakuntala, written by Somadeva Vasudeva:

Imagine that you find yourself going to see a performance of “Romeo and Juliet.” You are in the right mood for the play, no mundane worries preoccupy your mind, you have agreeable company, and the theatre, the stage, the director and the actors are all excellent—capable of doing justice to a great play. Your seat in the theatre is comfortable and gives an unobstructed view.

The play begins and you find yourself drawn into the world Shakespeare is sketching. The involvement deepens to an immersion where the ordinary, everyday world dims and fades from the center of attention, you begin to understand and even share the feelings of the characters on stage—under ideal conditions you might reach a stage where you
begin to participate in some strange way in the love being evoked.

Now, if at that moment you were to ask yourself: “Whose love is this?” a paradox arises.

It cannot be Romeo’s love for Juliet, nor Juliet’s love for Romeo, for they are fictional characters. It cannot be the actors’, for in reality they may despise one another. It cannot be your own love, for you cannot love a fictional character and know nothing about the actors’ real personalities (they are veiled by the role they assume), and, for the same reasons, it cannot be the actors’ love for either you or the fictional characters. So it is a peculiar, almost abstract love without immediate referent or context.

A Sanskrit aesthete would explain to you that you are at that moment “relishing” (āsvādana) your own “fundamental emotional state” (sthāyi-bhāva) called “passion” (rati) which has been “decontextualised” (sādhāraṇīkṛta) by the operation of “sympathetic resonance” (hṛdayasaṃvāda) and heightened to become transformed into an “aesthetic sentiment” (rasa) called the “erotic sentiment” (śṛṅgāra).

This “aesthetic sentiment” is a paradoxical and ephemeral thing that can be evoked by the play but is not exactly caused by it, for many spectators may have felt nothing at all during the same performance. You yourself, seeing it again next week, under the same circumstances, might experience nothing. It is, moreover, something that cannot be adequately explained through analytic terms, the only proof for its existence is its direct, personal experience.

[…]

It is, moreover, a blissful experience. The fact that sensitive readers often weep while reading poetry does not mean that they are suffering, rather the tenderness of the work has succeeded in melting the contraction of their minds or hearts.

The non-ordinary nature of such aesthetic sentiments makes it possible for the spectator or reader to derive a pleasurable experience even from what in ordinary life would be causes of grief.

The Indian scholarly tradition has a lot more, including some very thoughtful deliberation and perceptive observation, but it seems good to start a discussion of rasa with an example like this, than to start with the technical details.

[Another good start may be via film. See for instance:
How to Watch a Hindi Film: The Example of Kuch Kuch Hota Hai by Sam Joshi, published in Education About Asia, Volume 9, Number 1 (Spring 2004).
and perhaps (and if you have a lot of time):
Is There an Indian Way of Filmmaking? by Philip Lutgendorf, published in International Journal of Hindu Studies, Vol. 10, No. 3 (Dec., 2006), pp. 227-256.
Previously on this blog: On songs in Bollywood]

Written by S

Fri, 2014-06-06 at 23:46:41

## The rest is commentary

Famous verses appear in many variants. Thanks to Google, it is easy to find many of them. For “paropakāraḥ puṇyāya, pāpāya parapīḍanam”, Google throws up a lot of variants for the first half.

The Vikramacarita has:

śrūyatāṃ dharmasarvasvaṃ, yad uktaṃ śāstrakoṭibhiḥ /
paropakāraḥ puṇyāya, pāpāya parapīḍanam

Other variants are:

saṅkṣepāt kathyate dharmo janāḥ kiṃ vistareṇa vaḥ |
paropakāraḥ puṇyāya pāpāya para-pīḍanam ||Panc_3.103||

or

paropakāraḥ puṇyāya pāpāya parapīḍanam //

or

paropakāraḥ puṇyāya pāpāya parapīḍanam

Going by the first line gives other verses:

śrūyatāṃ dharmasarvasvaṃ śrutvā caivāvadhāryatām | (or caiva vicāryatām ।)
ātmanaḥ pratikūlāni pareṣāṃ na samācaret ||

[Cāṇakya-nīti, Pañcatantra, Subhāṣitāvalī etc.]

prāṇā yathātmano ‘bhīṣṭā bhūtānām api te tathā |

तस्माद्धर्मप्रधानेन भवितव्यं यतात्मना ।
तथा च सर्वभूतेषु वर्तितव्यं यथात्मनि ॥ Mahābhārata Shānti-Parva 167:9
(http://blog.practicalsanskrit.com/2013/05/do-unto-others-golden-rule-of-humanity.html)

05,039.057b*0238_01 ātmanaḥ pratikūlāni vijānan na samācaret
05,039.057c saṃgraheṇaiṣa dharmaḥ syāt kāmād anyaḥ pravartate

As Hillel says, the rest is commentary.

For (some) commentary, go here.

Written by S

Fri, 2014-06-06 at 23:38:30

Posted in quotes, sanskrit, unfinished

## Prefatory apprehension

Robert Recorde’s 1557 book is noted for being the first to introduce the equals sign =, and is titled:

The Whetstone of Witte: whiche is the seconde parte of Arithmeteke: containing the extraction of rootes; the cossike practise, with the rule of equation; and the workes of Surde Nombers.

Its title page (see http://www.maa.org/publications/periodicals/convergence/mathematical-treasures-robert-recordes-whetstone-of-witte, see also the full book at https://archive.org/stream/TheWhetstoneOfWitte#page/n0/mode/2up) contains this verse:

 Original spelling Though many ſtones doe beare greate price, The whetſtone is for exerſice As neadefull, and in woorke as ſtraunge: Dulle thinges and harde it will ſo chaunge, And make them ſharpe, to right good vſe: All arteſmen knowe, thei can not chuſe, But uſe his helpe: yet as men ſee, Noe ſharpeneſſe ſemeth in it to bee. The grounde of artes did brede this ſtone: His vſe is greate, and moare then one. Here if you lift your wittes to whette, Moche ſharpeneſſe thereby ſhall you gette. Dulle wittes hereby doe greately mende, Sharpe wittes are fined to their fulle ende. Now proue, and praiſe, as you doe finde, And to your ſelf be not vnkinde. Modern spelling Though many stones do bear great price, The whetstone is for exercise As needful, and in work as strange: Dull things and hard it will so change And make them sharp, to right good use: All artsmen know they cannot choose But use his help; yet as men see, No sharpness seemeth in it to be. The ground of arts did breed this stone; His use is great, and more than one. Here if you lift your wits to whet, Much sharpness thereby shall you get. Dull wits hereby do greatly mend, Sharp wits are fined to their full end. Now prove and praise as you do find, And to yourself be not unkind.

Apparently the full title contains a pun (see http://www.pballew.net/arithm17.html): “the cossike practise” in the title refers to algebra, as the Latin cosa apparently meaning “a thing” was used to stand for an unknown, abbreviated to cos — but the Latin word cos itself means a grindstone.

The author again reminds readers not to blame his book, at the end of his preface:

 To the curiouſe ſcanner. If you ought finde, as ſome men maie, That you can mende, I ſhall you praie, To take ſome paine ſo grace maie ſende, This worke to growe to perfecte ende. But if you mende not that you blame, I winne the praiſe, and you the ſhame. Therfore be wiſe, and learne before, Sith ſlaunder hurtes it ſelf moſte ſore.

Authors are either anxious about how their book is received, or make sure to be pointedly uncaring.

Sir Arthur Conan Doyle, in a mostly forgettable volume of poetry (Songs of the Road, 1911), begins:

If it were not for the hillocks
You’d think little of the hills;
The rivers would seem tiny
If it were not for the rills.
If you never saw the brushwood
You would under-rate the trees;
And so you see the purpose
Of such little rhymes as these.

Kālidāsa of course begins his Raghuvaṃśa with a grand disclaimer:

kva sūryaprabhavo vaṃśaḥ kva cālpaviṣayā matiḥ /
titīrṣur dustaram mohād uḍupenāsmi sāgaram // Ragh_1.2 //

mandaḥ kaviyaśaḥ prārthī gamiṣyāmy upahāsyatām /
prāṃśulabhye phale lobhād udbāhur iva vāmanaḥ // Ragh_1.3 //

atha vā kṛtavāgdvāre vaṃśe ‘smin pūrvasūribhiḥ /
maṇau vajrasamutkīrṇe sūtrasyevāsti me gatiḥ // Ragh_1.4 //

But the most nonchalant I’ve seen, thanks to Dr. Ganesh, is this gīti by Śrīkṛṣṇa Brahmatantra Yatīndra of the Parakāla Maṭha, Mysore:

nindatu vā nandatu vā
mandamanīṣā niśamya kṛtim etām
harṣaṃ vā marṣaṃ vā
sarṣapamātram api naiva vindema

Screw you guys. :-)

Written by S

Wed, 2014-05-28 at 23:56:11

Posted in history, mathematics