26 votes
Accepted

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

I'm going to take this as a general question, referring to all atomic objects, not just DelaunayMesh. By design, atomic objects like ...
Szabolcs's user avatar
  • 233k
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
  • 270k
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
  • 270k
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
  • 136k
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
  • 130k
21 votes

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

I think this is the simplest fast way to convert an atomic expression to an equivalent compound form, to be able to inspect and manipulate its "apparent" full form: ...
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.6k
20 votes

Extracting variables from an expression

Using an undocumented function: ...
J. M.'s eventual burnout's user avatar
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
  • 130k
18 votes
Accepted

When is the righthand side of a RuleDelayed evaluated?

There seems to be a subtlety in the way delayed rules are used. Have a look at the following: ...
Fred Simons's user avatar
  • 10.1k
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
  • 112k
17 votes
Accepted

List of atomic expressions

You can executive the code in mma 10 or above version EntityClass["WolframLanguageSymbol", "Atomic"]//EntityList But is not all atomic function,as I know.
yode's user avatar
  • 26.3k
17 votes
Accepted

Import package with correct symbol contexts

...
Kuba's user avatar
  • 136k
16 votes

How to replace the first Head of a currying expression like "a" in a[b,c][d]?

y = a[b, c][d]; y[[0, 0]] = w; y (* w[b, c][d] *)
Mike Honeychurch's user avatar
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
  • 68.4k
15 votes
Accepted

First order approximation

You can use Series to specify the order of approximation. When an expression involving the output of Series, which is a ...
Michael E2's user avatar
  • 233k
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
  • 136k
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
  • 270k
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
  • 22.9k
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
  • 65.8k
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
  • 384k
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
  • 130k
13 votes
Accepted

Factoring out a common term

Defining a function like Clear[FactorByVariable] FactorByVariable[p_,c_]:=c Expand[p/c] will be one of the simpler options. The argument ...
IPoiler's user avatar
  • 1,220
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
12 votes
Accepted

How to replace the first Head of a currying expression like "a" in a[b,c][d]?

For arbitrarily nested heads I would use recursion and pattern matching, like this: ...
Szabolcs's user avatar
  • 233k
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
  • 270k
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
  • 130k
12 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
  • 384k
11 votes
Accepted

Evaluation of Alternatives

The two examples in this question relate to two different aspects of pattern matching. I will start with the simpler to understand and intentional aspect, which is the second example. ...
Itai Seggev's user avatar

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