Questions tagged [evaluation]

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

Filter by
Sorted by
Tagged with
90
votes
4answers
12k views

Plot draws list of curves in same color when not using Evaluate

This example comes from the Mathematica documentation for Plot under Basic Examples. Can someone please explain why these are each plotted as a different color in ...
28
votes
6answers
3k views

How are parameters evaluated for a Plot in Manipulate

I am trying to get my head around how Manipulate evaluates functions in a Plot. I have read the introduction to Manipulate, and introduction to Dynamic, but I still ...
90
votes
4answers
4k views

Replacement inside held expression

I wish to make a replacement inside a held expression: f[x_Real] := x^2; Hold[{2., 3.}] /. n_Real :> f[n] The desired output is ...
67
votes
10answers
3k 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]}] ...
59
votes
4answers
4k views

How do I evaluate only one step of an expression?

I am looking for a simple, robust way to evaluate an expression only one step, and return the result in a held form. The definition of a single step is ambiguous, and this itself is probably worthy ...
118
votes
6answers
121k views

Get a “step-by-step” evaluation in Mathematica

Is it possible in Mathematica to get a step-by-step evaluation of some functions; that's to say, outputting not only the result but all the stages that have led to it? If so, how does one do it? ...
44
votes
5answers
3k views

How to create symbols from strings and set values for them?

I am trying to convert a list of string names into symbols, which will then be used to store data. I have 24 files (where the name of each file is a member of the list mentioned above) that I need to ...
22
votes
3answers
18k views

General::ivar is not a valid variable when plotting - what actually causes this and how to avoid it?

I was just evaluating a couple of expressions and started to get errors like this: ...
12
votes
2answers
512 views

Unexpected behavior of rule matching a pattern

I am a beginner exploring the world of Mathematica. I expected the following code T[6, 5, 4, 1, 2, 3] /. {T[a___, 1, b___] -> Length[List[b]]} should return ...
74
votes
3answers
3k views

The clearest way to represent Mathematica's evaluation sequence

WReach has presented here a nice way to represent the Mathematica's evaluation sequence using OpenerView. It is much more clear way to go than using the standard <...
47
votes
2answers
2k views

How do you set attributes on SubValues?

SubValues, as discussed in a previous question, are declared as follows ...
20
votes
1answer
1k views

Using Evaluate and Evaluated -> True in Plot

A few use cases: (1) This, as expected, returns (almost) immediately: f[x_?NumericQ] := Evaluate[(Pause[1]; x)] Plot[f[x], {x, 0, 1}] (2) This takes ...
25
votes
5answers
5k views

How to pass a symbol name to a function with any of the Hold attributes?

Given a function with the attribute HoldFirst, HoldAll or similar, and a variable, list, how ...
22
votes
5answers
947 views

Reassign values to symbols

I've got a situation where I have, say 4 symbols, a, b, c and ...
37
votes
4answers
948 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 12.0 In 11.3 it is even worse. An example from the accepted answer with a Slider is now broken too: ...
19
votes
5answers
637 views

Prevent graphics from rendering inside a held expression

Assuming each odd line is input I would like the even lines to be the output of the following lines. In the above the Graphics are inside ...
22
votes
4answers
958 views

Making a symbol's new definitions be tried before all previously defined ones

Is there any way to "close" a package (or a symbol, or a context) in that if a user of the package adds definitions to the symbol they will be tried before the package defined ones, just like what ...
35
votes
2answers
5k views

Difference between AbsoluteTiming and Timing

I need to evaluate the efficiency of my code. Therefore I would like to evaluate the time the code need for some calculations. Mathematica gives me two possibilities for this kind of evaluation: <...
17
votes
4answers
1k views

Returning an unevaluated expression with values substituted in

Let's say I have a function formula[x_List] := (x[[1]] - x[[2]]) + (x[[3]] - x[[4]]); and I want to pass it a variable and get back the unevaluated formula with ...
10
votes
2answers
1k views

Why do I have to put Evaluate[] here

I wanted to draw some contours. I succeeded with this: ...
3
votes
3answers
723 views

Help on evaluation control?

I want to plot series of slopes: x, 2x, 3x, 4x, 5x, 6x... I'm trying to do this: ...
28
votes
1answer
3k views

How does Return work?

It is not completely clear to me how Return[] works. The documentation says: Return[expr] returns the value expr from a ...
28
votes
2answers
988 views

Block attributes of Equal

I answered “Equating matrices (or higher order tensors) element-wise” with: ...
22
votes
2answers
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: ...
22
votes
2answers
724 views

Implementing a safe ValueQ that does not evaluate its argument

Mathematica has a built-in function ValueQ. Quoting the docs, ValueQ[expr] gives True if ...
21
votes
6answers
3k views

All curves in plot have the same style. Cannot be fixed with Evaluate[]

Usually, when I plot multiple curves in Mathematica Plot[{x,x^2,x^3},{x,0,1}] they are given different colors. However, if I try to construct a list inside the <...
14
votes
2answers
686 views

Understanding Villegas-Gayley

Temporary message: I have written another question about the behaviour the code by Oleksandr R. . Sadly I clicked "discard" and that was lost. I am a bit demotivated now and in order to not let the ...
13
votes
6answers
4k views

Prevent Part[] from trying to extract parts of symbolic expressions

If you have a list, e.g. {1, 2, 3} then you can extract the $k$th part using Part (...
10
votes
3answers
3k views

Keep function range as a variable

Plot[2*x^2 - x + 2, {x, -1, 1}] plots a function of x from -1 to 1. As far as I can see, I cannot "save" this range in a variable: ...
26
votes
2answers
767 views

Evaluation of OptionValue[]

I have a function that takes an OptionsPattern and I want to access several options, say a, and ...
29
votes
1answer
3k views

A one line proof that one is zero using Mathematica 10

a = (Sqrt[2] + 1) (Sqrt[2] - 1) - 1; {a/a, Simplify[a]/a, b/b == Simplify[b]/b} {1, 0, True} This one line "proof" that ...
14
votes
3answers
349 views

Pattern matching on Orderless functions inside Hold

MatchQ[Hold[1 + 2], Hold[2 + 1]] returns False. But in the presence of a Blank[] in the ...
2
votes
3answers
7k views

Step-by-step definite integration

I am interested in obtaining the intermediate steps for rather straightforward symbolic definite integrations (e.g., from an elementary calculus text). As an example, for $\int_0^1 x\,dx$ I'd like ...
8
votes
2answers
2k views

Normal[Series[ ]] does not give a normal expression

Let us say I want to show how the Taylor's series for Sin behaves: ...
18
votes
3answers
377 views

How can I test properties of a symbol from the string name without the symbol completely evaluating

Suppose I have a few symbols, one of which has a value: {abc1, abc2 = 5, abc3}; I can use Names to get the list of names, as ...
8
votes
1answer
380 views

Where does a package have to be loaded?

I'm trying to solve a very tricky issue in my function. The function needs the NDSolve`FEM` framework. Here is a minimal example: ...
17
votes
1answer
1k views

Get the name of a symbol passed to a function

I'm trying to get the name of a symbol passed to a function with this: f[x_] := {SymbolName[x], x} SetAttributes[f, HoldFirst] x = 5; f[x] But ...
12
votes
2answers
303 views

Working with DynamicModule: Tracking the progress of Initialization

How to track Initialization step by step? Any tricky solution is ok. One condition, x should be ...
11
votes
2answers
408 views

Held keys in associations

Bug introduced in 10.0 and persisting through 11.0.1 or later Bug introduced in 10.0 and fixed in 10.4 Association is new in 10.0. Bug still present: ...
24
votes
1answer
2k views

How can I set a keyboard shortcut to run a command?

I want to use this to add a keyboard shortcut to an undo function I wrote. The basic problem is the following: I have a command, let's say x=1, and I want to run ...
21
votes
3answers
2k views

When must I use the Return function?

In a comment to my answer to this question, QuantumDot asks, "Where can I find more information on when I must use the 'Return' function?". I found this too deep a question to be answered by leaving a ...
18
votes
2answers
309 views

Association's Attributes change between 10.3.1 & 10.4?

In Mathematica 10.3.1 In[1]:= Attributes[Association] Out[1]= {Protected} In Mathematica 10.4: ...
23
votes
2answers
706 views

Context unique to each group at a specified level

Are there any new tools in v10 that might be applicable to this problem? Recent versions of Mathematica provide the option of having a unique $Context for each ...
24
votes
2answers
883 views

Wagner's trick to monitor FindRoot no longer works in Mathematica version 8

I recently learned that we can use Print as a monitoring tool. My favorite is Ted Ersek's example ...
13
votes
3answers
519 views

Unexpected behavior of Unevaluated

This question of mine got a bit ruined by the fact that I got a bit confused. I hope this separate question will take away this confusion. My confusion was that I found it strange that we have, for <...
30
votes
8answers
1k views

Elegant high precision `log1p`?

Sometimes it is hard to understand how numerical expressions are evaluated. I remember reading claims by Wolfram on how smart the Kernel is to evaluate expressions trees numerically by recognizing ...
9
votes
3answers
1k views

Very different results from evaluating same expression with different precisions

When I evalute the following expression, ...
8
votes
4answers
11k views

Mapping multiple parameters of a function to specific values

I am a little bit confused by the documentation for Apply (@@). I want to define a list of parameters, for instance: ...
24
votes
2answers
537 views

Why doesn't a Composition[] hold its arguments and what can be done about it?

Now that Composition (also RightComposition) has shorthand syntax I am more inclined to use it, however what I feel should be ...
10
votes
4answers
399 views

Working with DynamicModule: ScheduledTasks with local variables

I have a question - is it possible to run ScheduleTask[] inside DynamicModule[]? What I have tried so far: ...