Tag Archives: Futurama

systematically generate all permutations

In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, rearranging (reordering) its elements, a process called permuting. These differ from combinations, which are selections of some members of a set where order is disregarded. For example, written as tuples, there are six permutations of the set {1,2,3}, namely: (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), and (3,2,1). These are all the possible orderings of this three element set. As another example, an anagram of a word, all of whose letters are different, is a permutation of its letters. In this example, the letters are already ordered in the original word and the anagram is a reordering of the letters. The study of permutations of finite sets is a topic in the field of combinatorics.

Permutations occur, in more or less prominent ways, in almost every area of mathematics. They often arise when different orderings on certain finite sets are considered, possibly only because one wants to ignore such orderings and needs to know how many configurations are thus identified. For similar reasons permutations arise in the study of sorting algorithms in computer science.

The number of permutations of n distinct objects is n factorial usually written as n!, which means the product of all positive integers less than or equal ton.

In algebra and particularly in group theory, a permutation of a set S is defined as a bijection from S to itself. That is, it is a function from S to S for which every element occurs exactly once as an image value. This is related to the rearrangement of the elements of S in which each element s is replaced by the corresponding f(s). The collection of such permutations form a group called the symmetric group of S. The key to this group’s structure is the fact that the composition of two permutations (performing two given rearrangements in succession) results in another rearrangement. Permutations may act on structured objects by rearranging their components, or by certain replacements (substitutions) of symbols.

In elementary combinatorics, the k-permutations, or partial permutations, are the ordered arrangements of k distinct elements selected from a set. When k is equal to the size of the set, these are the permutations of the set.

In mathematics, when X is a finite set of at least two elements, the permutations of X (i.e. the bijective functions from X to X) fall into two classes of equal size: the even permutations and the odd permutations. If any total ordering of X is fixed, the parity (oddness orevenness) of a permutation \sigma of X can be defined as the parity of the number of inversions for σ, i.e., of pairs of elements x, y of X such that x<y and \sigma(x)>\sigma(y).

The sign or signature of a permutation σ is denoted sgn(σ) and defined as +1 if σ is even and −1 if σ is odd. The signature defines thealternating character of the symmetric group Sn. Another notation for the sign of a permutation is given by the more general Levi-Civita symbol (\epsilon_\sigma), which is defined for all maps from X to X, and has value zero for non-bijective maps.

The sign of a permutation can be explicitly expressed as

sgn(σ) = (−1)N(σ)

where N(σ) is the number of inversions in σ.

Alternatively, the sign of a permutation σ can be defined from its decomposition into the product of transpositions as

sgn(σ) = (−1)m

where m is the number of transpositions in the decomposition. Although such a decomposition is not unique, the parity of the number of transpositions in all decompositions is the same, implying that the sign of a permutation is well-defined.[1]

There are many ways to systematically generate all permutations of a given sequence. One classical algorithm, which is both simple and flexible, is based on finding the next permutation in lexicographic ordering, if it exists. It can handle repeated values, for which case it generates the distinct multiset permutations each once. Even for ordinary permutations it is significantly more efficient than generating values for the Lehmer code in lexicographic order (possibly using the factorial number system) and converting those to permutations. To use it, one starts by sorting the sequence in (weakly) increasing order (which gives its lexicographically minimal permutation), and then repeats advancing to the next permutation as long as one is found. The method goes back to Narayana Pandita in 14th century India, and has been frequently rediscovered ever since.[11]

The following algorithm generates the next permutation lexicographically after a given permutation. It changes the given permutation in-place.

  1. Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
  2. Find the largest index l such that a[k] < a[l]. Since k + 1 is such an index, l is well defined and satisfies k < l.
  3. Swap a[k] with a[l].
  4. Reverse the sequence from a[k + 1] up to and including the final element a[n].

After step 1, one knows that all of the elements strictly after position k form a weakly decreasing sequence, so no permutation of these elements will make it advance in lexicographic order; to advance one must increase a[k]. Step 2 finds the smallest value a[l] to replace a[k] by, and swapping them in step 3 leaves the sequence after position k in weakly decreasing order. Reversing this sequence in step 4 then produces its lexicographically minimal permutation, and the lexicographic successor of the initial state for the whole sequence.

An alternative to the above algorithm, the Steinhaus–Johnson–Trotter algorithm, generates an ordering on all the permutations of a given sequence with the property that any two consecutive permutations in its output differ by swapping two adjacent values. This ordering on the permutations was known to 17th-century English bell ringers, among whom it was known as “plain changes”. One advantage of this method is that the small amount of change from one permutation to the next allows the method to be implemented in constant time per permutation. The same can also easily generate the subset of even permutations, again in constant time per permutation, by skipping every other output permutation.[11]

 

Taxi cab numbers

Fermat’s Last Theorem near misses?

In mathematics, the nth taxicab number, typically denoted Ta(n) or Taxicab(n), is defined as the smallest number that can be expressed as a sum of two positive algebraic cubesin n distinct ways. The concept was first mentioned in 1657 by Bernard Frénicle de Bessy, and was made famous in the early 20th century by a story involving Srinivasa Ramanujan. In 1938, G. H. Hardy and E. M. Wright proved that such numbers exist for all positive integers n, and their proof is easily converted into a program to generate such numbers. However, the proof makes no claims at all about whether the thus-generated numbers are the smallest possible and thus it cannot be used to find the actual value of Ta(n).

The restriction of the summands to positive numbers is necessary, because allowing negative numbers allows for more (and smaller) instances of numbers that can be expressed as sums of cubes in n distinct ways. The concept of a cabtaxi number has been introduced to allow for alternative, less restrictive definitions of this nature. In a sense, the specification of two summands and powers of three is also restrictive; a generalized taxicab number allows for these values to be other than two and three, respectively.

Ta(2), also known as the Hardy–Ramanujan number, was first published by Bernard Frénicle de Bessy in 1657 and later immortalized by an incident involving mathematicians G. H. Hardy and Srinivasa Ramanujan. As told by Hardy [1]:

I remember once going to see him when he was lying ill at Putney. I had ridden in taxi-cab No. 1729, and remarked that the number seemed to be rather a dull one, and that I hoped it was not an unfavourable omen. “No”, he replied, “it is a very interesting number; it is the smallest number expressible as the sum of two [positive] cubes in two different ways.”

The subsequent taxicab numbers were found with the help of supercomputersJohn Leech obtained Ta(3) in 1957. E. Rosenstiel, J. A. Dardis and C. R. Rosenstiel found Ta(4) in 1991. J. A. Dardis found Ta(5) in 1994 and it was confirmed by David W. Wilson in 1999.[1][2] Ta(6) was announced by Uwe Hollerbach on the NMBRTHRY mailing list on March 9, 2008,[3] following a 2003 paper by Calude et al. that gave a 99% probability that the number was actually Ta(6).[4] Upper bounds for Ta(7) to Ta(12) were found by Christian Boyer in 2006.[5]