Re: [sage-devel] `ModuleElement` is forced though `Element` should be enough by the category framework

2019-02-27 Thread Kwankyu Lee


On Wednesday, February 27, 2019 at 3:26:08 PM UTC+9, Jeroen Demeyer wrote:
>
> On 2019-02-26 23:44, Kwankyu Lee wrote: 
> > It could be possible to hammer the coercion model to behave more nicely 
> > with the category framework, at least with respect to the issue that I 
> > raised. 
>
> By the way, why is it an issue in the first place? Is there any reason 
> why you don't want to inherit from ModuleElement? 
>

No. I was just annoyed several times by my failed attempts to implement 
scalar multiplication using Element. 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] `ModuleElement` is forced though `Element` should be enough by the category framework

2019-02-26 Thread Jeroen Demeyer

On 2019-02-26 23:44, Kwankyu Lee wrote:

It could be possible to hammer the coercion model to behave more nicely
with the category framework, at least with respect to the issue that I
raised.


By the way, why is it an issue in the first place? Is there any reason 
why you don't want to inherit from ModuleElement?


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] `ModuleElement` is forced though `Element` should be enough by the category framework

2019-02-26 Thread Kwankyu Lee


On Wednesday, February 27, 2019 at 7:06:42 AM UTC+9, Jeroen Demeyer wrote:
>
> On 2019-02-26 21:53, Jeroen Demeyer wrote: 
> > I think that you are 100% right but that (as with many things) it is the 
> > way it is for historical reasons and it hasn't bothered anyone 
> > sufficiently much to change it. 
>
> Part of the reason why I haven't personally touched _lmul_/_rmul_ (while 
> I did change many other things in the coercion model) is that I never 
> really understood how _lmul_/_rmul_ are supposed to behave precisely. 
>

It could be possible to hammer the coercion model to behave more nicely 
with the category framework, at least with respect to the issue that I 
raised. But I fear that doing it without the overall precise understanding 
of the systems would somehow break them someway. It seems to me if you 
wouldn't do it, no one dares :-)

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] `ModuleElement` is forced though `Element` should be enough by the category framework

2019-02-26 Thread Jeroen Demeyer

On 2019-02-26 21:53, Jeroen Demeyer wrote:

I think that you are 100% right but that (as with many things) it is the
way it is for historical reasons and it hasn't bothered anyone
sufficiently much to change it.


Part of the reason why I haven't personally touched _lmul_/_rmul_ (while 
I did change many other things in the coercion model) is that I never 
really understood how _lmul_/_rmul_ are supposed to behave precisely. 
And there are some strange things, especially the "return None if not 
implemented" part. So the only way to know whether _lmul_ is implemented 
is to actually call it and look at the result, which is a bit weird.


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] `ModuleElement` is forced though `Element` should be enough by the category framework

2019-02-26 Thread Jeroen Demeyer

On 2019-02-26 14:44, Kwankyu Lee wrote:

My question is: why should I use `ModuleElement` instead of just `Element`?

If I use `Element`, the scalar multiplication is not detected by the
coercion system. So I am forced to use `ModuleElement`.

Since my parent is in the category of modules over QQ, then I think
elements of the parent should be automatically treated as module
elements, and using `Element` should just be ok.

What do you think?


I think that you are 100% right but that (as with many things) it is the 
way it is for historical reasons and it hasn't bothered anyone 
sufficiently much to change it.


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] `ModuleElement` is forced though `Element` should be enough by the category framework

2019-02-26 Thread Kwankyu Lee
Hi,

I am defining a parent and elements in the category of modules over QQ. The 
proper way would be to use the category framework:

from sage.structure.parent import Parent
from sage.structure.element import ModuleElement

from sage.categories.modules import Modules

class MElement(ModuleElement):

def __init__(self, parent, x):
ModuleElement.__init__(self, parent)

self._x = x

def _repr_(self):
return 'element {}'.format(self._x)

def _rmul_(self, e): # defines scalar multiplication
R = self.parent()
return R.element_class(R, e * self._x)

class M(Parent):
Element = MElement
def __init__(self):
Parent.__init__(self, base=QQ, category=Modules(QQ))

Then the following works fine:

sage: P = M()
sage: five = P.element_class(P, 5); five
element 5
sage: 2 * five
element 10

My question is: why should I use `ModuleElement` instead of just `Element`? 

If I use `Element`, the scalar multiplication is not detected by the 
coercion system. So I am forced to use `ModuleElement`.

Since my parent is in the category of modules over QQ, then I think 
elements of the parent should be automatically treated as module elements, 
and using `Element` should just be ok. 

What do you think? 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.