Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coercion map should depend on the signature of the arguments #16054

Open
tscrim opened this issue Apr 3, 2014 · 2 comments
Open

Coercion map should depend on the signature of the arguments #16054

tscrim opened this issue Apr 3, 2014 · 2 comments

Comments

@tscrim
Copy link
Collaborator

tscrim commented Apr 3, 2014

The problem is the signature doesn't match the domain, so the incorrect conversion map is being called.

More specifically, I have an algebra (with a basis) where I want to be able to construct elements from the input of (R, R, R). However it errors out because it's trying to apply the natural coercion from the base ring into my algebra.

class Foo(Parent):
    def __init__(self, R):
        Parent.__init__(self, base=R, category=AlgebrasWithBasis(R))
    def _element_constructor_(self, *args):
        return self.element_class(self, *args)
    class Element(Element):   # Remember to import Element in the command line
        def __init__(self, parent, *args):
            Element.__init__(self, parent)
            self.value = args
        def _repr_(self):
            return "bar: {}".format(self.value)

So try:

sage: F = Foo(ZZ)
sage: F._element_constructor_(1, 2, 3)
bar: (1, 2, 3)
sage: F(1, 2, 3)
...
TypeError: Underlying map <type 'instancemethod'> does not accept additional arguments

Really I'm wanting a (conversion) map from R x R x R to my algebra.

Note that F(1) goes into an infinite loop because I haven't defined a one() method, nor multiplication.

CC: @vbraun @nbruin @nbruin @simon-king-jena

Component: coercion

Keywords: algebras, base ring

Issue created by migration from https://trac.sagemath.org/ticket/16054

@tscrim tscrim added this to the sage-6.2 milestone Apr 3, 2014
@tscrim tscrim self-assigned this Apr 3, 2014
@nbruin
Copy link
Contributor

nbruin commented Apr 3, 2014

comment:1

If you want a conversion map from R x R x R, then you should call it with F( (1, 2, 3) ). I'd say the problem is that your signature isn't supported out of the box (and I don't think it should). If you want to support more liberal syntax for F(...) then you can implement it ad-hoc.

@tscrim
Copy link
Collaborator Author

tscrim commented Apr 3, 2014

comment:2

Actually I first wanted R x M for some other parent M. So F(3, (1,2)) (which is what my repr currently looks like) does not with the same error as above, but this works F((1, 2), 3) (because there is no coercion map in the first arg). I can reverse my repr order, but I prefer my current output.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants