Argh. It was right when I wrote that documentation and implemented
the second version of the coercion model. :-) Whoever implemented
the third/fourth version(s) of the coercion model will I hope also
update the programming guide with correct statements (hint, hint
Robertwb).
-- william
Yep, sorry. Do we want this behavior? (This could be done without too
much trouble.)
- Robert
I consider the input of those *not* familiar with the model essential
in judging whether or not we have done anything sane.
> The absolute most important thing is that it be correctly documented.
Yes, and I am working on this. I am also adding much more
introspection into the model itself, like an "explain" method among
other things.
> After that, I would like the behavior to be predictable -- maybe I'm
> imagining it, but it seems that the current behavior might depend on
> the order in which various parents get cached.
Yes, that is correct. When it discovers the correct common parent for
a+b, it stores the result for b+a as well to save it work next time.
The only case where this may be ambiguous is if there is a map both
directions.
> Finally, I think that
> having the parent default to be the parent of the left factor (in the
> situation discussed in the documentation) seems pretty innocuous and
> is reasonable behavior.
Yes, I'll change this. I think the coercion model should act as if it
has no history (though it must cache things for speed), and this
seems like the most reasonable way to break symmetry.
- Robert
> I have several different vector space bases for an algebra A, and I
> have implemented this by having a class MyAlgebra, instances of which
> have an attribute _basis_name which is a string naming the basis. I
> have __cmp__ defined so that the basis is ignored: any two instances
> are canonically isomorphic, and there is good coercion between them.
>
> Now, the attribute _basis_name just affects the _repr_ and _latex_
> methods for elements of the algebra; it has no other effect.
I'd like to question this design. It seems odd to me to have two
different algebras which are identical except for how elements are
printed. In a sense, it would be like having different types
"int-base-10", "int-base-2", etc. for each way of printing an integer.
If I have an element of an algebra, I should request at the time I
convert to a string, which method of printing to use.
I realize that the attribute _basis_name is supposed to be a
convenience, but it does seem odd to have it.
Getting to your specific question about coercion, it appears that
this has to do with the difference between "is" and "==". And one
could argue that you shouldn't make things "==" if you care about
the differences between them.
Dan
Different ways of printing stuff is a common issue in Sage, and there
has been talk of creating a more unified framework to deal with this.
(David Roe has a lot of ideas, but I don't think he's had the time to
implement anything along these lines yet...) Of course sometimes
there's the question of different internal representations as well,
which probably merit different parents.
>> I realize that the attribute _basis_name is supposed to be a
>> convenience, but it does seem odd to have it.
>>
>> Getting to your specific question about coercion, it appears that
>> this has to do with the difference between "is" and "==". And one
>> could argue that you shouldn't make things "==" if you care about
>> the differences between them.
>
> In this situation, I'm viewing == as meaning 'canonically isomorphic',
> or something like that. If the only differences between two of these
> algebras are the input and output formats for elements, I think it's
> reasonable for them to be ==. That is, I'm viewing == as meaning that
> the only differences between them are not mathematical, but
> typographical. (Given my design choice, I suppose I can make the
> different algebras fail to be ==, but I must still have them coerce to
> each other, because that is mathematically what makes the most sense.
I think the default will be that there is an assumed coercion if two
objects are ==, but perhaps this should be overrideable? One must
also remember that == is used, for instance, for stuff like keys in
hash tables.
> If the coercion model worked as documented -- see the rest of the
> posts in the thread -- then the user could also predict the basis in
> which the answer is printed.)
Yep, it will...
- Robert
I like your current implementation too.
By the way, I'm really sorry it's taking so long for your code to get
fully refereed. I would just do it right now, to get it done, but I've
been so crazy busy this summer. I did install it into a branch on
my laptop though, so maybe I'll find time soon.
-- William
As am I (the person who was supposed to be doing it). Sorry it's been
so long. After this weekend I will have enough time to referee it.
David