1 | initial version |
This is more complex to test in Sage than in Maple or Sympy, because "atomic" elements can belong to various classes. Furthermore, defining what is "atomic" isn't obvious in some cases...
You can test if a Sage object belongs to SR, then test if its operator
is None
, test if its belongs to a "basic" (to be defined...) ring of Sage of if it is one of the generators of its parent. But this does not exhausts the possibilities: in fact, you would have to define what is an "atomic element" for each possible category of your element...
A very rough sketch, catching only a few possibilities, could be:
def is_atomic(u):
if u.parent() is SR:
return u.operator() is None
if u.parent() in (ZZ, QQ, AA, QQbar):
return u in u.parent() # Should always return True
if hasattr(u.parent(),"base_ring") and hasattr(u.parent(),"gens"):
return u in u.parent().base_ring() or u in u.parent().gens()
return False
sage: is_atomic(x)
True
sage: is_atomic(x^2)
False
sage: R1.<t>=PolynomialRing(QQ)
sage: is_atomic(t)
True
sage: is_atomic(t^2)
False
sage: is_atomic(R1(17))
True
OTOH, other possible definitions could be more useful ; for example, for univariate polynomials, is_term
could be more useful ; similarly, picking apart a polynomial via list
might offer other possibilities.
HTH,