Comap
Details and Options
- Comap is typically used to apply each of a list of functions to a single common argument. »
- Comap uses standard level specifications:
-
n levels 1 through n Infinity levels 1 through Infinity {n} level n only {n1,n2} levels n1 through n2 - The default value for levelspec in Comap is {1}.
- A positive level n consists of all parts of fs specified by n indices.
- A negative level -n consists of all parts of fs with depth n.
- Level –1 consists of numbers, symbols and other objects that do not have subparts.
- Level 0 corresponds to the whole expression.
- With the option setting Heads->True, Comap includes heads of expressions and their parts. »
- Comap always effectively constructs a complete new expression and then evaluates it. »
- The head of fs in Comap[fs,x,…] need not be List.
- If fs is an Association object, Comap[fs,x] applies the values in the association to x. »
- Comap[fs][x] is equivalent to Comap[fs,x].
- Parallelize[Comap[fs,x]] computes Comap[fs,x] in parallel on all subkernels. »
Examples
open all close allBasic Examples (4)
Wrap x with each element of a list:
Comap[{f, g, h}, x]Use the operator form of Comap:
Comap[{Sin, Cos, Tan}][Pi / 3]Comap[{{Sin, Cos, Tan}, {Csc, Sec, Cot}}, Pi / 3, {2}]Comap an expression under values in an association:
Comap[<|"a" -> f, "b" -> g, "c" -> h|>, x]Scope (6)
Comap[{1 + f[#]&, 2 + g[#]&, 3 + h[#]&}, x]Comap[{x |-> x ^ 2, x |-> x ^ 3}, 2]Comap can be used on expressions with any head:
Comap[a + b + c + d, x]Comap[f ^ a + g ^ b, x, {2}]Comap on the second level of a nested Association:
Comap[<|"a" -> <|"x" -> f|>, "b" -> <|"y" -> g|>|>, x, {2}]Comap[{Gamma, {Exp, Log}, {{Sin, ArcSin}, {Cos, ArcCos}}}, 0, {-1}]Positive and negative levels can be mixed:
Comap[f[f[f[f[f[f]]]]], x, {2, -3}]Different heads at each level:
Comap[h0[h1[h2[h3[h4[h5]]]]], x, {2, -3}]Options (1)
Applications (3)
Apply a sum of functions by forming the sum of the individual applications:
Comap[f + g + h, x]Apply a differential operator:
Comap[(D[#, x]&) + (D[#, x, x]&), f[x]]Tabulate square roots of values without using auxiliary variables:
TableForm[Comap[{Identity, Sqrt}] /@ {0, 1.0, 2.0, 3.0, 4.0}]Properties & Relations (9)
Comap wraps parts of an expression around another expression:
Comap[{f, g, h}, x]Map wraps an expression around parts of another expression:
Map[f, {x, y, z}]Query[list] is equivalent to Comap[list]:
Query[{Mean, Median, StandardDeviation}][{6, 2, 3, 4, 4, 4, 0}]Comap[{Mean, Median, StandardDeviation}][{6, 2, 3, 4, 4, 4, 0}]Query[assoc] is also equivalent to Comap[assoc]:
Query[<|"a" -> f, "b" -> g, "c" -> h|>][x]Comap[<|"a" -> f, "b" -> g, "c" -> h|>][x]Through[p[f,g,…][x]] is equivalent to Comap[p[f,g,…],x]:
Through[{f, g, h}[x]]Comap[{f, g, h}, x]Compare this to the operator form of Comap:
Comap[{f, g, h}][x]Comap[p[f,g,…],x] can be used even when p[f,g,…][x] has a value:
Comap[<|"a" -> f, "b" -> g|>, x]When p[f,g,…][x] has a value, Through cannot be used:
<|"a" -> f, "b" -> g|>[x]Through[<|"a" -> f, "b" -> g|>[x]]Comap[{f1,f2,…},x] is equivalent to Map[f|->f[x],{f1,f2,…}] when the fi have no attributes:
Comap[{f, g, h}, x]Map[e |-> e[x], {f, g, h}]Comap can apply parts inside held expressions to an expression without allowing evaluation to proceed:
Comap[Hold[Length, Total], {a, b, c}]Use ReleaseHold to allow evaluation to proceed:
ReleaseHold[{%}]If only some arguments are held, only those arguments will not evaluate further:
SetAttributes[h, HoldRest]Comap[h[Length, Total], {a, b, c}]Use Unevaluated to apply a list of functions to an expression without evaluating it first:
Comap[{Hold, HoldComplete}, Unevaluated[2 3 4]]The expression is evaluated first by default:
Comap[{Hold, HoldComplete}, 2 3 4]Use Unevaluated to comap an expression into the parts of an expression without evaluating it first:
Comap[Unevaluated[f g f], x]The expression is evaluated first by default:
Comap[f g f, x]Comap can be parallelized automatically:
Parallelize[Comap[{f, g, h}, x]]Possible Issues (1)
Comap by default starts at level 1, so does not apply the whole expression to the expression:
Comap[f[g[h]], x, -1]Comap[f[g[h]], x, {0, -1}]Tech Notes
History
Text
Wolfram Research (2024), Comap, Wolfram Language function, https://reference.wolfram.com/language/ref/Comap.html.
CMS
Wolfram Language. 2024. "Comap." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Comap.html.
APA
Wolfram Language. (2024). Comap. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Comap.html
BibTeX
@misc{reference.wolfram_2026_comap, author="Wolfram Research", title="{Comap}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/Comap.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_comap, organization={Wolfram Research}, title={Comap}, year={2024}, url={https://reference.wolfram.com/language/ref/Comap.html}, note=[Accessed: 13-June-2026]}