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

learn more… | top users | synonyms

10
votes
4answers
242 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 ...
10
votes
2answers
230 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 ...
10
votes
4answers
336 views

How to take and evaluate a specific part of a list without evaluating the rest?

I have a large list, for example, lis = {x + y, x y, Sin[x] y + Exp[y], x^2 y} and its elements depend on variables x and ...
10
votes
3answers
3k views

Keyboard shortcut to evaluate notebook

(If this is entirely trivial, although I couldn't find an answer as much as I searched the archives, I will delete the question.) How could I add a keyboard shortcut to evaluate the entire notebook ...
10
votes
3answers
350 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
403 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 ...
10
votes
1answer
340 views

Why does the documentation call functions “pure”?

Clearly, functions in mathematica are not pure functions according to the definition on Wikipedia (no side effects - basically implementabe with table lookups): ...
10
votes
2answers
189 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
337 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
1answer
443 views

A problem about the implementation of Bezier curve

I implemented the Bezier curve like built-in BezierCurve as follow: SplineDegree -> d specifies that the underlying ...
10
votes
2answers
275 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 ...
10
votes
1answer
123 views

Aborting from inside a ScheduledTask

If you have an Abort[] inside a ScheduledTask expression, what does it abort? The scheduled task evaluation, or any main kernel ...
10
votes
1answer
471 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
122 views

Use EvaluationCompletionAction to notify me only after long evaluation

Is it possible to use the option EvaluationCompletionAction to notify me (e.g. with a Beep[]) when an evaluation that took ...
10
votes
2answers
175 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 ...
10
votes
2answers
312 views

Another difference between Set and Setdelayed. Evaluation shortcut?

A little while ago I wondered why f[x_] = f[x] gives an infinite iteration. I ended up discovering the following difference in evaluation between ...
10
votes
2answers
306 views

Return partial result when MemoryConstrained aborts NDSolve

I use NDSolve to solve a large set (~400) of coupled ODEs. Sometimes, the memory (~4GB) gets filled up, and my computer becomes impossible to work with, because it ...
9
votes
3answers
365 views

How to write a function-defining function which stores the function arguments in a stack?

I have a function-defining function SetAttributes[DefFn, HoldAll]; DefFn[f_[args___], body_] := f[args] := body; I am trying to modify this function to record ...
9
votes
3answers
311 views
9
votes
2answers
320 views

How to see which arguments are passed into a function

It is often that one wonders which arguments are evaluated before being passed into a function. I would like to know if it is possible to see which argumets are being passed into a function without ...
9
votes
2answers
469 views

Why do I have to put Evaluate[] here

I wanted to draw some contours. I succeeded with this: ...
9
votes
2answers
350 views

Using up-values and down-values

I have a problem I'm trying hard to find a solution for, although I don't know if a solution exists. The following rules produce the result e[2].f[] ...
9
votes
2answers
768 views

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

I am doing a little project to demonstrate something: ...
9
votes
1answer
106 views

Different behaviour of ValueQ inside and outside of a loop

I need to store a rather big number of variables and I tried to do that by storing each variable as Z[n] with varying n. I guess this was not my best idea. The first problem I encountered is when I ...
9
votes
2answers
420 views

Defining a ForEach function

Consider the following function definition: ForEach[iterators__] := Table[#, iterators] &; Two questions about it: I. It works perfectly if you call it like ...
9
votes
1answer
157 views

Tracking Initialization

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

Menu item “Interrupt Evaluation…” missing in V10

The menu item “Interrupt Evaluation…” seems to have disappeared in Mathematica 10 on OS X. Well, this is a bummer. I personally use Mathematica for very long calculations, and I was using this ...
9
votes
3answers
180 views

Implement settable properties

I am looking for advice on implementing the following. (It is possible that the answer is that it is simply not a good idea to do this.) I would like to have an object similar to ...
9
votes
2answers
367 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 ...
9
votes
1answer
141 views

Is it possible to use the global definition of a symbol as part of its new local definition set in a Block?

Consider the following expression: Block[{Print = CopyToClipboard}, doSomething[]] Now all calls to Print from ...
9
votes
1answer
134 views

Why does $Failed have attribute HoldAll?

Why does $Failed have attribute HoldAll? Are there typical situations where $Failed is ...
9
votes
2answers
182 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 ...
9
votes
1answer
357 views

Performance of Dispatch and lists of Rules

The issue outlined here seems to be no longer present in version 10, if you use a Dispatch table! This because a Dispatch table ...
9
votes
1answer
148 views

Prevent Plus from threading InterpolatingFunction

For an InterpolatingFunction $y:\ \mathbb{R}\to\mathbb{R}^2$, Plus is unaware of this, so when I do any modifications to it in ...
9
votes
1answer
181 views

Comparing exact expressions for equality — is it really OK if I get wrong answer?

Bug introduced in 7.0 or earlier and fixed in 10.2.0 I found an unexpected behavior (that I think of as a bug) in evaluation of the equality operator applied to mathematical functions with exact ...
9
votes
0answers
66 views

Is there a way to TagSet a HoldAllComplete function?

Let's say I want to overload the built-in function Lookup, to handle my data wrapped in myObject. One would use ...
8
votes
4answers
7k 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: ...
8
votes
4answers
294 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 ...
8
votes
5answers
310 views

Generate list of strings from a list of assigned variables

How do I generate a list of strings from a list of assigned variables? Eg. Convert ...
8
votes
2answers
321 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 ...
8
votes
2answers
224 views

Why does the name of a pattern affect the result of a transformation rule?

I was playing a little dirty, trying to get a template for defining a Curl[] operator. I wrote the following rule, which I knew was going to spit out a few ...
8
votes
4answers
2k 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 ...
8
votes
3answers
827 views

Why are functions called first-class objects in Mathematica?

I've heard lots of people say a function is a first-class object in Mathematica. "Everything is an expression, including function." "There is no distinction between functions and data." Having read ...
8
votes
3answers
239 views

Graphics in Notebook Different from Graphics Expression?

Consider the expression TreeForm[a+b^2+c^3+d] which displays as This is a nice Graphics object, as I can prove by typing ...
8
votes
3answers
179 views

Expand series unevaluated

I'm newbie in Mathematica. I'd like to obtain nice and verbose output for any series calculation. For example, given a simple sequence n*(-1)^(n-1) and ...
8
votes
2answers
1k views

Obtaining the name of a variable as a string [duplicate]

Suppose that I have an arbitrary variable myVariable. Is there some function fun -- either built-in or one that I can define -- ...
8
votes
2answers
209 views

Keywords to find documentation for this syntax

Mathematica allows this syntax, but I cannot find any documentation (or books) that discuss the various uses/advantages of it ...
8
votes
3answers
175 views

With/Function(/etc) replacement behaviour

Can anyone explain to me this behaviour? I've been having more than a couple of similar doubts these last weeks. For example f[_?NumericQ] := 8; Now, if I do ...
8
votes
2answers
284 views

Difference between Evaluation>>Quit Kernel and Quit[]

What is the difference between Evaluation >> QuitKernel and Quit[]? Both seem to quit the kernel (and clearing all ...
8
votes
2answers
192 views

Obtain input expression from history without evaluating

I typed and evaluated an expression, but deleted it from the notebook. For instance, suppose it was In[1]:= Round@SessionTime[] Out[1]= 2 I now want to retrieve ...