Closed tscrim closed 8 years ago
Great job! Two things, though:
_Key
by something more readable: Helper class to serve as a key for comparing elements of the
lattice.
The change-of-basis morphisms between the bases of the
:class:`MoebiusAlgebra` are triangular with respect to the partial
order of the poset. Since this partial order might not agree with
the standard comparison function ``cmp``, we need a wrapper around
the elements of the lattice which ensures that calling ``cmp`` on
them (when wrapped) actually compares them using the lattice's
partial order. This helper class is precisely that.
(You probably can do better.)
module_morphism
infrastructure does to key
allows key
to live in a poset? I see leading_item
being called in https://github.com/sagemath/sage-prod/blob/develop/src/sage/modules/with_basis/morphism.py ; what does this return when there are several maximal items?Branch pushed to git repo; I updated commit sha1. New commits:
499bbe6 | Addressing Darij's comments. |
Thank you for looking at this.
I made that a lot shorter because (IMO) this class does not deserve any real documentation because it is hidden from the doc and never exposed to the user. You are only going to see this if you are looking at the code, but it is clear from the code what this class does. I feel it is just an implementation detail because of how we handle posets.
There is only one maximal element because the Möbius algebra is only defined for lattices.
?
I'm talking about leading terms of elements in the lattice algebra. Those can easily have multiple "leading" terms.
We don't care, it just does reduction and the triangularity guarantees the invertibility.
OK, I am still unconvinced of any guarantees, but that's probably the best I can do without knowing the module_morphism code (I'm not sure I ever did, for all the doc edits I made on that file). But in the worst case, it will just throw errors or endless-loop on methods which would otherwise just be not implemented; so there's no harm done here (and if there was, it would have been done by #21054, not by this ticket).
Sorry for my lack of faith in anything Sage lately... your code is good, that's not the issue.
It's okay, and skepticism is good. As I understand it, the triangular module morphism code will not throw errors or result in endless loops here because it is only used for computing the inverse, which uses the triangularity, something the theory guarantees. Can I count this as a positive review, or do you think we need more discussion?
See my comment on the previous ticket: maybe it's not needed to have a class for this. Well, maybe it is if we want the morphism to be picklable.
Oops, yes, I forgot to say: it's a positive review, if the tests pass.
@
Nicolas: out of curiosity, why does a key class make morphisms picklable, but a custom cmp doesn't?
@tscrim: it's also used for computing preimages, for example. Though, as I said, I'm fine with all sorts of bad behavior short of wrong results here, because these would be NotImplementedErrors without the triangularity parameters.
Branch pushed to git repo; I updated commit sha1. New commits:
872f3c0 | Fixing pickleability for Moebius algebra morphisms. |
The reason why it doesn't pickle is because lambda functions don't pickle. I've fixed this by adding a method to the category. However, I have uncovered a very subtle bug with pickling of the module morphisms with cached methods, see #21133. All tests pass for me.
Patchbot passes all tests as well. Positive review?
As far as I'm concerned, yes, positive_review. Nicolas, any objections?
Reviewer: Darij Grinberg
Ping, Nicolas?
Sorry, I am about to take off for vacations and was busy with preparation. I just had a look at the code. I believe the key function, should really just be an ranker according to the default linear extension. Luckily, I just remembered that we already had rankers as a picklable object:
sage: key = sage.combinat.ranker.rank_from_list(['a', 'b', 'c'])
sage: key('b')
1
sage: loads(dumps(key))
{'a': 0, 'c': 2, 'b': 1}
sage: key == loads(dumps(key))
True
Branch pushed to git repo; I updated commit sha1. New commits:
56e4fb3 | Using the Hasse diagram's promise that 0..n is a linear extension. |
That actually gave me a good idea, where we can use data from the poset. In particular, we have _element_to_vertex
and the promise that [1..n]
is a linear extension of the HasseDiagram
. Unfortunately using (the [marginally] faster) _element_to_vertex_dict.__getitem__
didn't want to unpickle. Anyways, this is a much better solution than what I had before.
OOps, I completely forgot about this one! Yeah, you found the best possible solution. Great job!
Changed branch from public/combinat/moebius_algebra_basis_keys-21122 to 56e4fb3
This can cause subtle bugs with comparisons between wrapped elements of a poset, which might not be given by the poset. We fix this and the triangularity issue that was hacked around in #21054, which introduced this problem.
See the discussion on #21054.
Depends on #21054 Depends on #21043
CC: @sagetrac-sage-combinat @nthiery @darijgr
Component: combinatorics
Keywords: poset
Author: Travis Scrimshaw
Branch/Commit:
56e4fb3
Reviewer: Darij Grinberg
Issue created by migration from https://trac.sagemath.org/ticket/21122