#10963: More functorial constructions
-------------------------------------+-------------------------------------
Reporter: nthiery | Owner: stumpc5
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-6.1
Component: categories | Resolution:
Keywords: days54 | Merged in:
Authors: Nicolas M. Thiéry | Reviewers: Simon King, Frédéric
Report Upstream: N/A | Chapoton
Branch: | Work issues:
public/ticket/10963 | Commit:
Dependencies: #11224, #8327, | ec340363a811bbafbb8cd5ff8f39e75db9872f9f
#10193, #12895, #14516, #14722, | Stopgaps:
#13589, #14471, #15069, #15094, |
#11688, #13394, #15150, #15506 |
-------------------------------------+-------------------------------------
Comment (by nthiery):
Hi Simon, Nils, Volker,
When designing infrastructure, one of my main guiding principle is to
strive hard to get concise, expressive, redundancy free idioms. In
particular, I believe that a bit of well localized black magic in the
infrastructure is acceptable if it avoids redundancy in many places in
the code using that infrastructure. Trading uglyness in one spot for
beauty in many. For example ClasscallMetaclass is definitely ugly
black magic, but I believe it was the price to pay for the nice
UniqueRepresentation idiom.
Now, in the case at hand, is this going overboard?
Here are some necessary conditions that should be satisfied:
(1) The black magic should be robust.
(2) The black magic should be well documented.
(3) The black magic should be transparent to the casual user; that is
it should be invisible most of the time, and when it appears on
the surface, it should be easy to understand what it does without
understanding the implementation details.
(4) In particular, in case of error, the black magic should raise
clear enough messages.
(5) There should be a couple developers that understand the
implementation details.
(6) It should be worth it :-)
Let's take those points one by one.
(1,5) Well, hopefully this is now the case :-)
Thanks so much and congratulations for your work on this! The
recursion triggered by an assertion check was really a tricky
one.
(2) Granted, this is not yet up to speed. In general there is no
documentation yet on how axioms work, and this should definitely
be fixed. I created the follow up #15643 for this.
(3) From the feedback I got from users / implementers of axioms, this
seems to be not so bad.
(4) This is hopefully better now. See below.
(6) the guesswork is currently used in roughly 20 categories:
{{{
mistral>grep -L base_category `grep -l "^class.*CategoryWithAxiom" *.py` |
wc -l
20
}}}
I expect this number to increase much with time, as more and more
categories with axioms are added. The existing followup code in the
Sage-Combinat queue adds at least as many.
About Simon's issue with interactively creating categories with axiom.
The error message was confusing; it is in fact possible; one just need
to specify _base_category_class_and_axiom if the guessing does not
work:
{{{
sage: class Cs(Category):
....: def super_categories(self): return [Sets()]
sage: class Ds(CategoryWithAxiom):
....: _base_category_class_and_axiom = [ Cs, "Finite" ]
sage: Cs.Finite = Ds
sage: Cs.Finite = Ds
sage: Ds()
Category of ds
sage: Ds().super_categories()
[Category of finite sets, Category of cs]
}}}
In an upcoming commit, I improved the error message and also the
logic: for the guessing to work, only the base category needs to be in
the standard location, not the category with axiom itself. So now one
can do:
{{{
sage: class FacadeSemigroups(CategoryWithAxiom):
....: pass
sage: Semigroups.Facade = FacadeSemigroups
sage: FacadeSemigroups()
Category of facade semigroups
}}}
Thanks Simon for pointing those deficiencies!
Altogether, I think it's worth keeping the feature. The implementation
is definitely disputable and any further improvement is more than
welcome: simplified logic, better error handling, documentation, ...
But maybe we can consider it good enough for now.
Cheers,
Nicolas
PS: about Python's Zen about guessing: I believe this is more about
human guessing rather than computer heuristics; but that might be just
my interpretation!
--
Ticket URL: <http://trac.sagemath.org/ticket/10963#comment:313>
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/groups/opt_out.