ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 26 Dec 2019 14:23:46 +0100what is sagemath equivalent to atomic type in Maple?https://ask.sagemath.org/question/49179/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](https://www.maplesoft.com/support/help/Maple/view.aspx?path=type/atomic) 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](https://reference.wolfram.com/language/ref/AtomQ.html) "
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
--NasserWed, 25 Dec 2019 07:41:47 +0100https://ask.sagemath.org/question/49179/what-is-sagemath-equivalent-to-atomic-type-in-maple/Answer by Emmanuel Charpentier for <p>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.</p>
<p>Here is <a href="https://www.maplesoft.com/support/help/Maple/view.aspx?path=type/atomic">description</a> of what an atomic type is. Examples will make it more clear</p>
<pre><code>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
</code></pre>
<p>In Mathematica, this is called <a href="https://reference.wolfram.com/language/ref/AtomQ.html">AtomQ</a> "
yields True if expr is an expression which cannot be divided into subexpressions, and yields False otherwise."</p>
<p>Now, in sympy, the closest I found is <code>is_Atom</code> even though it is not exactly the same as Maple and Mathematica. In sagemath, the closest I found is <code>expression.is_symbol()</code> but this is also not exactly the same. Because I can't use it on variable of numeric type for example.</p>
<p>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.</p>
<p>Thank you
--Nasser</p>
https://ask.sagemath.org/question/49179/what-is-sagemath-equivalent-to-atomic-type-in-maple/?answer=49208#post-id-49208This 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,
Thu, 26 Dec 2019 14:23:46 +0100https://ask.sagemath.org/question/49179/what-is-sagemath-equivalent-to-atomic-type-in-maple/?answer=49208#post-id-49208