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

learn more… | top users | synonyms

32
votes
3answers
9k 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? Example : Let's say I want to ...
28
votes
1answer
509 views

How to compare power towers in Mathematica?

First I tried it directly, but it overflowed: ...
24
votes
9answers
780 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]}] ...
24
votes
4answers
900 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 ...
23
votes
2answers
684 views

Block attributes of Equal

I answered “Equating matrices (or higher order tensors) element-wise” with: ...
22
votes
3answers
725 views

Difference in Plot when using Evaluate vs 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 ...
19
votes
2answers
646 views

Mathematica for Computer Scientists

Background I've coded in C/Scheme for 10 years. I have a BS CS. I've recently become very interested in pattern-matching (lisp's match macro), and term rewriting systems, which brought me to ...
18
votes
2answers
188 views

Evaluation of OptionValue[]

I have a function that takes an OptionsPattern and I want to access several options, say a, and ...
17
votes
3answers
403 views

How can I completely ban usage of some functions in output and mandate use of others?

For example, I hate that Mathematica uses Pochhammer symbol in outputs and prefer all the expressions in Gamma function. How can ...
17
votes
2answers
357 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 ...
16
votes
5answers
326 views

Reassign values to symbols

I've got a situation where I have, say 4 symbols, a, b, c and ...
16
votes
1answer
354 views

How do you set attributes on SubValues?

SubValues, as discussed in a previous question, are declared as follows ...
16
votes
3answers
447 views

Asynchronous evaluation: Is it possible?

Currently we have a limited number of ways to perform asynchronous evaluation. The most common is through Dynamic and ...
16
votes
2answers
280 views

Context unique to each group at a specified level

Recent versions of Mathematica provide the option of having a unique $Context for each cell group, via: Evaluation > Notebook's Default Context > Unique to Each ...
15
votes
5answers
677 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 ...
15
votes
4answers
277 views

Function that caches when it returns unevaluated

How would you go about implementing a function that caches not the result but the fact that it didn't match a pattern? So that it doesn't waste time recomputing a complex time-consuming pattern ...
15
votes
1answer
346 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 ...
15
votes
1answer
198 views

Polynomial expectations of generic distributions

Summary Polynomial expectations depend only moments and cross moments of a multivariate distribution. I would like to use Expectation to compute polynomial ...
13
votes
3answers
176 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 ...
13
votes
2answers
224 views

How to make use of NumericQ[x] = True (and use it safely)?

Basic Issue: I'm trying to understand the proper use of NumericQ's "magical" capabilities. Please consider the examples below. Actual question and some links are ...
13
votes
2answers
303 views

How to REALLY Hold arguments and capture FullForm?

I'm trying to write an expression deconstructor or FullForm-capturer; might even call it a parser, maybe, but that might be too glorious a word. I got some great ...
13
votes
1answer
396 views

Unique[] symbol not properly tracked

In a nutshell, why does this work (change y and see how the value updates) ...
12
votes
2answers
385 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: ...
12
votes
4answers
467 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 ...
12
votes
1answer
107 views

Exclude Sections/Subsections/… from evaluation

I'm working on a large notebook and I want to exclude some sections and subsections from being evaluated when I evaluate the whole notebook. Is there a way to exclude specific sections or ...
12
votes
1answer
226 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 ...
12
votes
2answers
323 views

Preventing Numerical value from being evaluated

I have searched stackoverflow (and comparable pages) for quite a while now (got redirected from there to this specialized stack), and I surrender. I am trying to evaluate an expression that is small ...
11
votes
3answers
219 views

Does AbsoluteTiming slow the evaluation time?

I've started using AbsoluteTiming to discriminate between similar function constructs, but I sometimes feel like it takes substantially more time to evaluate a ...
11
votes
5answers
454 views

How to determine how much of a table is generated?

If I'm generating a table from a slow function, like this: foo = Table[SuperSlowExpression, {1000}] is there a way to determine after submission (so it is too ...
11
votes
3answers
208 views

Numbers in alternate bases transcend the evaluator?

It looks to me like a number in a base other than base 10 gets evaluated before the evaluator ever gets a chance to be tweaked. For example, FullForm[16^^abcdef] ...
11
votes
3answers
241 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 ...
11
votes
3answers
230 views

Comparing Mathematica expressions like diff

I am looking for a way to compare (or "diff") two Mathematica expressions, similarly to how to diff utility can compare two text files and report the differences. Has anyone already written such a ...
11
votes
3answers
290 views

Labeling plots without evaluation

This is my first question here so please excuse my mistakes. Let us consider a rather contrived example: ...
11
votes
2answers
213 views

can a ColorFunction have side effects?

Can anyone explain this (to me) odd behavior. If I run this code once (fresh kernel) it works as intended. ...
11
votes
1answer
320 views

Get the current iteration count

I would like to be able to get the current iteration count, the one that if exceeds $IterationLimit makes the evaluation stop. After not finding a magical variable ...
10
votes
7answers
256 views

Question about evaluation control

I want to make a function that takes a function as a parameter and prints an integral with the function inside. I've tried this: ...
10
votes
4answers
152 views

How do I evaluate the terms in an expression, but not the expression itself?

I am trying to write a set of homework questions. I would like the output to evaluate the constants but not the sum, so that I may present the homework question as something like this: ...
10
votes
2answers
177 views

Make a button that evaluates a function over and over

I would like to have a command "RedoButton" which would make a button (or whatever control is suitable) that when clicked would print the value of a certain function over and over in the same place. ...
10
votes
3answers
191 views

Arguments to If[] are not evaluated

I got bitten by the following: f[x_] := 3*x; g[x_] := If[Log[f[x]] < 0, f[x], 0]; g[x] Out[11]= If[Log[3 x] < 0, f[x], 0] where I thought the call to ...
10
votes
4answers
272 views

Recovering intermediate results from a Table after an interruption

I am interested in knowing if it is possible to recover intermediate results from a Table after an interruption. Let us say I want to produce a really useful table ...
10
votes
3answers
232 views

How can I hold UpValues but evaluate other expressions?

Consider these definitions: own = "OwnValue"; down[_] = "DownValue"; sub[_][_] = "SubValue"; N[n] = 3.14; _[___, up, ___] ^= "UpValue"; The attribute ...
10
votes
3answers
267 views

Why does ++++x return an increment of 2 when the value of x is only incremented by 1?

This line returns 3: x = 1; ++++x However, the value of x after the increment is only ...
10
votes
2answers
337 views

How do you programatically load data into symbols?

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 ...
10
votes
2answers
186 views

How can I access a variable in one evaluator from another evaluator?

I have two notebooks, each with a different kernel. Is there a way to grab the value of a variable in KernelA from KernelB?
10
votes
2answers
260 views

Unexpected differences with various uses of NormFunction

I would expect all of the following to give the same answer (2.12467) but only half of them give this answer. The others seem to be using the default ...
10
votes
2answers
131 views

Subtle difference in conditional rules placement

I had gotten used to thinking of the placement of a condition in a rule definition as logically immaterial. In my specific example, namely ...
10
votes
2answers
264 views

DSolve cannot solve for certain branches of the solution

Could somebody please tell me, why I am always getting an error message when trying to run the following code: ...
10
votes
1answer
145 views

Old values are not freed/garbage collected when you re-evaluate an assignment

For this code: (* Cell 1 *) generate := Module[{x}, x = Range[100 * 1000 * 1000]; x]; (* Cell 2 *) g = generate[]; MemoryInUse[] If I evaluate cell 2 ...
10
votes
1answer
261 views

Manipulate evaluation sequence

Manipulate doesn't always evaluate in the order I expect it to. What is the evaluation sequence for Manipulate and other ...
10
votes
1answer
137 views

Evaluation indicator for a notebook

I have a GUI with a number of TabView and other Manipulate controls. Sometimes clicking from one Tabview to the other can take a while, and I would like to have a global "Please wait" indicator. So ...

1 2 3 4 5