is an attribute that can be assigned to a symbol
to indicate that the function
should automatically be threaded over lists that appear as its arguments.
Listable
is an attribute that can be assigned to a symbol
to indicate that the function
should automatically be threaded over lists that appear as its arguments.
Details
- Listable functions are effectively applied separately to each element in a list, or to corresponding elements in each list if there is more than one list.
- Most built‐in mathematical functions are Listable. »
- All the arguments which are lists in a Listable function must be of the same length. »
- Arguments that are not lists are copied as many times as there are elements in the lists.
Examples
open all close allBasic Examples (4)
A Listable function threads over its list argument:
Attributes[f] = {Listable};
f[{1, 2, 3}]Log is listable:
Log[{a, b, c}]Attributes[Log]Listable functions combine corresponding elements:
{a, b, c} + {x, y, z}Arguments that are not lists are replicated as needed:
{a, b, c} + x{{a, b}, {c, d}} + xScope (4)
Define a function to be listable:
f[x_] := If[x > 0, Sqrt[x], Sqrt[-x]];
SetAttributes[f, Listable];f[{3, 0, -2}]Most built-in mathematical functions are listable:
Attributes[Power]{a, b, c} ^ {1, 2, 3}{a, b, c} ^ 5Listability works for any nesting depth of lists:
Sqrt[{{1, 2}, {3, 4}}]The nesting level of the different arguments need not be the same:
{{a, b}, {c, d}} ^ {2, 3}Listability works on other list-like constructs such as SparseArray:
SetAttributes[f, Listable]f[SparseArray[{1 -> E, 5 -> Pi}]]f[Association[1 -> 1, 5 -> 5]]Applications (2)
To apply a function to a vector, take advantage of Listable functions when possible:
v = RandomReal[1, 10 ^ 6];Use the listability of Plus, Power, Sin, and Times:
Timing[fvl = Sin[2 Pi (v - .5) ^ 2];]Use Map:
Timing[fvm = Map[Sin[2 Pi (# - .5) ^ 2]&, v];]Use Table:
Timing[fvt = Table[Sin[2 Pi (x - .5) ^ 2], {x, v}];]Use Table and Part to access elements of v as might be done in a lower-level language:
Timing[fvp = Table[Sin[2 Pi(v[[i]] - .5) ^ 2], {i, Length[v]}];]The results are the same up to numerical roundoff:
{Norm[fvl - fvm], Norm[fvl - fvt], Norm[fvl - fvp]}Use efficient sparse arithmetic to numerically solve the heat equation
:
n = 1000;
x = N[Range[0, n] / n];Matrix for a second-order approximation to the second derivative on the grid
:
d2 = n ^ 2SparseArray[{{i_, i_} -> -2., {i_, j_} /; Abs[i - j] == 1 -> 1.}, {n + 1, n + 1}, 0.]Incorporate Dirichlet boundary conditions to form the Jacobian J:
j = d2;
j[[1, {1, 2}]] = 0.;
j[[-1, {-1, -2}]] = 0.;
j = SparseArray[j]id = IdentityMatrix[n + 1, SparseArray]Form sparse matrix
for
using the listability of arithmetic:
m = id - 0.001 jLU decomposition of
in a functional form:
lu = LinearSolve[m]Step initial condition on spatial grid x using the listability of UnitStep:
init = UnitStep[x - .5];
ListPlot[init, DataRange -> {0, 1}]Get the solution at
,
using the backward Euler method:
sol = init;
Do[sol = lu[sol], {10}]ListPlot[sol, DataRange -> {0, 1}]Properties & Relations (7)
Listable, in general, functions effectively apply Thread many times:
SetAttributes[f, Listable];f[{1, 2, 3}]g[{1, 2, 3}]Thread[g[{1, 2, 3}]]Applying listable functions to several arrays of equal dimension is equivalent to using MapThread:
SetAttributes[f, Listable];{a, b} = {Array[x, {2, 2}], Array[y, {2, 2}]};f[a, b] == MapThread[f, {a, b}, 2]Listable functions applied to several arrays require overlapping dimensions to be equal:
SetAttributes[f, Listable];Arguments with equal dimensions:
f[Array[x, {2}], Array[y, {2}]]//DimensionsArguments with equal overlapping dimensions, i.e. {2} has the same leading dimensions as {2,3}:
f[Array[x, {2}], Array[y, {2, 3}]]//DimensionsArguments with unequal overlapping dimensions, i.e. {2} does not have the same leading dimensions as {3,2}:
f[Array[x, {2}], Array[y, {3, 2}]];Listable functions applied to arrays can be written as a Table:
SetAttributes[f, Listable];a1 = Array[x, {5}];
a2 = Array[y, {5, 7}];
a3 = Array[z, {5}];f[a1, a2, a3] == Table[f[a1[[i1]], a2[[i1, i2]], a3[[i1]]], {i1, 5}, {i2, 7}]A function implemented in terms of a listable operation may not need the Listable attribute:
g[x_] := x ^ 2g[{1, 2, 3}]Attributes[Power]The system symbols with the Listable attribute:
listable = Entity["WolframLanguageSymbol", "Listable"]["SymbolsUsingAsAttribute"];
Short[listable, .5]More than half these are arithmetic functions possessing the NumericFunction attribute as well:
{Length[listable], Length[EntityList[EntityClass["WolframLanguageSymbol", "Attributes" -> ContainsAll[{"Listable", "NumericFunction"}]]]]}The products given by Dot, Times, and KroneckerProduct are inner, element-wise, and outer:
u = {a, b, c, d};
v = {1, 2, 3, 4};The inner product of two vectors:
u.vThe vector resulting from the product of corresponding elements:
u vThe matrix resulting from the outer product of the vectors:
KroneckerProduct[u, v] // MatrixFormTech Notes
Related Guides
Related Workflows
- Run a Computation in Parallel
Related Links
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), Listable, Wolfram Language function, https://reference.wolfram.com/language/ref/Listable.html.
CMS
Wolfram Language. 1988. "Listable." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Listable.html.
APA
Wolfram Language. (1988). Listable. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Listable.html
BibTeX
@misc{reference.wolfram_2026_listable, author="Wolfram Research", title="{Listable}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Listable.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_listable, organization={Wolfram Research}, title={Listable}, year={1988}, url={https://reference.wolfram.com/language/ref/Listable.html}, note=[Accessed: 12-June-2026]}