On 2013-01-04, Simon King <simon.k...@uni-jena.de> wrote: > Hi Nathann, > > On 2013-01-04, Nathann Cohen <nathann.co...@gmail.com> wrote: >> --e89a8f6467594d8d3f04d276c2d8 >> Content-Type: text/plain; charset=ISO-8859-1 >> sage: p >> x^3 - 3*x >> sage: p.abs() >> ... >> AttributeError: >> 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' >> object has no attribute '__abs__' > > The abs() method is defined in sage.structure.element.RingElement. If
but why? not all rings have any meaningful abs().. Isn't is somthing that should be fixed? > that method makes sense for your specific class of ring elements, > implement a method __abs__. > >> sage: p.N() >> TypeError: unable to coerce to a ComplexNumber: <type >> 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'> > > p.N and p.n seem to be synonyms of p.numerical_approx and call some > function (not very object oriented...) in sage.misc.functional. > >> sage: p.additive_order() > > This is again in sage.structure.element.RingElement. > >> So if anybody knows where this comes from, and why an object has method >> that cannot be used.... :-P > > Well, it provides a general interface for typical tasks (in order to avoid > that the same functionality is provided by methods of different names in > different classes). I think it's useful, even though it means that some > methods > exist in a context in which they make no sense (and thus raise errors > when they are called). > > If you don't think that predefined method names are useful, then look at > polynomials: > sage: P.<t>=QQ[] > sage: t.leading_coefficient() > 1 > sage: P.<a,b>=ZZ[] > sage: a.lc() > 1 > sage: hasattr(a,'leading_coefficient') > False > sage: hasattr(t,'lc') > False > > That's why some people prefer to use a multivariate polynomial ring with > a single variable: > sage: P.<t> = QQ[] > sage: Q.<s> = PolynomialRing(QQ,1) > sage: P > Univariate Polynomial Ring in t over Rational Field > sage: Q > Multivariate Polynomial Ring in s over Rational Field > sage: hasattr(t,'lc') > False > sage: hasattr(s,'lc') > True > > Best regards, > Simon > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To post to this group, send email to sage-devel@googlegroups.com. To unsubscribe from this group, send email to sage-devel+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en.