Skip to content

AtomQ

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

AtomQ[expr]

gives True if expr is an atomic object (Integer, Real, BigInt, Rational, Complex, Symbol, or String), and False if expr is a compound expression of the form head[...].

Examples (16)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (4)

In[1]:= StringQ["AbC"]
Out[1]= True

In[2]:= StringQ[""]
Out[2]= True

In[3]:= StringQ[123]
Out[3]= False

In[4]:= StringQ[] StringQ::argx: StringQ called with 0 arguments; 1 argument is expected.

Scope (6)

In[5]:= MachineNumberQ[Sin[1000.]]
Out[5]= True

Overflows to +inf

In[6]:= MachineNumberQ[Exp[1000.]]
Out[6]= False
In[7]:= MachineNumberQ[-29037945.290347]
Out[7]= True

MPFR, not machine

In[8]:= MachineNumberQ[N[Pi, 30]]
Out[8]= False
In[9]:= MachineNumberQ[1.0 + 2.0 I]
Out[9]= True

Exact Gaussian integer

In[10]:= MachineNumberQ[1 + 2 I]
Out[10]= False

Applications (6)

Integers are atoms

In[11]:= AtomQ[5]
Out[11]= True

So is a bare symbol

In[12]:= AtomQ[x]
Out[12]= True

A Rational is treated as atomic

In[13]:= AtomQ[1/2]
Out[13]= True

And so is a Complex

In[14]:= AtomQ[3 + 4 I]
Out[14]= True

A Plus has parts, so it is not an atom

In[15]:= AtomQ[1 + x]
Out[15]= False

A list is a List expression, not an atom

In[16]:= AtomQ[{1, 2, 3}]
Out[16]= False

Implementation notes

builtin_atomq (src/core.c) returns True for any non-EXPR_FUNCTION node (integers, reals, bigints, symbols, strings) and for the two function heads Mathilda treats as atomic, Rational and Complex; every other EXPR_FUNCTION yields False.

Attributes: Protected.

References

See also: NumberQ, IntegerQ, StringQ, MachineNumberQ, Complex, ExactNumberQ

Notes & additional examples

Notes

AtomQ[e] is True exactly for the expressions with no subparts: integers, bigints, reals, symbols and strings, plus the two compound heads Mathilda treats as atomic, Rational and Complex. Every other f[...] is False.

AtomQ is the complement of "has a head you can take Parts of". It never returns unevaluated — the answer is a structural property of the already-evaluated argument.