Questions about how Mathematica evaluates expressions, tracing evaluation (Trace*), handling expressions in unevaluated form (Hold*, Unevaluated), nonstandard evaluation, etc.

learn more… | top users | synonyms

9
votes
4answers
165 views

Evaluation of Alternatives

I recently stumbled upon a few examples that suggest patterns containing Alternatives do not evaluate for individual alternatives. For example: ...
1
vote
0answers
56 views
7
votes
1answer
263 views

How is LHS = RHS; … ; LHS (nontrivially) different from … ; RHS

I'm trying to understand how Mathematica thinks about the results of Set. Suppose we perform LHS = RHS. I'm focusing on when ...
0
votes
0answers
32 views

Substitute arguments before evaluating variables in Block [duplicate]

Suppose I have f = x^2; mod[x_] := Module[{}, f] Then mod[3] returns x^2. Is there any way to tell Mathematica to treat the "x" inside of f as the same "x" as ...
1
vote
0answers
50 views

Solving a polynomial equation with an approximate constraint is slower than the symbolic solution

Why do these two operations have such different timing, when the only difference is specifying r as approximate $0.1$ vs arbitrary-precision $1/10$? Here are the ...
1
vote
1answer
72 views

How can I draw truth tables using Mathematica [duplicate]

For instance, the given expression p ⊕ (p v q) In the problem I'm trying to solve. There's a Mathematica answer to this: ...
14
votes
3answers
1k views

How to evaluate the $0/0$ type limit in Mathematica?

When I use Limit to evaluate the limit $$\begin{align}\lim_{k \to 0} \frac{ (k+2)(\alpha^2 - \sqrt{\alpha^4 + k}) + k}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 ...
0
votes
0answers
37 views
0
votes
0answers
59 views

Approaching infinity

I'm using Mathematica to visualize the autocorrelations of all kinds of wave-types. Obviously, my waves aren't infinite and don't have infinite periods though, so the autocorrelation I get is a ...
10
votes
2answers
260 views

Held keys in associations

Jacob Akkerboom commented: Note that PositionIndex does work correctly with held expressions, whereas this is a bit painful to implement using ...
6
votes
1answer
111 views

Why do certain fractional values in TriangleWave not evaluate?

While answering another question I discovered that TriangleWave does not automatically evaluate when given certain fractional values, specifically fractions with a ...
2
votes
1answer
80 views

Clearing a global variable from inside a Module

This is a highly simplified version of a initialization problem I have with a complicated program with many (about 100) modules. If one enters: X=42; Clear[X]; the ...
1
vote
2answers
69 views

Evaluation of a list

I'd like to assign to $a[1],\ldots,a[m]$ ($m$ being defined beforehand) zero values. I tried Table[a[i], {i, m}] := Table[0, {m}]; but got an error message ...
10
votes
4answers
433 views

Order of evaluation - does Mathematica evaluate variables before or after substitution?

Let's say I write y = x^2; x = 10; z = y + y^2 + y^3 Does Mathematica internally evaluate y before or after substituting it into z? I.e., does Mathematica ...
4
votes
2answers
57 views

Controlling evaluation in a custom summation function

I'm doing some computations that involve summations with many indices over the same range - consider the simplified example Sum[a[i,j],{i,1,2},{j,1,2}]. To prettify ...
53
votes
10answers
2k views

Injecting a sequence of expressions into a held expression

Consider the following toy example: Hold[{1, 2, x}] /. x -> Sequence[3, 4] It will give Hold[{1, 2, Sequence[3, 4]}] ...
1
vote
5answers
168 views

Do not expand matrices in Mathematica calculation

Here is an example of a problem I'm having. Consider that I have defined: omega={{p[t]},{q[t]},{r[t]}} x={{a},{b},{c}} R={{1,2,3},{4,5,6},{7,8,d}} What I would ...
8
votes
4answers
231 views

How to inject unevaluated list of Unique into a RuleDelayed?

I am writing a function that constructs a rule which has Unique[] in the RHS. Here is a simplified segment of code ...
7
votes
2answers
136 views

Evaluation inside Inactivate

The documentation for Inactivate makes the function sound really powerful because it gives granular control over which kind of expressions specifically not to ...
0
votes
0answers
31 views

How to calculate a required definition only once for each iteration of NonlinearModelFit

This is my first post here. I've been using Mathematica for about 4 years now to analyze data, but am still very new and have no background in formal programming. This is the first question I couldn't ...
4
votes
2answers
63 views

Append fixed value to random selection of list

(This question might be an application of this other question, but there might be another solution specific to this application that I'm not aware of.) I am currently in a situation in which (in a ...
4
votes
1answer
55 views

Strange behavior of ArcTan [duplicate]

I've noticed a strange behavior of Mathematica's ArcTan function with two arguments. If both arguments are 0 or ...
18
votes
1answer
230 views

What is the difference between Dynamic[x] and Dynamic[ h[x] ] for DynamicModule variables?

Bug introduced in 9.0 or earlier and persisting through 10.3.1 or later Why plain Dynamic[x] is less sensitive and less likely to automatically be updated than ...
3
votes
4answers
87 views

Working with ScheduledTasks inside DynamicModules

I have a question - is it possible to run ScheduleTask[] inside DynamicModule[]? What I have tried so far: ...
3
votes
2answers
50 views

How to avoid 0 OverVector[F] to be evaluated as 0?

I am fairly new in Mathematica and I am trying to work with scalars and vectors. I decided to denote vectors using OverVector (as example, ...
7
votes
1answer
300 views

Debugging a $RecursionLimit error?

I sometimes encounter bugs that involve a recursion limit. It's often very hard to find the origin of the problem. Would there be a way to copy the stack somewhere and abort the evaluation in order ...
5
votes
2answers
131 views

A pre-parsed HoldForm

HoldForm holds an expression's parsed form not its actual "inputted form" e.g. ...
12
votes
5answers
237 views

Prevent Plus from threading

This is probably a very simple question, but I couldn't find a duplicate. As everybody knows, {x, y} + v gives {x + v, y + v}. ...
4
votes
2answers
92 views

Derivative before Numerical Integration

I need to take the derivative of a function that have a numerical integration on it. The variable in which the integration will be taken is not the same as the one in which the derivative will be ...
0
votes
1answer
182 views

How to force numeric evaluation?

I need to evaluate the PolyLog function at some points, but I'm interested in numeric values. E.g. PolyLog[3, 2.7] works fine, ...
1
vote
1answer
67 views

RunScheduledTask and return the result

I created a task that removes itself when an external variable x,is changed: ...
20
votes
3answers
377 views

Can't inject EncryptedObject

Bug introduced with Encrypt in 10.0 Persisting through 10.3.1 or later Here are minimal examples: ...
16
votes
2answers
872 views

How to restart computation when kernels die?

When an important process needs to be kept alive, there are monitoring tools to restart them if they die (e.g. god tasks in ruby), in my case I have an overnight scraping task that I need to have done ...
0
votes
1answer
49 views

Alter evaluation order when applying scalar multiplication to function

Consider the following program: g = 2f; g[x] (* (2f)[x] *) Is there any way I can change the above expression to have it return ...
3
votes
0answers
51 views

Is there an analogue of Evaluated->False (in FindRoot) for FindMinimum?

I guess functions like FindRoot, FindMinimum, etc puts the estimation number into the expression, and then do other ...
0
votes
2answers
41 views

Unevaluated derivatives of known functions after replacement

I want to make the following replacement work correctly: Array[(2 D[xM[[#1]][t], t] * D[xM[[#2]][t], t]) &, {3, 3}] /. {xM -> {Sin[ω t], Cos[ω t], 0}} ...
3
votes
1answer
87 views

Fast evaluation of a function in many points

I need to feed to an external program a number of points (in Complex128 format) generated from the numerical evaluation of some function, e.g. $e^{i ...
1
vote
1answer
171 views

new kernel for notebook

I know I can create a new kernel for my notebook from the evaluation menu but is there a command for this? I'd really like some of my notebooks to startup their own kernel as the first line of code.
4
votes
2answers
105 views

Manipulate in modal mode

It is sometimes convenient to use Manipulate to set up global values which are to be used in the rest of the notebook. In such cases one can select and run the ...
0
votes
0answers
52 views

What makes items with head `Function` different?

I apologize beforehand for the muddleheadedness of this question. It reflects the fact that I'm trying to interpret outward "behaviors" of Mathematica expressions without having any understanding of ...
1
vote
2answers
59 views

NDSolve with one parameter

This is a copyable minimal example to illustrate the problem that occours when I include one parameter U into a differential equation which I want to solve with ...
0
votes
0answers
39 views

Order of evaluation for numeric functions

I'm trying to plot a 3D vector field to illustrate an electric field of a uniformly charged disk, and I used Manipulate to change the radius R of the disk to see ...
5
votes
5answers
204 views

Nested function with an increasing argument

If, for example, I have a nesting function like Nest[1 + x^n (#) &, 1, 3] it gives the result ...
3
votes
0answers
109 views

Assign variables from list inside With or Module

I have found that it is possible to assign variables from lists, as follows. r = {1, 2, 3}; {a, b, c} = r; b 2 However, ...
0
votes
1answer
104 views

Plotting two variables indirectly dependent on each other

I have the following system of linear ODEs for "i" number of species "c" migrating in "j" number of habitats: ...
18
votes
2answers
349 views

What does f_[whoCalled]^:=f really mean?

I came across the following post by John Doty in this Google Groups discussion: On Friday, January 11, 2013 8:23:16 PM UTC-7, amzoti wrote: It is clear the Mathematica uses Lisp as one ...
2
votes
0answers
51 views

Import names into notebook namespace [duplicate]

I have function that at some point has list of strings (e.g. {"apple","pear"}) and I want to declare (initialize) those variables in notebook namespace to default ...
1
vote
0answers
31 views

Save a Mathematica notebook evaluated [duplicate]

My notebooks can take some time to evaluate and by quitting Mathematica, I have to reevaluate every definition I've made once I restart Mathematica. Is there a way to tell Mathematica to save the ...