4

In computer science, there's a "basic problem" called string reversal. You take a piece of text, and flip it so it reads backwards. "abcd" becomes "dcba", etc. There's also the question of plaindromes -- "hannah" is a name that reads the same both ways if it is flipped in the middle.

However with Unicode this becomes difficult, because suddenly rather than having to deal with just western languages like English (Which I assume to be uniform in this regard -- but I could be incorrect!), you also have to deal with Arabic, Sumarian, any language that Unicode supports.

So my question is: Has this question been studied and what assumptions about reversing pieces of text like this can be made, and what assumptions made in the context of English are likely to be wrong?

For example, maybe in some languages with diatrics, the correct approach is to flip the diatric to the other side of the character, or keep it in the same position. Maybe some languages/cultures have never thought of palindromes, etc.

6
  • 4
    Some languages cannot have palindromes, since the consonants allowed in syllable onset and syllable coda are mutually exclusive (e.g., Hawaiian). And if you take a writing system like Devanagari where vowels are diacritics but different vowels appear on different sides of the base consonant (left/right/above/below), I’m not sure what exactly you’d even expect to happen if you ‘reverse’ the text. – Janus Bahs Jacquet Mar 31 at 7:06
  • 3
    I think string reversal is a "basic problem" only in the sense that it's pedagogically useful - once you assume every character is a single byte, it's a nice programming exercise. Once you have Unicode, string reversal becomes a lot harder, ill-defined, and most importantly, I don't think there's practical application. So I'm afraid this falls under the group of those programming problems where "if you need to do it, you're probably doing it wrong." – jick Mar 31 at 17:22
  • You need a more specific specification. How about working just like Unix rev, with the same limitations and flags, as far as possible? What new flags would be needed, and what defaults? – jlawler Mar 31 at 20:58
  • 3
    @JanusBahsJacquet - Just a remark — Hawaiian can have palindromes, such Hawaiian words begin and end with the same vowel, like olo “to rub back and forth; a saw”, a‘a “vein, nerve, tendon”, or even ā “jaw”. – Yellow Sky Apr 1 at 7:51
  • 1
    @YellowSky You’re right, I didn’t think that bit through thoroughly enough. – Janus Bahs Jacquet Apr 1 at 8:13
4

Kaibun (circle sentences) are a poetic form in Japanese, for example (in romaji)

Ta-ke-ya-bu ya-ke-ta (The bamboo grove has been burned) from Wikipedia, Kaibun.

(they are also a "uncle joke" ie something your uncle would think is clever and funny)

Note that when rendered in natural script, with kanji, the sound structure is hidden (竹薮焼けた) So checking that this is a palindrome would first require the computationally complex step of converting to kana. Moreover rules are made to be broken, and the elements of Japanese text such as the morae written with one large and one small kana (for example しゃ "sha") might be reversed or not, as the poetry requires. So the reversal of a string is not generally possible.

In Hebrew, דוד‎ ("dvd" or David) is a palindrome in text, but the implied vowels are different. In Hebrew, in contrast to Japanese, it is the written form that is reversed, with unwritten vowels ignored.

You can investigate other languages through wiktionary palindrome appendices

3

I think James K's answer gives valuable insight, and shows the way to the general principle: Text reversal in any language is the reversal of the order of the units. Text reversal for a given writing system is well-defined to the same degree that the unit in that writing system is well-defined.

In English, the unit of writing is considered to be the letter. Since digital text is designed around the idea of making the letter the unit of writing, the problem of reversal is comparatively trivial.

Moreover, the problem is not much compounded by the addition of European diacritics, which are mostly considered to occupy the same linear index as the letter. For example, we intuit that the reversal of bébé should be ébéb, even though in the underlying Unicode representation each diacritic ends up on the same side of the e it was originally on. We don't care about that; our definition of é as a unit allows us to define ébéb as the reversal.

James K's kaibun example illustrates what happens when we take the idea further. Here, the unit is the syllable (or rather the on, as can be seen from the fourth example on the kaibun page). Hence, we get the surprising result that many letters, like the diacritic in é, maintain their original order in reversal:

ta ke ya bu ya ke ta (Japanese reversal)
ta ke ya bu ay ek at (Latin reversal — not a palindrome, because of bu!)

We should pause here and notice something curious: in the Latin text, the unit was written and not sounded,1 whereas in the Japanese text, the unit is sounded and not written (as James K pointed out). The choice is utterly arbitrary and yields different types of reversal. For example, nothing prevents us from deciding to reverse English syllabically, abandoning written reversal:

syllabically <> ly bik la syl 2

And nothing prevents us from rendering kaibun with text reversal, abandoning spoken reversal.

Or, just to push the point further, we could do graphical reversal, choosing points on a Cartesian grid as our unit and negating the x coordinate, y coordinate, or both coordinates. Or we could choose Unicode representation as our unit, in which case reversal becomes very easy again, but not very compelling: bébé <> ´eb´eb.3

In any case, suppose we apply the principle of a chosen unit defining the reversal to a different writing system. Let's try Devanagari, very different from Latin. This writing system combines consonants with appended vowels (an abugida). Unmarked vowels are a by default. As a syllabic system, the most natural reversal works similarly to Japanese:

देवनागरी devanāgarī <> रीगनावदे rīganāvade

In this system, because syllables are (more or less) identical with composed characters,4 text reversal and sound reversal happen to go handily together. Of course, as with bébé, this isn't a Unicode reversal; if we did so, we would end up with unattached ī before r and so on, and it would look as odd as ´eb: ीर (the first character, ी, is supposed to be attached to something to its left).

However, Hindi phonotactics (unlike Japanese ones) do allow a strict reverse of the sounds in these syllables. So you could begin the word with a different character for ī, one that's meant to stand on its own, followed by the character for ra: ईर, and continue from there:

ईरगानवेद् īragānaved

Here are these examples with highlighting:

devanagari reversals

(The little stroke at the end ् suppresses the default a vowel on the d.)

Hence Devanagari is a good example of a system where we could reverse it textually, phonemically, or syllabically, and get sensible reversals (at least for the combinations in this word; I'm not sure if every word in Hindi can be reversed phonemically). The choice of unit will make or more less sense depending on the language and writing system, but is ultimately up to you — or the designer of the programming problem.

What you observed at the start, though, is of course true. Non-Latin reversals, while possible and definable, are much thornier to code!


1 James K gave the Hebrew example as a system where the written and spoken forms differ; English furnishes an equally good example of this, since words like hannah and racecar are not spoken palindromes any more than דוד is.

2 In French, it's easy to do written reversal, but they also do a spoken reversal called verlan that combies intra- and inter-syllabic reversal of individual words. It has been studied (Wikipedia article; call for papers).

l'envers ["inverse"] <> verlan ["language game"] (reversed order of syllables)
femme ["woman"] <> meuf ["woman"] (intrasyllabic phoneme reversal)

Doing this reversal well is of course an interesting computational and linguistic challenge, since you need to analyze a sound structure that is not unambiguously indicated by the text alone.

3 It can yield more interesting results with Hebrew, where diacritics are more symmetrical: דָוִד (david) <> דִוָד (divad).

4 As with accents, your computer will generally not let you select less than a consonant + a vowel in Devanagari.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.