Adding new attribute to Poset

25 views
Skip to first unread message

pong

unread,
Sep 28, 2020, 12:29:43 PM9/28/20
to sage-support
For convenient, I would like to add an attribute, upper_bounds, to Poset objects

However, after writing the method and issue
Poset.upper_bounds = upper_bounds

X.upper_bounds(S) complains

'FinitePoset_with_category' object has no attribute 'upper_bounds'

When I try
FinitePoset_with_category.upper_bounds = upper_bounds

I got
name 'FinitePoset_with_category' is not defined

So how can one add an attribute to FinitePoset_with_category?

Eric Gourgoulhon

unread,
Sep 28, 2020, 2:38:15 PM9/28/20
to sage-support
Poset is a function, which constructs a finite poset, not the poset class, as you can check:
sage: type(Poset)
<class 'function'>
You can also check it by having a look at the source code:
sage: Poset??

So when you write
Poset.upper_bounds = upper_bounds
you are attaching upper_bounds to the function, not to the class of posets. The latter is FinitePoset (actually a subclass of it, name FinitePoset_with_category, which is constructed dynamically via Sage category mechanism). So you should do

sage: from sage.combinat.posets.posets import FinitePoset
sage: FinitePoset.upper_bounds = upper_bounds

Then
sage: X = Poset(...)
sage: X.upper_bounds(...)
shoud work.

pong

unread,
Sep 29, 2020, 12:44:28 AM9/29/20
to sage-support
Thanks Eric. It works!

I figured out the FinitePoset part after reading the manual. But I know test that it works for X = FinitePoset(...)
I didn't think of trying it with X = Poset(...).
Reply all
Reply to author
Forward
0 new messages