Questions tagged [hold]

Questions about functions which maintain an expression in unevaluated form, including the use and behavior of Unevaluated, Hold~ functions, Inactive related functions or Hold~ attributes.

Filter by
Sorted by
Tagged with
3 votes
3 answers
214 views

Different evaluation control inside of `Integrate` than outside of it

I want to keep inside of a integral evaluated after some replacement inside it, but at the same time the integral itself unevaluated. I start with: ...
user avatar
  • 2,503
6 votes
3 answers
231 views

HoldForm is not working as I would expect

Why HoldForm do this? HoldForm[a/b \[Integral]f[x] \[DifferentialD]x] Output is this ugly looking formula: $$\frac{a \int f(x) ...
user avatar
  • 2,503
2 votes
0 answers
38 views

Inactive form for PDE and symmetry

I would like to solve the following non-linear Poisson equation (as a toy problem for a more complicated problem) ...
user avatar
2 votes
3 answers
85 views

Holding after evaluation

Given this little piece of code: ...
user avatar
  • 165
0 votes
1 answer
45 views

How to construct the local variables for Block automatically (somewhere in the code)

I am working on the fancy abstraction for Block function. The idea is to use rules to specify which local variable will be used, even if it already defined in the global context like this ...
user avatar
4 votes
5 answers
244 views

How to define functions using a list of polynomials?

I feel stupid for not being able to do this and I think it is just a syntax error. Let's say i have the following list: L={x,xy,x^2+y,xyz,x^2} How do I define 5 ...
user avatar
  • 553
3 votes
3 answers
237 views

Seemingly identical expressions, only one evaluates! [closed]

I am having difficulty using NMaximize with a user-defined function that involves NSolve. Stack Trace shows trouble at the ...
user avatar
  • 131
6 votes
1 answer
182 views

Getting terms and only evaluate specific parts of a series

How to write the first five terms of this series in the following form by MMA code? $\sum_{n=1}^{\infty} \frac{1 \cdot 3 \cdot \cdots \cdot(2 n-1)}{2 \cdot 4 \cdot \cdots \cdot 2 n}= \frac{1}{2}+\frac{...
user avatar
  • 1,365
1 vote
0 answers
66 views

Why does Plot function have HoldAll attribute?

I had an odd issue where my plot wasn't drawn correctly when I called it via Plot[Join[fs,gs], (*..*)]. However, these two versions worked: ...
user avatar
1 vote
0 answers
67 views

Why does equal remain unevaluated in this case? [closed]

This is not really an issue but rather a curiosity. Why does -1 + 1/2 (-1 - Sqrt[5 - 20/9 (-43 + Sqrt[1885])]) + 1/2 (1 + Sqrt[5 - 20/9 (-43 + Sqrt[1885])]) == -1 ...
user avatar
  • 553
0 votes
0 answers
30 views

How to Hold a Form function

For Example Hold[HoldForm[FullForm[x]]] ...
user avatar
  • 275
3 votes
3 answers
106 views

Apply HoldForm on only a part of an expression

This expression: Det[Array[a, {3, 3}]] is evaluated as: $-a(1,3) a(2,2) a(3,1)+a(1,2) a(2,3) a(3,1)+a(1,3) a(2,1) a(3,2)-a(1,1) a(2,3)a(3,2)-a(1,2) a(2,1) a(3,3)+a(...
user avatar
0 votes
1 answer
70 views

Variable dimension tables with variable ranges

I need to construct a table that has variable dimension and variable ranges (see for tables with variable dimensions and constant ranges, e.g., this question). Suppose there is a list ...
user avatar
  • 317
3 votes
1 answer
84 views

A possible issue in combination of the Infix operator ~ with Sequence [closed]

There are other similar questions on this site about using the Infix operator for more than two arguments, which I have read. But there is one thing that I wasn't able to understand and couldn't ...
user avatar
  • 789
5 votes
3 answers
277 views

Apply Plus as a new head to a list but prevent evaluation

I would like to illustrate to users the use of Apply with an example. Plus@@Range[5] (*15*) To display what is happening I'm ...
user avatar
  • 1,603
3 votes
1 answer
139 views

How to substitute a random function into a solution of a differential equation?

I would like to solve a differential equation including a source term. The source term is a random variable and I model this by creating a list of RandomReal and ...
user avatar
0 votes
0 answers
38 views

Create a function from another by substituting arguments

Suppose I have a function f[x, coeff] ...
user avatar
  • 291
3 votes
1 answer
37 views

Removing conditions on patterns from LHS of a rule

Let's consider a rule which takes conditions on the patterns specified on the LHS: In[1]:= rule = j[n1_?NonPositive,n2_?Positive,n3_?Positive]:>AAA I would like ...
user avatar
  • 471
1 vote
0 answers
65 views

Can't Export string made with StringForm?

This works. It returns "acb". StringForm["a``b", "c"] This doesn't work. ...
user avatar
  • 61
0 votes
1 answer
68 views

Derivative with respect to a variable is leaving unevaluated derivatives of functions

I have the following ...
user avatar
2 votes
1 answer
73 views

Different Latex is generated when changing a number from 2 to 1. Using HoldForm

This is the most bizzar thing I saw with Mathematica TeXForm. Could someone please explain why it happens and if there is a workaround? First, will show screen shot. I have an expression, when I have ...
user avatar
  • 108k
1 vote
0 answers
43 views

Generalised Hold pattern for currying

Let myFun[a_][b_] := myFun[a[b]] . The HoldFirst attribute will prevent evaluation of a. Is ...
user avatar
1 vote
1 answer
67 views

Getting a symbol from a string without it being replaced by its value?

Consider the following code running on a fresh Mathematica session with no symbols defined: p[s_String] := Protect[s]; p["x"] This doesn't do anything ...
user avatar
  • 107
1 vote
1 answer
41 views

HoldAll doesn't work for List or BlankSequence?

Consider the following function: f[arg_] := Print[Unevaluated[arg]]; Attributes[f] = HoldAll; The purpose of the function is to print the arguments unevaluated. In ...
user avatar
  • 107
4 votes
1 answer
68 views

Mathematica Documentation for HoldAll: Unevaluated doesn't do anything?

I'm trying to understand the difference between HoldAll and Unevaluated. The documentation for ...
user avatar
  • 107
1 vote
1 answer
66 views

Control evaluation for functional constraints

I'm trying to understand how to use Mathematica to find a solution subject to constraints, where one of the constraints is specified as a predicate function. But I don't know how to control evaluation ...
user avatar
  • 113
0 votes
0 answers
44 views

Evaluating function of two variables inside NMinimize with respect to second argument

Consider three functions: f[t_, 1] := {Cos[t], 1, 0} f[t_, 2] := {Sin[2 t], 1, 0} f[t_, 3] := {Cos[t - 2], 1, 0} For each $k=1,2,3$, let $g(\cdot,k)$ be the ...
user avatar
  • 123
0 votes
0 answers
20 views

How to set attributes for f[x_][y_]? [duplicate]

This doesn't hold expr: ...
user avatar
  • 1,055
4 votes
1 answer
74 views

Refer to OptionValue externally without a specific function name

I want to refer to the actual option values of a function f outside of f, using OptionValue. ...
user avatar
3 votes
1 answer
109 views

How does MMA return an unevaluated expression on errors without going into an infinite loop? [duplicate]

Post-answer note: this question is (understandably) marked as a duplicate, and indeed has a similar solution, but is subtly different in focus: the linked question is about returning a function call ...
user avatar
  • 7,604
0 votes
0 answers
61 views

A function that maps Held symbol to string

Rougly my question is about constructing a function that maps Hold[var] to "var" even when var has an assigned value. In details : ...
user avatar
  • 2,411
1 vote
2 answers
125 views

Making an expression to Iceberg-like object?

Can we construct a function Iceberg, which maps a given expression X to Iceberg[X] satisfying 1. and 2. and 3. ? 1. From Iceberg[X], it is not possible to inspect/extract a part of X with usual ...
user avatar
  • 2,411
0 votes
0 answers
46 views

Best way to simplify a polynomial before making it the body of a function?

So, I'm dealing with iterated polynomials of a single variable—say they're anonymous functions labeled as $p_i$, i.e. p[1], p[2],...
user avatar
  • 7,604
0 votes
0 answers
35 views

Inactivate Prints inside function?

If one has a piece of code with some prints, he can inactivate them using inactivate, like Inactivate[Print["test"];,Print]; (*returns nothing*) Hower, I ...
user avatar
1 vote
2 answers
138 views

Is it possible that the following pde be NDSolve-d?

I am working on an HJB recently and wish to get a numerical result. Can NDSolve on Mathematica 12.2 handle this? $$ V_t+(e^{-\sqrt{t}}+0.4e^{-2.5t}+0.01x)V_{x}+1.12e^{-2t}V_{xx}=\frac{1}{2}e^{-3t}\...
user avatar
  • 11
8 votes
1 answer
241 views

How to write a simple interpreter / DSL with Wolfram Language?

I am specifically trying to write an interpreter for Mathematica predicates to MongoDB aggregation stages, but I wanted to phrase the question a bit more generically because I can see many times one ...
user avatar
  • 710
1 vote
1 answer
59 views

Inactive and simplify does not work [duplicate]

Consider the following code: Simplify[Conjugate[Inactive[cn][n, nAvg]], Assumptions -> Inactive[cn][__] > 0] If you run it, it will not simplify, i.e ...
user avatar
  • 1,973
1 vote
0 answers
81 views

Speeding up value reassignments in ParallelTable

I am solving a differential equation of two closed functions using ParallelTable. For the attached code, I thought the computation time should be approximately proportional to ...
user avatar
7 votes
2 answers
176 views

Extract held value from Association

Consider an association which contains a key which must not be prematurely evaluated. assoc = <| key :> value |> For example, a value of ...
user avatar
7 votes
1 answer
134 views

How to define a version of Table[] which localizes iteration variable by Module[]?

For reusable code it's good practice to use Module[] to localize iteration variables used by Table[], as explained by this post. ...
user avatar
  • 489
2 votes
0 answers
43 views

Hold parents of ArcTan

If this question is beating a dead horse about Hold, Inactivate etc., a close vote is fair enough. That being said, I'm curious ...
user avatar
  • 2,578
1 vote
2 answers
55 views

Applying a particular rule to a held (or unevaluated) function

I am a very novice Mathematica user and still can't get my head around its evaluation control, all possible constructs related to it (e.g. Hold, ...
user avatar
  • 11
1 vote
3 answers
64 views

How to set a value to the symbol denoted by a given string? [duplicate]

The code setString[name_String, value_]:= Evaluate[Symbol[name]] = value fails whenever Symbol[name] has already been assigned ...
user avatar
5 votes
1 answer
107 views

Extracting n-th part of an expression without any evaluation

Is it possible to extract n-th part of an expression as a string, without any evaluation? For example, ...
user avatar
  • 2,411
0 votes
1 answer
140 views

ReplaceThen and ReplaceAt - Cross between ReplacePart, Replace, and Extract -- Request for Comment

REWRITE: Multiple edits were hurting clarity Overview: I'm doing some work involving injecting code into held expressions, and found that I was repeating myself in a couple areas related to the ...
user avatar
  • 555
4 votes
0 answers
121 views

DynamicModule Error when assigning Nothing to variable

Assigning Nothing to a variable inside Module works as expected: ...
user avatar
  • 41
0 votes
1 answer
86 views

Combination of Block and With - Unexpected results

I'm trying to use Block to prevent a function from executing. In this example, the function I'm trying to block will simply be ...
user avatar
  • 555
21 votes
1 answer
437 views

What's the difference between these 2 associations?

I have 2 associations similar to these simplified ones: ...
user avatar
  • 19k
0 votes
2 answers
74 views

Hold `outermost layer` of expression

In pursuit of a function to force unsimplified fractions forceden[x_,d_]:=Hold[Evaluate[Numerator[x]d/Denominator@x]/d]; There are many related functions (...
user avatar
  • 2,578
1 vote
1 answer
110 views

Exploring curl of a gradient of a scalar function

Suppose I want to explore $\nabla \times \nabla V$ where $V$ is some scalar function. It basically results in a zero. But I would only know why if I solve it on paper. I wanted to use Mathematica for ...
user avatar
  • 558

1
2 3 4 5
7