# what is sagemath equivalent to atomic type in Maple?

I am having hard time finding equivalent to atomic type in Maple to use in Sage for converting a function written in Maple to sagemath.

Here is description of what an atomic type is. Examples will make it more clear

type(1,'atomic');
true
type(1/2,'atomic');
true
type(.5,'atomic');
true
type(3+1/2*I,'atomic');
true
type(x+1/2*I,'atomic');
false
type("String",'atomic');
true
type(Name,'atomic');
true
type(a[b],'atomic');
true
type(a/b,'atomic');
false


In Mathematica, this is called AtomQ " yields True if expr is an expression which cannot be divided into subexpressions, and yields False otherwise."

Now, in sympy, the closest I found is is_Atom even though it is not exactly the same as Maple and Mathematica. In sagemath, the closest I found is expression.is_symbol() but this is also not exactly the same. Because I can't use it on variable of numeric type for example.

My question is, how does one check expression is atomic (in the above sense) in sagemath? I googled and not able to find such command. I am sure it is there somewhere since this basic command.

Thank you --Nasser

edit retag close merge delete

Sort by » oldest newest most voted

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,

more