On Sat, Oct 23, 2010 at 09:31:43AM -0700, Simon King wrote:
> On Oct 22, 11:40 am, "Nicolas M. Thiery" <Nicolas.Thi...@u-psud.fr>
> wrote:
> > > And do you have an idea of how the user can assert "X is finite/
> > > infinite/doesn't matter"? What about a method "X.assert(self,
> > > 'foo', value)" that creates an instance method X.is_foo returning
> > > the given value?
> >
> > Oops, I am confused: are you referring back to some email of mine for
> > the use case? If yes, can you point which one?
>
> I think I remember that at some point you wrote that it would be
> useful if the user could assert that a structure is finite or
> infinite, because this is difficult/impossible to detect
> algorithmically.
Ah, I see. I got confused, because I thought you meant ``assert`` as
in assertion tests in the code (which I use all the time):
assert X in FiniteEnumeratedSets()
> More generally: Assume that you have a property that is important for
> containment in a specific category, but is, in general, difficult to
> prove. Such as:
> 1) finiteness
> 2) commutativity
> 3) associativity
> 4) distributivity
> 5) ...
>
> For each of these properties, it might be the case that the user knows
> whether an object X satisfies the property. There already exist some
> "is_*" methods, such as "is_field", "is_commutative", "is_finite". But
> there is no standardised way to change the output of these methods
> after initialisation of X.
I think this is the perfect use case for the idiom:
X.update_category(FiniteSets())
X.update_category(Fields())
So far, when we encountered similar situations, we either declared
appropriately the category in the __init__ of the parent (requiring to
change the sources), or passed this category to the __init__ of that
parent (which must accept this optional argument). Of course, this
approach can only be used at the time the parent is constructed, and
the update_category idiom would be much better. Still, I have done a
lot of that lately:
semigroupe.Semigroup(..., category = JTrivialMonoids())
In fact, I have used this idiom quite a few times to add code to an
already implemented parent, by creating a fake category containing
that code (a bit of a hack, but very handy!).
> If you have a specialised algorithm for finite structures, then you
> could do
> if hasattr(self,'is_finite') and self.is_finite() is True:
> <specialised code>
> else:
> <generic code>
Just a side note: specialized algorithms for finite (resp. infinite)
structures should go in the FiniteBlah (resp. InfiniteBlah) category.
Cheers,
Nicolas
--
Nicolas M. Thi�ry "Isil" <nth...@users.sf.net>
http://Nicolas.Thiery.name/
On Sun, Oct 24, 2010 at 02:34:53PM -0700, Simon King wrote:
> As you may have noticed, I posted on sage-devel and asked if there is
> interest in the automatic dynamical update of categories, at the
> expense of slowing down "sage -testall -long" by 1.5%. I could imagine
> that many people wouldn't like to slow things down if the only gain is
> a generalisation of an abstract framework. But let us see what people
> think.
I have been overflowed by sage-devel lately, but I will have a look! I
would bet for a strong opposition, unless the slow down would only
concern code specifically using the feature.
> in either case, I think that a method "update_category" is non-
> controversial and clearly a missing feature. Using my experiences with
> *automatically* updating the category and subclassing both parent and
> element classes exploting the abc module, I would certainly be able
> to implement the update_category functionality (simply drop the word
> "automatically" in this sentence...).
Looking forward to that! This feature, especially combined with better
join treatment for Finite/Commutative/..., will be really powerful.
Cheers,
Nicolas
PS: by the way: the pushout construction mechanism does overlap much
with the "functorial constructions" in the categories
(Algebras/Subquotients/...). At some point, we will need to
investigate exactly how much they overlap, and devise plans to merge
the two features or at least make them interact smoothly. I know the
general principle of the pushout mechanism, but you have a much
stronger practical experience with it. Would you volunteer to start
this investigation?
As a first round, I just wanted to focus on having a clean
infrastructure on the category side, without having to worry about
backward compatibility.
> > I know the general principle of the pushout mechanism, but you
> > have a much stronger practical experience with it. Would you
> > volunteer to start this investigation?
> First I need to settle in Jena, were I will return next week.
Sure, that's a long term / no rush project! Thanks!
Cheers,
Nicolas