On Fri, May 22, 2009 at 5:18 AM, John Cremona <john.crem...@gmail.com> wrote:
> 2009/5/22 Gonzalo Tornaria <torna...@math.utexas.edu>:
>> Sometimes I wish there was a standard/uniform way to code the frontend
>> for a multiple-implementation function in such a way that
>>
>> (a) introspection knows about it, so e.g. "function??" shows the
>> actual code for the default implementation, and it's also easy to get
>> the actual code for the other implementations.
>
> This can be done if the implementation are in different sub-functions
> (maybe with underscore prefixes, and suffixes equal to "_" +
> "algorithm").

Yes, but usually those are not exported, hence it's not that easy to
get to the source code. And not all the functions are necessarily
implemented in this way.

>> (b) doctesting can be improved based on that (e.g. doctests are run
>> with algorithm="all", without need to repeat).
>
> Not all functions with algorithm parameters allow "all" and do a
> comparison.  Should they?  (Omitting those which require optional
> packages, of course).

Using algorithm="all" may not always work; in fact it could be that
different "algorithms" have different ranges of application. What I'm
just saying is that it would be nice if some doctests actually mean
"test all the algorithms", while some mean "test just this particular
algorithm".

>> (d) in case there is a better implementation which depends on optional
>> packages or tables, it becomes default when the required optional
>> package is installed.
>
> That happens to some extent already -- e.g. if you ask for the
> generators of an elliptic curve in my database, it does a look-up if
> the database is installed and otherwise computes them.  This is
> probably left to be handled  case-by-case.

Yes, it's just that case-by-case sometimes mean that the
implementation details may differ a little bit, or diverge over time.
In fact, the code for gens doesn't know if the database is installed
or not. It just tries, and backs up to a computation in case this
fails (which is quite sensible, but adds overhead).

But to my point, in this case
{{{
E = EllipticCurve("389a")
E.gens??
}}}
does actually show the source code for all the "algorithms", which are
all in the same function body. But they are mixed up with the logic
for actually choosing the algorithm, so it's not "nice".

Gonzalo

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to