Ask Your Question
1

sage coercing subclass instance to superclass instance?

asked 0 years ago

JMacula gravatar image

I've created a subclass of the class 'sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field' so that I can run an implementation of the generalized Weil pairing (sage currently only has a built-in method for computing the weil pairing for a scalar endomorphism). My understanding is that when one creates a subclass, instances of that subclass should inherit all the methods of the superclass. However, when I define a point P on an elliptic curve E as an instance of the subclass I've created and then add that point to itself, sage returns to me an object of the superclass, 'sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field'.

I'm at a loss for why this is happening. Though my understanding of how Python works in general is limited, I believe that applying a superclass method to an instance of a subclass should yield another instance of the subclass.

I am happy to share my code if that would be helpful.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 0 years ago

I'm guessing that the _add_ method, inherited from the superclass, returns something lying in that superclass. I think the relevant method is EllipticCurvePoint._add_, and it contains lines like return E.point(...), where E.point(...) presumably is an instance of the superclass.

Preview: (hide)
link

Comments

Yes, that looks like what's happening. Since I don't really want to do anything other than extend the functionality of the ...EllipticCurvePoint_finite_field class, the best option might be for me to just modify the clone of the source code I have on my local machine. Thanks for chasing down what's happening in this superclass method.

JMacula gravatar imageJMacula ( 0 years ago )

You could define a new _add_ method for your class which calls the method for the superclass and then converts it to your class.

John Palmieri gravatar imageJohn Palmieri ( 0 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 0 years ago

Seen: 22 times

Last updated: Apr 11