Hi! On Wed, May 28, 2014 at 11:54:22AM +0200, Vincent Delecroix wrote: > Hi Christian, > > 2014-05-28 11:32 UTC+02:00, Christian Stump <christian.st...@gmail.com>: > >> It seems that actually nobody read my initial post on that thread... so > >> let me repeat > > > > I did -- but didn't really have any qualified contribution... > > > >> But the semantic has to be implemented at the level of maps not at the > >> level of methods. > > > > could you explain what you mean there (maybe using your example of the > > number of descents of a permutation). > > A method ( = a Python function) is not a Sage Map ( = a Python object > that model a mathematical function). I would like first to convert the > method into a map > {{{ > from sage.categories.map import Map > class NumberOfDescents(Map): > def __init__(self): > Map.__init__(Permutations(), NonNegativeIntegers()) > > def _call_(self, p): > return Integer(p.number_of_descents()) > }}} > The above example is already non-trivial since it specifies a domain > and a codomain (which is different from the parent of the image of an > element): > {{{ > sage: nod = NumberOfDescents() > sage: p = Permutation([3,2,1]) > sage: nod(p) > 3 > sage: nod(p).parent() is NN > False > }}} > The second step would be to think how to add semantic to the map. Part > of is already managed by the axioms/categories (for example a Morphism > between GradedSets preserve the grading). But there is nothing for > injectivity/surjectivity or more subtle properties.
For whatever it's worth: in MuPAD, it was possible to add type annotations on a method; typically to specify the domain and codomain: abs := proc(x: Dom::Integer): Dom::Integer begin return(x) end We were using this extensively for: - Dynamic type checking in debug mode - Retrieving the domain or codomain, typically when constructing new functions from existing ones (e.g. in module_morphism) - ... Python 3 will allow to add similar annotations. In the mean time we could possibly stuff such annotations to glorify methods: sage: def f(x): return abs(x) sage: f.domain=ConstantFunction(ZZ) sage: f.codomain=ConstantFunction(NN) sage: f(-3) 3 sage: f.domain() Integer Ring sage: f.codomain() Non negative integer semiring Anyway, just food for thoughts; it's not like there is a clear plan in this direction. Cheers, Nicolas -- Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-combinat-devel. For more options, visit https://groups.google.com/d/optout.