ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 17 Apr 2016 14:49:52 +0200Coercion on continued fractionshttps://ask.sagemath.org/question/33131/coercion-on-continued-fractions/Currently, when user types
sage: x = continued_fraction(pi)
sage: y = 3*x
an TypeError is raised saying
TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and '<class 'sage.rings.continued_fraction.ContinuedFraction_real'>'
I understand that Sage tries to find common parent of Integer element and `ContinuedFraction_real` and fails. It seems that continued fractions in Sage are not implemented as elements of any particular field, and are derived directly from `SageObject`.
I am implementing an algorithm for arithmetical operations on continued fractions. Is it possible to make Sage call a particular method when the user tries to perform an arithmetical binary operation, where one of the operands is a continued fraction?
I have found those [1](http://doc.sagemath.org/html/en/reference/coercion/index.html#methods-to-implement), [2](http://doc.sagemath.org/html/en/reference/coercion/sage/structure/coerce.html), [3](http://doc.sagemath.org/html/en/tutorial/tour_coercion.html) links, but it seems that the topic of coercion is rather extensive and I don't know what to look for, as I don't know what the correct solution to the problem is.
Thank you for any response!mirgeeSun, 17 Apr 2016 14:49:52 +0200https://ask.sagemath.org/question/33131/