Skip to main content
24 votes
Accepted

Shorthand for map at level 2

Corrected to use SubscriptBox as Rojo showed and Kvothe commented, fixing binding. Rojo shows a way in Is it possible to define custom compound assignment ...
Mr.Wizard's user avatar
  • 272k
24 votes

Can we intelligently control evaluation in Thread?

Analysis of the problem All functions in Mathematica either hold one or more of their arguments, or per The Standard Evaluation Procedure the arguments are evaluated before the function is applied. <...
Mr.Wizard's user avatar
  • 272k
24 votes

Cleanest way to take a[b[c]] to a[b][c]

test = a[b[c[d]]]; Fold[ Construct, (* or Compose, see [1] *) Level[test, {-1}, Heads -> True] ] a[b][c][d] [1] - ...
Kuba's user avatar
  • 137k
23 votes
Accepted

Mapping function across its arguments

Tuples[expr, 1] (* {f[a], f[b], f[c]} *)
Karl's user avatar
  • 941
22 votes

How to extract parts from atomic expressions like DelaunayMesh and Graph?

Motivation Recently, I wanted to extract parts of an atomic expression, and my first thought was to use a ToExpression/ToString ...
Carl Woll's user avatar
  • 131k
21 votes

Extracting variables from an expression

Using an undocumented function: ...
J. M.'s missing motivation's user avatar
21 votes
Accepted

Custom atomic expressions - modern tutorial

I have a new package for speeding up the construction of things like these which I discuss at the end Atomic vs Valid These are two related but distinct concepts. The former indicates that we can't ...
b3m2a1's user avatar
  • 46.9k
19 votes
Accepted

How can I obtain a complete list of the kinds of atomic expressions in the Wolfram Language using only the language itself?

You can use EntityValue to find out what symbols can be atomic: ...
Carl Woll's user avatar
  • 131k
18 votes

Can we intelligently control evaluation in Thread?

First, let me tell you that my answer here is by no means a replacement for the trickier, but more capable implementation of Mr. Wizard. What I want to show is that the examples I point out at the end ...
halirutan's user avatar
  • 113k
17 votes
Accepted

Import package with correct symbol contexts

...
Kuba's user avatar
  • 137k
16 votes
Accepted

Evaluated vs. unevaluated Association

Summary The confusion we observe here is largely due to ambiguous use of the symbol Association as an expression head. On the one hand, ...
WReach's user avatar
  • 69k
15 votes
Accepted

Joining two lists with relational operators

Thread[liste - listv <= 0] // Reduce 2 <= y <= 3 && z >= 4 && x <= 1 ...
Kuba's user avatar
  • 137k
15 votes

Is there a way to to substitute for symbols, simplify, and back-substitute?

This comes up often. Here are links to related MSE threads. Rename terms of polynomials Collecting factors of polynomials Can I simplify an expression into form which uses my own definitions? ...
Daniel Lichtblau's user avatar
14 votes
Accepted

Is there a built-in function to inverse Thread?

Let's make this a little more challenging: ...
Mr.Wizard's user avatar
  • 272k
14 votes

Shorthand for map at level 2

I'm not aware of a simple one, but perhaps you could make your own? The following is not great because it requires you to enter CenterDot as Esc+.+Esc, and you can'...
march's user avatar
  • 23.8k
14 votes

Is there a way to to substitute for symbols, simplify, and back-substitute?

You could use Simplify or FullSimplify with your transformation rules as assumptions, expressed as equations: ...
MarcoB's user avatar
  • 67.3k
14 votes
Accepted

How to replace $x$ and $x^2$ with different value?

Give the replacement rules in a list: expr /. {x^2 -> k p + k (k - 1) p^2, x -> k p} 2 k p + (-1 + k) k p^2
kglr's user avatar
  • 397k
14 votes
Accepted

Conflict with hidden names

First, you should never give Plus a downvalue. Always give your symbol upvalues instead by using TagSetDelayed. Giving such a ...
Carl Woll's user avatar
  • 131k
13 votes

Which operation combines {f,g,h,...} and y[u,v,w,...] to get y[f[u],g[v],h[w],...]?

Using Mapthread innerMap[funcs_, expr_] := Head[expr] @@ MapThread[#1[#2] &, {funcs, List @@ expr}] innerMap[myFuncs, expr] ...
NonDairyNeutrino's user avatar
13 votes

Split expression into list of terms

ClearAll[terms] SetAttributes[terms, HoldAll] terms[Plus[a__]] := {a} terms[a_?AtomQ] := {a} terms[a_] := a Examples: ...
kglr's user avatar
  • 397k
12 votes

Can we intelligently control evaluation in Thread?

Specific solutions Since my goal is for not only this Question to become canonical but also my solution my function must be applicable to most cases that come up. Threading behavior of SameQ vs ...
Mr.Wizard's user avatar
  • 272k
12 votes
Accepted

Separate or order the positive and negative terms of an expression

Perhaps something like: Values @ GroupBy[ List @@ (b+c^2-c^2+a^4-c^5), Internal`SyntacticNegativeQ, Total ] {a^4 + b, -c^5} Addendum OP requested ...
Carl Woll's user avatar
  • 131k
12 votes

Mapping function across its arguments

Using Subsets: expr = f[a, b, c]; Subsets[expr, {1}] (*{f[a], f[b], f[c]}*) Or using ...
E. Chan-López's user avatar
11 votes
Accepted

How to get the long logic expression with a terse method

My offering: And @@ Or @@@ Outer[Equal, {x, y, z, m}, {2, 3, 4}]
Quantum_Oli's user avatar
  • 7,964
11 votes
Accepted

Symbolic manipulation of expression with undefined function

example = v[1, 1, 1, 1] + 10*v[0, 0, 2, 0]; Using a replacement rule: ...
corey979's user avatar
  • 24k
11 votes
Accepted

How to represent $f(x) = (y-x)^k \log(y-x)$ as a summation of the form $f(x) = \sum\limits_{j=0}^\infty \cdots$?

Complete rewrite of answer The expression to be expanded as a series is the argument of ser = Series[(y - x)^k*Log[y - x], {x, 0, 5}] I attempted to obtain the ...
bbgodfrey's user avatar
  • 61.6k
11 votes

How to find all variables of an expression?

For polynomial expressions @Buddha_the_Scientist's suggestion Variables will work. For more general expressions ...
TimRias's user avatar
  • 3,180
11 votes

Which operation combines {f,g,h,...} and y[u,v,w,...] to get y[f[u],g[v],h[w],...]?

Inner[# @ #2 &, #, {##} & @@ #2, #2[[0]]] &[myFuncs, expr] y[f[u], g[v], h[w]] or ...
kglr's user avatar
  • 397k
11 votes
Accepted

How do two equations multiply left by left equals right by right?

I much prefer MultiplySides[eq1, eq2] //Expand to BobHanlon's otherwise fine solution. It also generalizes quite nicely to ...
David G. Stork's user avatar
11 votes

Mapping function across its arguments

Operate[Map[#]@*List &, expr]
lericr's user avatar
  • 29.2k

Only top scored, non community-wiki answers of a minimum length are eligible