# Wolfram Mathematica

## Palindromes

A palindrome is a number, word, or sentence that reads the same from left to right and right to left. Use PalindromeQ, its options, and other string-related low-level functions to test for palindromic words and sentences.

This is an English palindrome.

In[1]:=
PalindromeQ["racecar"]
Out[1]=

The name Anna is also a palindrome, but you need to ignore the capitalization.

In[2]:=
PalindromeQ["Anna", IgnoreCase -> True]
Out[2]=

Use Decapitalize as an alternative to make the first character be lowercase.

In[3]:=
PalindromeQ[Decapitalize["Anna"]]
Out[3]=

The French verb "rêver" is a palindrome as well, but you need to ignore the diacritic.

In[4]:=
PalindromeQ["rêver", IgnoreDiacritics -> True]
Out[4]=

Use RemoveDiacritics to process the verb instead.

In[5]:=
PalindromeQ[RemoveDiacritics["rêver"]]
Out[5]=

With palindromic sentences, you also generally need to process the initial string.

In[6]:=
sentence = "Now, sir, a war is won!";
In[7]:=
PalindromeQ[sentence]
Out[7]=
In[8]:=
StringDelete[sentence, PunctuationCharacter | Whitespace]
Out[8]=
In[9]:=
StringDelete[sentence, PunctuationCharacter | Whitespace]; PalindromeQ[%, IgnoreCase -> True]
Out[9]=