62 questions linked to/from Replacement inside held expression
1k views

### How to inject an evaluated expression into a held expression? [duplicate]

I know that there are methods to structurally manipulate held expressions (discussed e.g. here), but I failed to apply those for this particular problem: ...
1k views

### How to evaluate some parts of an expression inside Hold? [duplicate]

I want to return a Hold expression but with some parts pre-evaluated. The easiest way to explain this is probably through code example. Here is what I have ...
121 views

### How to substitute inside Hold? How to create table of summation (with Sigma symbol) expressions? [duplicate]

I would like to create table of summation expressions, which are not evaluated, but summation limits are substituted. I can't accomplish this so far. If I write I get summation expanded. If I ...
58 views

### Purpose of construct With[{var=myComputation[…]}, var/;True]? [duplicate]

Could someone please give an illustrative example showing the purpose of construct of form With[{var=myComputation[...]}, var/;True]? Also, I wonder what kind of ...
49 views

### How does the code idiom for replacing part of a held expression work? [duplicate]

I've seen this idiom used in different programs but never fully understand why it is necessary. Could someone explain? Is it still the recommended way to replace some part of a held expression to its ...
135k views

### Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
1k views

### How to display very small numbers in Mathematica?

I am trying to evaluate the function: $$f(x) = \cos(x) - \mathrm{e}^{-2.7 x}$$ at $x = 1.7 \times 10^{-25}$ and Mathematica keeps returning '0.' How do I evaluate the expression in a better way?
2k views

### What are all the “magic” Symbols in the Mathematica language?

Leonid Shifrin once wrote (excerpted): (Unevaluated) is one of a very few "magic symbols", along with Sequence and ...
629 views

### Is it possible to construct a fullform trace function

Is it possible to construct a FullFormTrace function that takes an arbitrary expression and prints a sequence (or returns a list) of the evaluation steps in full ...
871 views

### Generating assignments and transforming code inside held forms when generating code

I have been playing with slightly above trivial code manipulations in Mathematica. I thought Mathematica would be great for this kind of work because of rule replacement and expression manipulation, ...
548 views

### Replacing parts of a held expression with held parts of another expression

I'm applying the Trott-Strzebonski technique in order to replace inside a held expression. ...
1k views

### Does Set vs. SetDelayed have any effect after the definition was done?

I was always assuming that the only difference between Set (=) and SetDelayed (...
277 views

### Hold expression with RandomInteger

One more question for today: I'm trying to show two random integers with a plus (+) sign between them, in an unevaluated form. I know how Hold and HoldForm work, but they hold everything, including ...
305 views

### Is it possible to separately call the default value of a variable which isn't at the end of the sequence?

After reading this post I recalled an old question I once met. We know that we can set default values for variables of a function: ...
909 views

### Is this a bug in Replace?

Consider the following minimal examples. This one works as expected, replacing trees starting from the inside with a numerical value. ...
1k views

### How to solve the tsunami model and animate the shallow water wave?

Backslide introduced in 9.0, persisting through 11.3. Recently when I was learning differential equations, I noticed there is a shallow water wave equation to model the tsunami propagation. How to ...
569 views

### Why x = x doesn't cause an infinite loop, but f[x_] := f[x] does?

If I execute: In[1] := x = x Out[1] = x and then I evaluate the symbol x: ...
489 views

### partial numerical evaluation

Context The following is an issue I have come across many times and still do not have a satisfactory solution for. The context of it is this. Let's say we have an equation, a linear ODE for the ...
475 views

### Why can't I inject expressions in Compile using (only) With

Generally speaking, With can be used to inject into arbitrarily held expressions, for example: ...
3k views

### Replace symbols with values without evaluation

If I have assigned values to a, b and c: a=7; b=5; c=6; ...
453 views

### Obtaining the number of iterations used in ReplaceRepeated

ReplaceRepeated has an option MaxIterations which indicates Mathematica is keeping track of the number of iterations. Is there ...
389 views

### How can I break through Function's HoldAll attribute to force evaluation of a body element?

The question concerns creating a function. Let consider the following code With[{f = Function[t, Cos[t]]}, {First[#], f'[#]} & ] which returns ...
226 views

### How to Force Evaluation of Derivative in a Pure Function Definition

Let's say I have a function f1 = #^2 &; I want to calculate its derivative, perform some manipulations and make the result a pure function. I try ...
278 views

### Pattern matching to a function evaluation inside an Association

I find the following behaviour deeply counter-intuitive: <|1 -> 123.456 |> /. {x_?NumericQ -> Round[x]} (* <|1 -> Round[123.456]|> *) That ...
248 views

### why does Function have the HoldAll attribute?

Consider the following: f = 2 # & OwnValues[f] g = f[#]/2 & OwnValues[g] Since Function has the ...
229 views

### Apply function to nested associations

This seems like it should be easy but I am trying to concisely enhance some nested associations with Mathematica objects (e.g., convert things to matrices, etc) but I'm having a bit of difficulty with ...
699 views

### Free Convective Heat Transfer of Non-Newtonian Power Law Fluids from a Vertical Plate

I am trying to solve a set of PDEs mentioned in this paper with NDSolve but facing quite a few issues. The PDE system is: ...
420 views

### How to copy formatted numbers as MathML without quotation marks?

I have the following code: a = 6.08717*10^6; b = a/3; c = a*1.5; d = a^2; matrix={{a, b, c, d},{b, c, d, a},{c, d, a, b},{d, a, b, c}}; matrix // EngineeringForm ...
315 views

### How to sort arguments of Times in nonstandard order?

Is there an elegant way to sort the arguments of Times in e.g. TraditionalForm so that factors go to the front and state ...
366 views

### Evaluate Only Part of a Function

I have a list of functions, each containing none or more of the functions Plus, Times, ...
342 views

### HoldForm: how does it interact with nested evaluations?

Here's an example to illustrate the issue I'm having. right = 8 - y; left = y^2 + 6; integrand = HoldForm[Evaluate[right]] - HoldForm[Evaluate[left]] (I ...
239 views

### Puzzled regarding avoiding evaluations and using results of computations as functions

What did I do before? I seem not to be able to understand MMA's evaluation scheme. I read some posts like Preventing Evaluation or a MathGroup post where the topics of evaluation prevention are ...
218 views

...
143 views

### How to use ReplaceAll and RuleDelayed with an Association? [duplicate]

I expected that something like this ...
187 views

### Replace inside a Held expression separate context

How do I replace content inside a Held expression without local values coming through? For example if you run the following code you get g[2] instead of ...
230 views

### Replace variable with value prior to evaluating NIntegrate

The title says it all. Reading posts such as this however, I'm not seeing how to do this. This is the simplest example that can show my problem. ...
245 views

### Instability, Courant Condition and Robustness about solving 2D+1 PDE

After several discussions, I would like to focus on the robustness of solving 2D+1 PDE by considering all suggested methods from @xzczd (see here) I found that the Ratio between the convection term ...
439 views

### Condition and RuleDelayed

On this site I found, for example here, some very interesting questions and answers on the use of delayed rules with conditions. I would very much like to understand these answers, but so far I failed ...
204 views

### How I create a 'TraditionalForm' expression in which only parts are evaluated?

I have an expression for the form Subscript[W, f[a, b]][c] = ρ^f[a,b]ω[c]ρ^-f[a,b] that I want to render in TraditionalForm ...
909 views

### Collect and simplify both the coefficents and the matched patterns

(This is a far tighter version of a previous question I asked) The problem with Collect is that while Collect[exp, pattern, Simplify] will simplify the coefficients,...
197 views

### KeyValuePattern in matching and replacement in nested associations

This case revealed I am missing something in pattern matching and evaluation in case of match, or I can't grasp it due to the busy week I have. Either way, I find this problem interesting for wider ...
175 views

### Is Replace doing double work?

In an answer to this question, rm -rf used the function Replace with level spefication to do a series of replacements inside out. As far as I can see, the order of substitutions when more than one ...
1k views

### Pass unevaluated function with evaluated arguments

I am almost sure that this question has been asked somewhere. I found similar ones, but I cannot find exactly what I need, which might mean that I am on the wrong track. I search a method to pass an ...
248 views

### different situations with Compilation of ConstantArray

First, we load some tools related to Compile for analysis. ...
145 views

### How to pre-evaluate parts of a lambda or a delayed-assigned function?

I have an expression which I'd like to evaluate and use as a subexpression of a delayed-assigned expression. But I need it to be evaluated before actual assignment, while other parts of the full ...
162 views

### Pattern matching and HoldForm

Create rules based on data. I have a system that picks out on date,based on some rules. I then want to generate a new rule based on this date and apply the rule to a new dataset. ...
159 views

### Can I release a pattern without releasing the whole held expression?

I would like to release only the rules in an expression that held. Is that possible? ...
158 views

### Problem Using Evaluated Replace with Associations

If I define some function like: toISOdate[data_List]:=DateString[data,{"Year","-","Month","-","Day"}] and try to applicate it in an ...