Ask Your Question
0

what is sagemath equivalent to atomic type in Maple?

asked 2019-12-25 00:41:47 -0500

Nasser gravatar image

updated 2019-12-25 00:44:02 -0500

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-12-26 07:23:46 -0500

Emmanuel Charpentier gravatar image

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,

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-12-25 00:41:47 -0500

Seen: 34 times

Last updated: Dec 26 '19