AtomQ
范例
打开所有单元 关闭所有单元基本范例 (1)
范围 (6)
AtomQ["This is an atom"]AtomQ[ThisIsAnAtom]AtomQ[1.23]Rational 数显示具有复合结构:
FullForm[22 / 7]AtomQ[22 / 7]通过 Numerator和Denominator 可以访问这些部分:
{Numerator[22 / 7], Denominator[22 / 7]}Complex 数显示具有复合结构:
FullForm[1 + 2 I]AtomQ[1 + 2 I]{Re[1 + 2 I], Im[1 + 2 I]}SparseArray 对象为基元式原始对象:
s = SparseArray[{i_, i_} -> i, 3]AtomQ[s]用于 SparseArray 对象的指令通常像这样作用于所表示的数组:
a = Normal[s]s[[2, 2]]a[[2, 2]]一个 SparseArray 对象的 FullForm 被设计为足以重建原始对象:
FullForm[s]s1 = SparseArray[Automatic, List[3, 3], 0, List[1, List[List[0, 1, 2, 3], List[List[1], List[2], List[3]]], List[1, 2, 3]]]应用 (2)
leaves[expr_, OptionsPattern[]] := Block[{c = 0, cl, e},
cl[e_ ? AtomQ] := c++;
cl[e_] := Scan[cl, e, Heads -> OptionValue[Heads]];
cl[expr];
c];
Options[leaves] = {Heads -> True};e = Fold[f, x, Range[5]]leaves[e]它等价于 LeafCount:
LeafCount[e]使用可选项 Heads->False 只能计算不带分支的基元:
leaves[e, Heads -> False]它相当于用 TreeForm 看到的悬挂的叶:
TreeForm[e]depth[expr_] := Block[{mind = Infinity, maxd = 0, burrow},
burrow[e_ ? AtomQ, d_] := (mind = Min[d, mind];maxd = Max[d, maxd]);
burrow[e_, d_] := Scan[burrow[#, d + 1]&, e];
burrow[expr, 0];
{mind, maxd}]depth[1 + x + 2x ^ 2]depth[{{1, 2}, {3, 4}}]Depth 给出最大深度加1:
Depth[1 + x + 2x ^ 2]属性和关系 (1)
Map[f,expr,{-1}] 通常把 f 映射到 expr 中的基元上:
Map[f, 1 + x + 2x ^ 2, {-1}]mapf[e_ ? AtomQ] := f[e];
mapf[head_[args___]] := Apply[head, Table[mapf[arg], {arg, {args}}]]mapf[1 + x + 2x ^ 2]技术笔记
-
▪
- 表达式 ▪
- 限制模式 ▪
- 模式中的表达式类型限制 ▪
- 基本对象
历史
1988年引入 (1.0) | 在以下年份被更新:2003 (5.0)
文本
Wolfram Research (1988),AtomQ,Wolfram 语言函数,https://reference.wolfram.com/language/ref/AtomQ.html (更新于 2003 年).
CMS
Wolfram 语言. 1988. "AtomQ." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2003. https://reference.wolfram.com/language/ref/AtomQ.html.
APA
Wolfram 语言. (1988). AtomQ. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/AtomQ.html 年
BibTeX
@misc{reference.wolfram_2026_atomq, author="Wolfram Research", title="{AtomQ}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/AtomQ.html}", note=[Accessed: 07-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_atomq, organization={Wolfram Research}, title={AtomQ}, year={2003}, url={https://reference.wolfram.com/language/ref/AtomQ.html}, note=[Accessed: 07-August-2026]}