On Fri, Nov 23, 2012 at 06:53:56PM -0800, Travis Scrimshaw wrote:
>    Hey everyone,
>       I just had an idea, and maybe this is more wishful thinking, but I feel
>    like we should be able to pass a poset/lambda function(s)/class which
>    contains comparison methods into a parent and have that be able to
>    override the default ordering (similar to what C++ does in the STL).
>    Something like this:
>        sage: g = DiGraph([(0,1),(0,2)]) 
>        sage: p = Poset(g)
>        sage: G = IntegerRingMod(3, ordering=p)
>        sage: G(0) < G(1)
>        True
>        sage: G(0) < G(2)
>        True
>        sage: G(1) < G(2)
>        False

Well, maybe not that much of a wishful thinking actually!

Define this category:

    class Blahs(Category):
        def super_categories(self): return [Rings()]
        class ParentMethods:
            def blah(self): print "blah"
        class ElementMethods:
            def blih(self): print "blih"
            def __lt__(self, other):
                 print "comparing!"

And create the ring in this category:

    sage: G = IntegerModRing(3, category=Blahs())
    sage: g = G.an_element()

Now you can do:

    sage: G.blah()
    blah
    sage: g.blih()
    blih

So in principle one could use that to provide comparison methods. Alas
this does not work completely, because there already is a comparison
method implemented in G which override that of the category:

    sage: g < g
    False

This also fails for partitions because they do not yet accept a
category parameter.

Cheers,
                                Nicolas
--
Nicolas M. ThiĆ©ry "Isil" <[email protected]>
http://Nicolas.Thiery.name/

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-combinat-devel?hl=en.

Reply via email to