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

learn more… | top users | synonyms

2
votes
1answer
2k views

setting a variable equal to the output of FindRoot

So I set a function f[x] f[x_] := x*E^(-x) - 0.16064 Then I set a variable 'actualroot' to the function FindRoot, starting at 3 ...
14
votes
4answers
504 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 ...
3
votes
3answers
337 views

Help on evaluation control?

I want to plot series of slopes: x, 2x, 3x, 4x, 5x, 6x... I'm trying to do this: ...
19
votes
2answers
871 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 ...
12
votes
4answers
474 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 ...
5
votes
2answers
437 views

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

Let us say I want to show how the Taylor's series for Sin behaves: ...
8
votes
2answers
294 views

Why do I have to put Evaluate[] here

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

HoldFirst and inserting additional options into a Grid of Graphics

This is related to my earlier question, but is specific to an issue I have encountered with the use of the HoldFirst First, let's create some fake data for ...
15
votes
1answer
486 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 ...
3
votes
1answer
142 views

Set promotes Rule to RuleDelayed?

In mentally building a model of how Mathematica works, I naively expected Set to create a Rule in a symbol's ...
9
votes
4answers
218 views

Leave expression tree formatting the same when a replacement rule is applied

If I type e1 := 3 x + 2 (1 + y) z // TreeForm, I get an expression tree. If I then type e1 /. x -> 3, I get another ...
0
votes
1answer
111 views

NIntegrate failling on floating value

I'm trying to take the following integral NIntegrate[ ((Sin[Q 1]-Q 1*Cos[Q 1])/(Q 1)^3)^2 * S[Q,0.4,2] * Q BesselJ[0,0.5Q] , {Q,0,Infinity}] ...
7
votes
2answers
171 views

“A number in base b” and pure functions: why doesn't b^^# & work?

Why do the following not work (in Mathematica 7)? 2^^ # & /@ {1000, 1101} and 2^^ # & @ 1101 This does work: ...
6
votes
2answers
449 views

How do I make NotebookEvaluate work inside Button?

The following creates a button to select a notebook to run. When the button is pressed it seems that Mathematica finds the notebook but cannot evaluate it. The following error occurs Could not ...
4
votes
1answer
202 views

Assumptions seem not to be considered

In the following a,b is a probability distribution, i.e. a+b==1 with ...
11
votes
7answers
322 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: ...
6
votes
4answers
367 views

Attaching persistent assumptions to symbol definition

Is it possible to attach assumptions to a symbol? This relates to this question. Most of my work involves physical equations, i.e. there are basic assumptions on variables that will always hold true ...
10
votes
2answers
469 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: ...
5
votes
2answers
215 views

Why doesn't Evaluate appear to work in this RegionPlot example with MatchQ?

I am trying to plot the region over which a function of two (real) parameters a and b is real-valued, using ...
4
votes
4answers
4k 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: ...
5
votes
2answers
651 views

Speeding up mathematica by subsitituting numerical values

According to this Wolfram Blog post, one can speed up Mathematica code by substituting numerical values as soon as possible. How does one substitute before the main expression is evaluated? The ...
9
votes
2answers
150 views

A notebook created on demand from a main document showing executable input along with output cells

I would like to make Mathematica documents with hidden calculations, such that they can be visualized on demand. In general it can be done in several forms and I actually use some. I would like to ask ...
10
votes
2answers
251 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
2answers
311 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 ...
11
votes
3answers
253 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] ...
4
votes
1answer
370 views

Can a Table iterator “leak” into a Module?

I want to repeatedly call a module by using a Table statement. When I use an i iterator in the Table command calling the module, I receive the error message ...
17
votes
3answers
545 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 ...
3
votes
1answer
251 views

FunctionInterpolation Errors / Question re Evaluation Order and Options

I have using Mathematica functions that takes a Cartesian coordinate relative to the Earth (xyz) and converts it to a latitude, longitude, and altitude (lla). And here it is: ...
7
votes
4answers
1k views

Force function to make assumptions about its input variables in Mathematica

I'm trying to force a Mathematica function to make an assumption about its input variables. In my case, I'm trying to define a function to return the pdf of a Gaussian. But let's use a simple toy ...
5
votes
2answers
662 views

Expression evaluation inside of FindRoot inside a Compiled Function

I'm trying to get some performance increase out of my own implicit differential equation solver using Compile[]. The uncompiled function is of the following form: ...
4
votes
3answers
355 views

Delayed evaluation of assignment

I have a set of PDE's that depend on parameters. They depend on many parameters, but for simplicity we can here assume that they depend only on one, say a. I want ...
6
votes
1answer
188 views

Difficulty catching thrown errors in asynchronous tasks

In this Question, Leonid explained that module variables can get garbage collected from a chain of asynchronous tasks unless their Temporary attribute is cleared ...
6
votes
1answer
238 views

Module variable scoping in Scheduled Tasks?

I ran across a scoping puzzle while experimenting with ScheduledTasks, and I'd be grateful for an explanation from the sages here. I found a workaround by intuitive horse sense, but was unable to ...
5
votes
1answer
118 views

Changes in Handling of Real Zeros

I recently upgraded from Mathematica 5 to Mathematica 8 and I have a number of notebooks that no longer work correctly. The problems relate to the use of units. I don't need complicated unit ...
7
votes
1answer
211 views

How do I write a ValueQ function that only returns True if there exists an OwnValue?

Reading the comments in this answer has motivated me to request a full solution to part of this problem. What I'd like is an efficient solution that returns True ...
12
votes
3answers
309 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 ...
8
votes
1answer
461 views

How to properly DumpSave & Get Global`s symbols inside packages while not touching Global context?

For efficiency reasons I prefer to use DumpSave instead of Save. For ease of access I prefer to save symbols in ...
11
votes
1answer
242 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 ...
5
votes
2answers
307 views

Manipulate Evaluation Order Problem

I seem to be getting some unintended results from a nested Manipulate that I have not been able to resolve. I boiled down the problem I'm having to a simplified ...
7
votes
1answer
285 views

Changing the plot variable inside Plot [duplicate]

Possible Duplicate: Difference in Plot when using Evaluate vs when not using Evaluate Assume one has vector of functions (e.g., vec={x,x^2}). The ...
23
votes
2answers
764 views

Block attributes of Equal

I answered “Equating matrices (or higher order tensors) element-wise” with: ...
5
votes
1answer
148 views

Impossible to bypass evaluation on returned values?

Following all the great advice on this other question, I'm now fluent with HoldAllComplete and Unevaluated on the input side of ...
10
votes
2answers
166 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 ...
15
votes
4answers
617 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 ...
3
votes
2answers
275 views

Efficiently evaluating a held expression directly from a list

I am able to evaluate a held expression that I have put on a list by: ReleaseHold[expressionList[[1]]] and ...
13
votes
2answers
407 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 ...
19
votes
5answers
1k 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 ...
8
votes
2answers
383 views

Exporting held expressions through JSON

Trying to round-trip expressions through JSON, I'm getting unexpected errors for held expressions, and would be grateful for advice or clues. Consider, first, something that works well ...
8
votes
2answers
676 views

Mathematica rule substitution memory

First I present the specific programming question, and then I provide further background details. Given an expression in Mathematica, say f=3x+7y, there are two ...
8
votes
2answers
497 views

How to make Mathematica re-evaluate a cell after some event?

I am doing a little project to demonstrate something: ...