Hi John! On 19 Mai, 23:25, John Palmieri <jhpalmier...@gmail.com> wrote: > Suppose I want to define a new algebra in Sage. What should I do? > > - I have followed the nice coercion docs in the reference manual, and > in particular, I've set up _add_, _mul_, etc.; and also > _coerce_map_from_ and _element_constructor_. > > - Should I do anything with the new categories framework? I've > defined a "category" method for the algebra, but should I do anything > else?
In order to use the full machinery, you should define a "construction functor" (assuming that your construction is functorial). Look at sage.categories.pushout, and while you are at it, you could review the docs and bug fixes that I provided for it at #8800 and #8807... I'd describe it like this: - define a subclass of sage.categories.pushout.ConstructionFunctor. In the init method, you must indicate the categories on which the functor acts, by Functor.__init__(self,Rings(),Rings()) for example. - If #8807 gets accepted, you have to define a _apply_functor method (it tells what your construction does with objects) and perhaps a _apply_functor_to_morphism method (it yields induced homomorphisms). Without #8807, you need to define a call method for the objects, and can forget about the morphisms (so, you wouldn't get a mathematical functor)... - Your new algebra class needs to have a construction() method: It returns a pair (F,R), where F is an instance of your construction functor, and R is an object, so that F(R) yields your algebra. Example: QQ.construction() yields (FractionField, ZZ). - Each construction functor has a rank: When trying to find the pushout of two parent structure constructions, the construction with the lower rank is applied first. Example: The FractionField functor has lower rank than the PolynomialFunctor. By consequence, the pushout of ZZ['x'] and QQ is QQ['x'] and not FractionField(ZZ['x']). So, choose the rank carefully (it may coincide with the rank of an existing functor)! - You may define a "merge()" method. It may combine two concurrently applied functors into one, inside the pushout construction (it will only be used if two functors have the same rank). Typically, this would be used if your construction has different implementations (e.g., dense versus sparse); the merge() method would tell what implementation should be used in the pushout. This is why one can add a dense and a sparse matrix. - You may define a "commutes()" method. Namely, if in the pushout construction two functors of the same rank concur and don't merge, then Sage would complain since it can't find a unique pushout. But if you assert that the two functors commute then uniqueness is granted. I don't know of a good example: FractionField and Completion do commute mathematically, but they have different rank, so it doesn't matter for the pushout. And that's it, unless you want to do something very special (like overloading the mul method or using an expand method)! This is sufficient to do arithmetic relating your new algebra class and another (existing or future) parent structure. Cheers, Simon -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org