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

learn more… | top users | synonyms

15
votes
4answers
785 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 ...
15
votes
3answers
287 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 ...
15
votes
2answers
385 views

Shell Emulation inside Mathematica

I am trying to create a Mathematica/shell syntax hybrid. I would like the following command wget -qO- "http://google.com/space line break\"" $var to be ...
15
votes
2answers
306 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?
15
votes
2answers
206 views

How to find out what files are touched when Get is called?

Is there a way to capture all package files touched whenever a package is called via Get, Needs, ...
15
votes
1answer
371 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 ...
14
votes
4answers
2k 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
891 views

How does Mathematica determine that an evaluation should be terminated?

How exactly does Mathematica determine that evaluation of particular expression should be finished and the result should be returned? Here are some examples of unclear behavior which have arisen, ...
14
votes
3answers
395 views

Clever use of DownValues, or failure to understand the “Mathematica Way.”

I needed to look at the changes in the values of about 4000 items from one year to the next. I have a table with identifiers and values for each year. Not all of the items are in each list. The ...
14
votes
2answers
370 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 ...
14
votes
2answers
519 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 ...
14
votes
1answer
442 views

What is the real default CellEvaluationFunction?

The default CellEvaluationFunction is Identity but one can quickly see that this is handled specially as an equivalent function, ...
13
votes
3answers
760 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 ...
13
votes
4answers
362 views

Using With to scope over pure functions

Consider this example: given an option for a function func as "x" :> (a&), how can one assign different values to ...
13
votes
3answers
263 views

Selective evaluation of blocks of code in a Manipulate

Is it possible to attach certain pieces of code to certain controls in a Manipulate? For example, consider the following Manipulate ...
13
votes
2answers
161 views

Why the Block command does not forget the $ContextPath variable

I do not understand this behavior: ...
13
votes
4answers
368 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. ...
13
votes
5answers
256 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}. ...
13
votes
2answers
548 views

How do I get Mathematica to return a function call unevaluated?

How do I get Mathematica to return a function call (conditionally) unevaluated? I expect this may use the slightly-mysterious Hold function. As a toy example, ...
13
votes
2answers
377 views

ScheduledTask with scoped variables. Working with timed evaluation

I guess I have to try harder and focus more but timed evaluation always frustrates me. I will show the issue on simple example of delayed trigger. ...
13
votes
3answers
462 views

Handling Kernel quit

One can use $Epilog to do something when the Kernel is quit or put an end.m file next to the ...
13
votes
1answer
542 views

Evaluation indicator for a notebook

I have a GUI with a number of TabView and other Manipulate controls. Sometimes clicking from one tab view to the other can take ...
13
votes
1answer
555 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 ...
13
votes
1answer
449 views

Unique[] symbol not properly tracked

In a nutshell, why does this work (change y and see how the value updates) ...
12
votes
3answers
7k 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
7answers
628 views

How to properly inject iterators into table? [duplicate]

Goofing off on a prior question, I was fiddling with other methods, which led me to the need to inject a constructed set of iterators into a table construct. Now, ...
12
votes
3answers
292 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] ...
12
votes
3answers
598 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 <...
12
votes
3answers
264 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 ...
12
votes
4answers
504 views

How to pass a list of arguments into HoldAll

I have a list of arguments (which in reality is lengthy): arguments = {a, b, c} arguments2 = {a_, b_, c_} f[Sequence@@arguments2] := a + b + c Note: It seems ...
12
votes
1answer
890 views

Why is this 2D plot so slow?

I first do a 3D Plot of four surfaces (eigenvalues of a $4\times4$ matrix) over $kx,kz$ (setting $ky=0$ all along). And then I try to give a 2D plot along three connected particular lines in $kx,kz$-...
12
votes
2answers
5k views

How do you force a decimal output? [duplicate]

I have some very small values such as 2.601519253*10^-8. I'd like to output these values to CSV for another program to work with. I've tried N[value, 50], but Mathematica still insists on producing ...
12
votes
2answers
502 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
7answers
343 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: ...
11
votes
4answers
194 views

Evaluation of Alternatives

I recently stumbled upon a few examples that suggest patterns containing Alternatives do not evaluate for individual alternatives. For example: ...
11
votes
4answers
214 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: $$\sum_{n=1}^...
11
votes
2answers
345 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. ...
11
votes
2answers
231 views

Bags and non-standard evaluation

What can internally be happening here? Is the evaluator just messing with us and going non-standard because it's a Bag? Or am I just not seeing how something like ...
11
votes
3answers
239 views

Creating a custom context with a Hold construct

I'm trying to create a function "InContext" to execute a piece of code inside a certain context (and to return the result of evaluating that piece of code). One approach is to place the code inside a ...
11
votes
2answers
414 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 ...
11
votes
3answers
422 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 ...
11
votes
1answer
533 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 ...
11
votes
2answers
785 views

DSolve cannot solve for certain branches of the solution

Update - This has been fixed in 10.0.0 Could somebody please tell me, why I am always getting an error message when trying to run the following code: ...
11
votes
1answer
318 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 repeatedly,...
11
votes
1answer
278 views

TimeConstrained dynamic change of maximum time

I would like to run a time consuming function: TimeConstrained[f[x],maxseconds] and be able to change maxseconds during running (increasing or decreasing max ...
11
votes
3answers
785 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
1answer
286 views

Why does Plot[Hold[x], {x,0,1}] work?

It appears that, counter to my expectation, all of these (and probably many others) seem to work fine: ...
11
votes
2answers
277 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
2answers
183 views

stop notebook evaluation when Assert fails

I would like a notebook evaluation to entirely stop when an Assert fails, without quitting the kernel. Is this possible (e.g., by setting ...
11
votes
1answer
2k views

Can Mathematica do two evaluations at the same time?

When one evaluation is running, if I want do another evaluation, Mathematica will put the second one in the queue and run it after the first evaluation finish. However, the first evaluation may take ...