is an option that specifies the heads of subexpressions into which a function may descend.
AllowedHeads
is an option that specifies the heads of subexpressions into which a function may descend.
Details
- Different functions use different default settings for AllowedHeads.
- Settings for the AllowedHeads option include:
-
Automatic default settings Inherited allow only Head[expr] All allow any normal expression head h allow only head h {h1,…} allow any of h1,… h1|h2|… treat the hi as interchangeable Full treat all normal expression heads as interchangeable - For AllowedHeads, a normal expression head is the head of an expression that is not AtomQ, Association or the head of a special array object such as SparseArray, NumericArray and QuantityArray.
- For functions such as Dimensions, the setting AllowedHeads->{h1,h2,…} requires that all elements at a given level have the same head. AllowedHeads->{…,g1|g2|…,…} allows any of the gi as heads at a given level.
Examples
open all close allBasic Examples (4)
Only consider nested expressions with head List:
ArrayDepth[f[f[1, 2, 3], f[4, 5, 6]], AllowedHeads -> List]By default, nested expressions with any head are considered arrays:
ArrayDepth[f[f[1, 2, 3], f[4, 5, 6]]]Only consider nested expressions with head List:
Dimensions[f[f[1, 2, 3], f[4, 5, 6]], AllowedHeads -> List]By default, rectangular nested expressions with any head are considered arrays:
Dimensions[f[f[1, 2, 3], f[4, 5, 6]]]Sum inside the outermost head:
Total[f[f[1], g[2π]], ∞, AllowedHeads -> Inherited]Total[f[f[1], g[2π]], ∞, AllowedHeads -> {f, g}]Scope (3)
By default, Total only sums inside list representations and associations:
Total[f[1, g[2π]], ∞]Sum inside several specific heads:
Total[f[1, g[2π]], ∞, AllowedHeads -> {f, g}]Total[f[1, g[2π]], ∞, AllowedHeads -> All]Total[g[f[1], g[2π]], ∞, AllowedHeads -> Inherited]Allow any head at each level of the array:
Dimensions[f[g[1, 2, 3], g[4, 5, 6]], AllowedHeads -> All]An array has a consistent head at each level:
Dimensions[f[g[1, 2, 3], h[4, 5, 6]], AllowedHeads -> All]Completely ignore heads, looking only at the tree structure of the expression:
Dimensions[f[g[1, 2, 3], h[4, 5, 6]], AllowedHeads -> Full]Treat the heads g and h as the same head:
Dimensions[f[g[1, 2, 3], h[4, 5, 6]], AllowedHeads -> {f, g | h}]Without this stronger equivalence, the expression is considered one-dimensional:
Dimensions[f[g[1, 2, 3], h[4, 5, 6]], AllowedHeads -> {f, g, h}]Applications (1)
Create a version of MatrixQ that only accepts list matrices:
matrixQ[m_] := Length[Dimensions[m, AllowedHeads -> List]] === 2Create several expressions to test:
listMat = {{a, b}, {b, c}};
symmetrizedMat = SymmetrizedArray[listMat];
vector = {a, b};
scalar = Sin[x];The function matrixQ gives True only for listMat, which both is a matrix and has head List:
matrixQ /@ {listMat, symmetrizedMat, vector, scalar}MatrixQ gives True for matrices of any known array type:
MatrixQ /@ {listMat, symmetrizedMat, vector, scalar}Properties & Relations (2)
Once a head is excluded, no nested expressions are tested against the value of AllowedHeads:
Total[f[{1, 2, 3}], ∞, AllowedHeads -> List]If both f and List are allowed, then the inner list is tested and summed:
Total[f[{1, 2, 3}], ∞, AllowedHeads -> {f, List}]The meaning of AllowedHeads->Automatic may vary from function to function:
Dimensions[BesselJ[0, 1], AllowedHeads -> Automatic]Total[BesselJ[0, 1], AllowedHeads -> Automatic]See Also
Text
Wolfram Research (2019), AllowedHeads, Wolfram Language function, https://reference.wolfram.com/language/ref/AllowedHeads.html (updated 2020).
CMS
Wolfram Language. 2019. "AllowedHeads." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/AllowedHeads.html.
APA
Wolfram Language. (2019). AllowedHeads. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AllowedHeads.html
BibTeX
@misc{reference.wolfram_2026_allowedheads, author="Wolfram Research", title="{AllowedHeads}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/AllowedHeads.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_allowedheads, organization={Wolfram Research}, title={AllowedHeads}, year={2020}, url={https://reference.wolfram.com/language/ref/AllowedHeads.html}, note=[Accessed: 13-June-2026]}