#17053: Add function for direct sum of posets
---------------------------------+-----------------------------
Reporter: jmantysalo | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: sage-wishlist
Component: combinatorics | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
---------------------------------+-----------------------------
Comment (by jmantysalo):
Something like this:
{{{
def sum_of_posets(self, other, labeling=None):
if not hasattr(other,'hasse_diagram'):
raise ValueError('The input is not a finite poset.')
if labeling==None:
# Check for duplicates. Slow, just for an example.
for i in self.list():
for j in other.list():
if i==j:
raise ValueError('What should be type of this error?')
elements=self.list()+other.list()
coverings=self.cover_relations()+other.cover_relations()
return Poset( (elements, coverings) )
if labeling=='linear':
return sum_of_posets(self.canonical_label(),
other.canonical_label().relabel(lambda x: x+self.cardinality()))
if type(labeling) is tuple and len(labeling)==2:
return Poset( ([(labeling[0],x) for x in
self.list()]+[(labeling[1],x) for x in other.list()],
[[(labeling[0],x[0]),(labeling[0],x[1])] for x in
self.cover_relations()]+[[(labeling[1],x[0]),(labeling[1],x[1])] for x in
other.cover_relations()]) )
raise ValueError("Labeling must be 'linear' or tuple of two elements")
}}}
For testing try for example
{{{
P1=Posets.PentagonPoset(facade=True).relabel(lambda x: x+10)
P2=Poset({0:[1,2],1:[3,4]})
sum_of_posets(P1, P2, labeling=('a', 'b')).show(figsize=4,
vertex_size=1000)
sum_of_posets(P1, P2, labeling='linear').show(figsize=4, vertex_size=1000)
sum_of_posets(P1, P2).show(figsize=4, vertex_size=1000)
sum_of_posets(P1, P1)
}}}
Another question: should ordinal sum be part of same function with keyword
like `type='ordinal'` or distinct function?
--
Ticket URL: <http://trac.sagemath.org/ticket/17053#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.