
Christian Bauer wrote:
- It is legal to say degree(sqrt(2)*x).
Yes.
But then it would be useful to precisely characterize the class of expressions e and x such that degree(e, x) is well defined.
Is this possible? There might be terms sqrt(x) in e that cancel each other after some transformations, so while the input expression might logically be a polynomial, it is syntactically not.
I perfectly agree. In fact, what we are looking for is a _syntactic_ characterization of those GiNaC expressions for which degree, ldegree, coeff, tcoeff and lcoeff are guaranteed to give the right result.
But this is the intended behavior: If e is of the form e = sum(i=n1..n2, a_i * x^i) with n1, n2 integer and expressions a_i that satisfy has(a_i, x) == false, then degree(e, x) and ldegree(e, x) are well defined and accurate.
I think this should even cover cases like
degree(sin(y)^3-sin(y),sin(y))
which is guaranteed to return 3.
This is one possible syntactic characterization. Is this the one that the authors of GiNaC would like to adopt as _the_ definition of the syntactic domain where degree() and friends return a sensible result? Moreover, when degree() is called on something outside this domain, wouldn't it be better to throw an exception instead of returning with a value obtained in an undocumented way? Providing a function checking whether a given expression is inside the syntactic domain would also be useful (yes, we have been bitten by this kind of problem ;-) What do you think?
Roberto
participants (1)
-
Roberto Bagnara