In the last few weeks I spent a bit of time cleaning up Gray code. It went through a few API changes and I hope to have the subsets and partitions branches merged in within this week. I also implemented a demo of the Permutations branch that involves Polyhedron rotations. I hope to show one involving a Rubik’s cube when I have the Permutation group module in (more on that in a while). I also implemented a residue class and a residue group module as that was missing in the number theory branch of Sympy. That branch needs an overhaul both in terms of functionality as well as the code that is already there and I hope I can get some momentum going in that direction with the code I have written. I also wrote some generators for Permutation groups. This is fairly easy to do now, the basic algorithm is to generate all permutations and filter out those that do not fit the criteria. Of course, generating all permutations is inefficient, and some generators have certain special properties that we can use. For example, the Cyclic group can be generated in linear time as that simply involves a single rotation. Alternating group however requires the generation of all even permutations. Some group generators will probably make use of the specialized algorithms that have been implemented in the iterables section of Sympy.

I have also managed to implement the Schreier sims algorithm but its extremely ugly and unpythonic for now. Algorithms for generating orbits and stabilizer chains are also there but they are fairly inefficient. I hope to clean them up and submit them for a pull request in this week before the hard pencils down date.

]]>

I will probably spend this week cleaning up older pull requests rather than creating newer ones. Even so, those interested can keep track of my permutation_groups branch where most of my work related to that will go.

]]>

I had implemented Prufer codes before I left, which is basically a one-to-one mapping to labelled trees. Using Prufer codes, we can generate trees in an ordered manner, rank and unrank them and do all sorts of other cool stuff. By placing some restrictions on the enumerated Prufer codes, we can get the number of spanning trees of a complete bipartite graph. Apart from Prufer codes, I was also fixing up the algorithms I had implemented for bracelets, fixed-density and fixed-content necklaces, Lyndon brackets (these form the basis for free Lie algebra), meanders and stamp foldings. These are really specialized routines but it was decided in the mailing list that it would be really helpful for others to read.

Once I get the Permutations branch in, I can begin work on the Permutation Groups module, so that will be my immediate task.

]]>

So networkx integration is almost done. The code is a clinical wrapper over the networkx API exposed via a Graph object which is derived from the Basic class. Most of the algorithms are accessed via properties of the Graph. Doctests and docstrings are currently missing, I plan on adding them later. Currently I am working on a particularly hairy algorithm for generating all spanning trees. If things do not work soon enough I’ll just put in the brute force technique. Another thing not present right now is pygraphviz integration but this is a matter of a single function call. A related generation algorithm that will get integrated in iterables was one to generate all rooted oriented forests.

In the upcoming week I will move on to Permutation groups. Initially, I will need to revise my notes on group theory and take a look at some texts for computational group theoretic algorithms. Knuth’s book has material on Sims tables as well so lets see what I can glean from that front. Other than that, I hope to clean up my pull requests that have been lying around for so long and get them integrated. Concurrently, I intend to publish the algorithms I had written for Lyndon, Dyck gray codes, various necklaces, etc.

]]>

The other task that I was going to look up as networkx integration. This was rather easy. I have used pygraphviz for graph drawing. My mentor, Haz, suggested that I hook up some sort of a ascii drawer as well for the graph but that would look hideous IMO. At any rate, I could not find a decent ascii graph printing package. Once the code for this is reasonably polished, I will probably integrate some of David Eppstein’s python routines for various graph operations.

]]>

One favorite example of mine is this paper by Vincent Vajnovszki in which he introduces the ECO operator http://www.dmtcs.org/dmtcs-ojs/index.php/dmtcs/article/download/704/2887

Although several efficient, loopless, constant amortized time algorithms exist, they are all fairly distinct in their approaches. The above paper seeks to unify such structures using the ECO operator as a common theme. Another theme the author has addressed is the generation of p-ary Dyck Gray codes. To implement this I will be leveraging the already existing gray code infrastructure. To what extent though, I am not too sure.

There has also been a lot chatter lately on a Graph theory module for Sympy. Before the Gsoc started I had already written some code that tried to interface networkx and pygraphviz with Sympy and this sort of served as a prototype of the project. Anyway, I did mention that I would be integrating networkx into Sympy for implementing spanning tree generation. There is also the fact that a lot of stuff in the previous modules that is implemented by Mathematica that is incomplete because there is no Graph module. The presence of a graphing module, whether native or imported, is almost axiomatic to any complete CAS. Thus integrating networkx will be my task for the following week.

]]>

I also implemented a rather cute partitioning algorithm that breaks up numbers into powers of 2. This is referenced as an exercise in Knuth. In fact, since most of combinatorica’s functionality as far as permutations, partitions and subsets go, have been replicated, I am veering off into TAOCP’s exercises. These extend the theory developed in a rich and beautiful manner. A nice example is that of a partition lattice. This is basically a poset where the ordering between elements is decided on the basis of which majorizes the other. Majorization has been discussed earlier, so its a matter of generating all the partitions and figuring out an algorithm that can rapidly populate a lattice based this comparison measure. Comparisons between general partitions will be on the basis of their rank for now although a concept similar to majorization has been discussed for them in TAOCP.

Other things that were implemented this week was stuff related to restricted growth strings and Ferrers diagram which is a cute way to visualize a partition. RGS are fun because they are the basis of another type of gray codes. Currently I have implemented routines to extract the partition from the RGS, convert a partition to an RGS, enumerating all the RGS and ranking and unranking RGS. This will form the basis of stateful generation of lexicographically ordered partitions because I could not really find any other way of doing it cleanly.

Some pending work that I still need to do however is ranking and unranking ksubsets as well as their stateful generation. Once I have all of these things taken care of, hopefully I can move on to trees and graphs.

]]>

Most of the functionality for subsets and gray codes is complete and a lot of progress has been made on the partitions front as well. Since last week Chris Smith updated the integer partition algorithm to include compositions as well. So apart from listing all the partitions, it also lists partitions of a specific size as well as partitions whose elements don’t exceed a particular value.

Today I wrote the multiset partitions algorithm prescribed in Knuth. This algorithm effectively generates multipartitions in decreasing lexicographic order. Apart from that, I implemented functionality for generating restricted growth strings from partitions and generating partitions from restricted growth strings. My next task will be to investigate the relationships between Gray codes and partitions. My primary reference for this is a paper by Frank Ruskey who demonstrates the construction of a simple recursive gray code which utilizes the restricted growth strings of the partition.

Regarding gray codes themselves, I basically implemented a class that describes the basic functionality of a binary reflected gray code. Various tasks such as generating the next and previous gray code, ranking and unranking, etc have been implemented. Other gray code implementations need only inherit the gray code class and override the relevant functions. Functionality demonstrating the interplay between gray codes and subsets has also been implemented. The additions to subsets have been quite comprehensive. You can generate subsets in a binary order, lexicographically and gray code ordered. Ranking and unranking can also be done in a similar manner. Functionality to generate ksubsets has also been implemented. Generating, ranking and unrankng ksubsets is still incomplete and is currently my next task that I hope to undertake.

In the midst of all this, I will need to clean up my commit history for permutations and add tests for the partitions branch. Hopefully I will get on to trees later this week.

]]>

Some of the extras that have been implemented however are a few distance metrics, addition and subtraction of permutations on the basis of their Lehmer codes (inversion vectors) and linear time non lexicographic ranking and unranking.

Users will note that for now the Permutation class only supports numbers ordered from 0 to n. This design is deliberate as it significantly simplifies the implementation and keeps everything consistent. If one wishes to use the permutation class for objects other than integers then they would need to provide for some sort of mapping themselves. I will probably create a tutorial illustrating this in the future.

Regarding the work on partitions, thanks go out to community member Christopher Smith for correcting an implementation of mine of the k partitions and compositions algorithm. I have reposted the k partitions algorithm and started work on the integer partitions module. Currently we can compare two integer partitions based on the concept of majorizing which says that a partition majorizes another if the first k sum of its elements is greater than the first k sum of the other’s elements for all k > 0.

More stuff coming up…

]]>

This blog is intended to chronicle what I perceive is going to be an awesome summer. I have been selected in the GSoC program for the 2011 edition under Sympy. My task this summer will be to implement a combinatorics package.

More details to follow.

]]>