Older blog entries for fxn (starting at number 415)

7 Nov 2005 (updated 7 Nov 2005 at 16:25 UTC) »

Generation of Derangements

One of the current threads for the evolution of Algorithm::Combinatorics is researching the generation of derangements (i.e., permutations with no fixed points).

Looks like derangements are hard to generate efficiently. The most promising reference I've found by now is this paper from 2004 by James F. Korsh, and Paul S. LaFollette, Constant time generation of derangements.

Unfortunately I have not been able to find a copy online, so I wrote to the authors today asking whether it can be obtained somehow.

6 Nov 2005 (updated 6 Nov 2005 at 13:53 UTC) »

Algorithm::Combinatorics

Several things happened since the last diary entry:

  • I simplified the C code in some places and rewrote variations() which is now almost twice as fast and does not create SVs. With this modification the C code works completely in-place in all the subroutines.
  • Aaron Dalton is going to maintain a FreeBSD port of the module. Reported some problems compiling with 5.6.2 that got fixed. Thank you dude!
  • Googling for algorithms I came across a PDF draft of Knuth's The Art of Computer Programming, Volume 4, Fascicle 2: Generating All Tuples and Permutations and so I edited permutations() to match Algorithm L. The third fascicle is about combinations and partitions, so looks like I am gonna spend a few bucks on these books.
  • I added a workaround to Makefile.PL for "No rule to make target ... needed by `pure_all'" so that the Makefile generated by Inline::MakeMaker's WriteInlineMakefile() works, and thus the C part behaves like a regular XS extension instead of generating caches on the user machine.

All in all, Algorithm::Combinatorics 0.10 is out.

Algorithm::Combinatorics

Now that the module is out and the first iterations are done we start polishing. I simplified the code and the tests (96 by now), improved the docs, and speeded up permutations. That's the just uploaded Algorithm::Combinatorics 0.07 (waiting in PAUSE right now).

The most important thing that needs to be done once the module is getting stable is to find fast algorithms that comply with the constraints of the interface: generating tuples in lexicographic order, and not using recursion (or recursion-like) approaches, memory usage has to be minimal to support iteration over sequences of arbitrary size. I changed yesterday the initial naive algorithm for permutations with this one, which is 3-4 times faster. The initial algorithm for variations is bad as well, that's the next target (any pointer?)

In addition, I may consider later to provide even faster algorithms relaxing the condition about ordering, which sometimes is not needed. Those could be provided in separated subroutines, say, permutations_fastest(). More sequences will be implemented as well, like derangements..

4 Nov 2005 (updated 4 Nov 2005 at 23:37 UTC) »

Algorithm::Combinatorics

When I thought the interface of Algorithm::Combinatorics I devised this usage in scalar context:

    my $iter = combinations(\@data, $k);
    while (my @c = $iter->next) {
        # ...
    }
and this one in list context:
    my @all_combinations = combinations(\@data, $k);

When I was done with the first release (a couple of days ago), I realized something was wrong. When $k is zero the empty list has to be returned, because the empty list is a subset of @data with size $k = 0 (you know, the rationale for n choose 0 = 1).

The problem is that in the while loop the condition is an assignment to an array in boolean context, which evaluates to false if the iterator returns the empty list. Thus there was no way to support $k = 0.

The first reaction was to rule that call out, to stick with the interface I would expect from such a module. But it was a wrong decision, no matter whether it is a corner case or not, it has to be supported because I would expect combinations (and the rest of subroutines) to return that empty list. Thus I changed the iterator to return always an arrayref:

    my $iter = combinations(\@data, $k);
    while (my $c = $iter->next) {
        # ...
    }
and released 0.05 tonight.
3 Nov 2005 (updated 3 Nov 2005 at 16:25 UTC) »

Algorithm::Combinatorics

I completed the implementation of the initial interface, wrote a test suite, and documented the module. The result was the first release of Algorithm::Combinatorics yesterday, with a followup today.

1 Nov 2005 (updated 1 Nov 2005 at 23:47 UTC) »

Algorithm::Combinatorics

I have been playing around with the Perl API via Inline::C. This is for my new pet module Algorithm::Combinatorics (work in progress).

Algorithm::Combinatorics is a generator of (lazy) combinatorial sequences written in XS. Having all the looping implemented in C speeds the iterators up by several orders of magnitude compared to the pure Perl Math::Combinatorics.

As of today I have chosen the interface, implemented combinations, combinations with repetition, and variations with repetition, as well as a handful of tests.

24 Oct 2005 (updated 24 Oct 2005 at 17:17 UTC) »

Semantic Web Demystified

I like this quotation from Tim Berners-Lee (read here):

Is this rocket science? Well, not really. The Semantic Web, like the World Wide Web, is just taking well established ideas, and making them work interoperability over the Internet. This is done with standards, which is what the World Wide Web Consortium is all about. We are not inventing relational models for data, or query systems or rule-based systems. We are just webizing them. We are just allowing them to work together in a decentralized system - without a human having to custom handcraft every connection.
22 Oct 2005 (updated 22 Oct 2005 at 11:19 UTC) »

There has been a heated debate in p5p around the problem in perlsub I reported. There are 57 messages in two parallel threads so far. The discussion is not over yet, but I have written today a summary.

Perl documentation patch

I have been exchanging impressions in several places about a corner in the documentation of perlsub which is not totally accurate. The part that explains what does a subroutine return when no return statement is found. I submitted a documentation patch with one of the possible fixes.

19 Oct 2005 (updated 19 Oct 2005 at 06:56 UTC) »

mathrick, hahaha.

Akira, that kind of questions can't be answered on the abstract. There's no universal less than operator that applies to dynamic languages, and I know a lot of Perl fellows that know Python and Ruby, no contradiction, if you restrict yourself to language X then it is a matter of time you become blind and biased.

I am more or less active in the Perl communtity, but my last pet project is being written in Python. Why? Because among other technical requirements I need something like subprocess. Fine, go with Python then.

Oh, and remember the differences are by design not by age. Perl and Python have both about 18 years. Ruby has about 12 years.

If you follow the evolution of Perl 6 you'll see the fundamentals of Perl's design are there because they are a choice. Of course there's nothing on earth that pleases everyone, that's why we have different languages. I know people who can't stand Python whitespace conventions, I know people who think Ruby ends up being too dense.

In the end you have preferences based on a mixture of technical needs, personal taste (which weights a lot and is subjective), and then practical stuff such as the languages your team actually know, etc.

406 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!