New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Count Number of Linear Extensions of a Poset #14126
Comments
comment:3
Patch does not apply and it's not clear why. |
comment:4
(this code should probably be stored in |
Author: aschilling, nthiery, hivert |
comment:5
Replying to @nathanncohen:
I've moved the code to |
comment:6
Well, shouldn't the two codes that compute the number of linear extensions be at the same place ?... A choice could be madebetween the two with an argument to Nathann |
comment:7
We originally made this function not aware that linear extensions had an iterator which would compute P.linear_extensions().cardinality() without computing all of P.linear_extensions(). In it's current form, I believe this code iterates over all linear extensions roughly same way the iterator does. So they should be approximately the same speed, and if this code is better, then those changes should be applied directly to the iterator. However, Stembridge's posets package is still much faster at counting linear extensions. He iterates over all linear extensions approximately the same way we do, but when you just want a count of linear extensions, he has separate code that counts maximal chains in J(P). There's a fast way to count chains that doesn't involve iterating over all of them. One might think computing J(P) is expensive, but one only needs to know the covering relations, and we could come up with a faster implementation than P.order_ideals_lattice() for this purpose (that method computes a poset whose elements are sets of elements in P, and we should be able to more quickly make an isomorphic poset on [1..n]). I think it's worth keeping this ticket open for development of this alternate way of counting linear extensions. Once we have a satisfactory implementation, we can change P.linear_extensions().cardinality() to call this special code for enumeration, rather than using the linear_extensions iterator. |
comment:8
But for what it's worth, I was successfully able to apply the latest version of the patch. |
comment:9
Replying to @nathanncohen:
Fair point. |
comment:10
Hellooooooooo !!
Oh. Right. So it builds all linear extensions then counts them
My understanding of categories is that when they prevent you from doing something you need then categories should be changed to allow you to do whatever you wanted to do in the first place. Technically I do not think that categories would mind an optional argument to .cardinality. I guess that they would not notice it, so that's all good. This being said, if you are at the Sage Days 45 right now Nicolas Thiery should be around. And he's THE guy you should bug for anything related to categories Nathann |
comment:11
Replying to @nathanncohen:
To be precise, for an object in FiniteEnumeratedSets, cardinality is
+1
Certainly: in any object oriented system, abstract classes are here to Categories are nothing but a way to organize those abstract classes. Cheers, |
comment:12
I will give |
comment:18
Replying to @kevindilks:
What is it? If there are several ways to do this, none of which is best from all sides, shouldn't we then have Is there something wrong with making a function with dumb implementation first? Then we would have a reference implementation, docstring and already thinked interface and place for the function. |
Branch: u/jmantysalo/count-lin-ext |
comment:26
?? Current version is written by me. (But of course it is trivial modification that just basically still counts all linear extensions.) |
comment:27
I was just cleaning a few invalid author fields. Please change it. |
Changed author from Anne Schilling, Nicolas M. Thiéry, Florent Hivert to Jori Mäntysalo |
comment:29
I am still intending on figuring out the 'right' way to do this. After recently realizing I can make the method be on the Hasse diagram, and can assume that I'm working with a naturally labelled poset on |
comment:30
I don't quite understand. AFAIK it is proved that counting linear extensions is in We can trivially reduce time by doing series-parallel decomposition first. It won't help on average. So do you have some good algorithm in mind? Being in |
comment:31
The The algorithm is used in Stembridge's Posets package. The general idea is that linear extensions are maximal chains in the lattice of order ideals. If you want to enumerate (not generate) maximal chains, then you can use fact that if f(x) is the number of saturated chains from a minimal element to x, then f(y) = sum f(x) over all x covered by y. If we wanted to keep the code simple, we could just create the lattice of order ideals However, there should be some wizardry that lets us quickly create a dictionary on This algorithm works whether or not P is connected. However, there would be some significant speed-up for posets with a large number of connected components if we just counted the number of linear extensions on each connected component, and combined the results appropriately (if f(P) is the number of linear extensions on P, and P=P_1 U ... U P_k , then f(P)= multinomial(|P|,{|P_1|,...,|P_k|}) * product f(P_i) . For example, say we look at the anti-chain of 11 elements. Currently, we have to iterate over close to 40 million permutations. Using the wizardry, we would just have to create a dictionary of 2048 elements corresponding to up-edges in the Boolean lattice and iterate over it. And if we split into connected components...getting 11! is almost automatic. |
comment:32
?? Isn't the concept of Of course there are easy answers for some posets. For the ordinal sum of But I will wait for the code and see. E: Something in lattice of ideals - but every ideal corresponds to an antichain, and counting antichains is in |
comment:33
Whatever it is, asymptotics aren't particularly relevant when in practice we're not going past |P|>100. Even without any wizardry, |
comment:34
Very interesting! Must think about this. And |
comment:35
This got more speed with even very basic implementation of maximal chains counting:
If we have better way to make a order ideals lattice, it is a place for new ticket. It would be nice feature in itself. Hmm... Assuming we have |
comment:36
I guess this is worth reading about order ideals lattice: http://www.sciencedirect.com/science/article/pii/S0166218X00002584 |
comment:37
After much staring at Maple code, I now mostly understand the algorithm to generate a naturally labelled poset isomorphic to the order ideal lattice given a naturally labelled poset. The idea is similar to what you mentioned. Run a loop that takes the lattice of order ideals for P restricted to Now, you create a list The main subtlety is in creating and maintaining a helper list that will eventually tell you where Since it might take me some time to actually sit down and implement this, I agree that it makes sense to just change the |
comment:38
Does that mean that |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:40
Shall we then accept this solution, and later think about optimizing this in two different ways? Series-parallel decomposition could be a good thing anyways. |
comment:41
Replying to @jm58660:
Yes. It probably makes sense to deprecate I guess I'd want to quantify how much overhead calculating connected components and a series-parallel decomposition of the original Hasse diagram introduces (my guess is a little and lot, respectively) before making it part of every single computation. I feel like unless you explicitly construct something as an ordinal/disjoint sum of smaller posets (and thus should already know the decomposition), almost every poset you'd throw at this where you'd really need optimal performance is going to be connected and not have a series-parallel decomposition. |
comment:42
Replying to @kevindilks:
That could be done now; a little less time for new users to learn a feature to be deprecated.
True, but then whole decomposition will be just one check to see that the poset can not be decomposed. And in any case that should a place for it's own ticket. |
comment:43
ok, looks good to me. |
Reviewer: Frédéric Chapoton |
Changed branch from u/jmantysalo/count-lin-ext to |
Posets appear to have no mechanism to count the number of linear extensions other than computing all the linear extensions and finding the length of that list. Using recursion, one can count the number of linear extensions without having to generate all the linear extensions.
CC: @kevindilks @jm58660
Component: combinatorics
Keywords: days45
Author: Jori Mäntysalo
Branch/Commit:
24bc331
Reviewer: Frédéric Chapoton
Issue created by migration from https://trac.sagemath.org/ticket/14126
The text was updated successfully, but these errors were encountered: