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

learn more… | top users | synonyms

0
votes
0answers
117 views

How to evaluate only arguments, but leave topmost expression unevaluated? [duplicate]

I want to represent expressions mostly in unevaluated form, but being able to evaluate it's subparts. For example, how to evaluate only arguments, but leave topmost expression unevaluated? For ...
0
votes
0answers
127 views

Integrating and plotting pde system solution

I have a trouble with plotting a pde system solution. I'm solving a PDE system in 2-dimensional space and then I want to integrate the solution along one dimension and build a log plot along the ...
19
votes
5answers
544 views

Reassign values to symbols

I've got a situation where I have, say 4 symbols, a, b, c and ...
14
votes
3answers
234 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 ...
18
votes
2answers
468 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 ...
6
votes
2answers
274 views

Why is CityData[All, “Coordinates”] failing?

When I evaluate CityData[All, "Coordinates"] Mathematica returns {Missing["NotAvailable"], Missing["NotAvailable"]} ...
1
vote
1answer
3k views

Evaluate an expression at a specific point

In Maple, you right click and can evaluate an expression (whatever it is) at a specific point say: Expr.= abcddafjosjfoj, then right click and simply evaluate at c=-34 say. But how does one do the ...
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 ...
4
votes
1answer
188 views

Is there a way to force Mathematica 8 to expand $z^{a+b}$ into $z^a z^b$?

The function PowerExpand[z^(a+b)] does not transform $z^{a+b}$ into $z^a z^b$. Is there a way to force Mathematica 8 to expand $z^{a+b}$ into $z^a z^b$? In this ...
10
votes
2answers
218 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 ...
5
votes
0answers
157 views

Context “Unique to This Notebook” makes variables black even if they're not defined?

I'm trying to use this technique to keep variables separated between different notebooks. It seems to be working fine, except that variables turn black as soon as they are evaluated — any ideas why ...
4
votes
3answers
301 views

Unexpected behavior of Unevaluated

Maybe it is about time I read some proper text about the main loop. Maybe I should not care (so much) about Unevaluated (as Leonid suggests). But I think this is an interesting question anyway. This ...
0
votes
3answers
151 views

Evaluation in Manipulate [duplicate]

I have an expression assigned to a variable. For example: exp1 = a*x+b Now I would like to plot it using something like this ...
5
votes
3answers
220 views

Applying a function with the HoldAll attribute inside NestList

I'm trying to write an update function, which can be applied to a list and then to NestList it. As the function has to manipulate the given variable I figured I ...
1
vote
2answers
109 views

Automatically evaluating related cells

I have the cells: In[1]:= l = 2 + 2; In[2]:= l >= 5 After evaluating them: Out[2]:= False Is there a way to evaluate ...
1
vote
1answer
179 views

Confused about Unevaluated

Why does Map[Unevaluated, Table[PauliMatrix[i], {i, 1, 3}] give {Unevaluated[{{0, 1}, {1, 0}}], Unevaluated[{{0, -I}, {I, 0}}], Unevaluated[{{1, 0}, {0, ...
20
votes
2answers
911 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 ...
1
vote
1answer
140 views

direct assignment to the element in a Table

I have already asked a related question here why set values in this way doesn't work? But I think I have to write the question which I encountered explicitly? ...
14
votes
3answers
473 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 ...
2
votes
2answers
212 views

Evaluating Polynomials at Grid Points

I am continuing my quest on B-splines. The code below builds a 5x5 matrix out of B-splines, using the BSplineBasis[] routine. I now want to evaluate the polynomials that are stored in each matrix ...
8
votes
2answers
3k 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 ...
5
votes
1answer
105 views

“And” to continue evaluation after “False”

Below, is it possible to print No and have x be 2. That is, I'm looking for an And-like function that looks at all arguments ...
38
votes
9answers
1k 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]}] ...
7
votes
2answers
204 views

Is there a way to show the details of a numerical computation?

I have recently started using Mathematica as a calculator while teaching (definitely overkill, but I try to use as few tools as possible). I would like my students to be able to trace simple numerical ...
4
votes
3answers
385 views

Why the difference?

When I do the double sum using the sigma notation I get $$1 + \sum_{n=0}^{\infty}\sum_{k = n}^{\infty} \frac{1}{(k+2)k!}$$ $1 + e - \cosh[1]$ When I do the sums as below, I get the expected ...
0
votes
1answer
111 views

Can I force a function to quit and return some value after a certain amount of time has passed during its evaluation?

Imagine I provide some random input to function like FindInstance[], and I observe that, despite the existence of good solutions, the function will, with some ...
5
votes
2answers
234 views

Graph does not evaluate some options when not displayed

How can I force Graph to evaluate all its options without actually displaying the graph itself? Evaluating the following code ignores the ...
0
votes
2answers
122 views

Symbolic evaluation fails because it exceeds $RecursionLimit

I am trying to perform a simple arithmetic in complex algebra. ...
0
votes
4answers
793 views

Specify a variable as an integer

I have a formula that always evaluates to a certain number for any variable X under one condition that X is an integer and ...
4
votes
2answers
789 views

How do you configure Mathematica 9 to automatically evaluate all notebooks?

I have a Mathematica 6 course that I am using in Mathematica 9; there is no updated version. Every time I open a notebook I have to go to the Evaluation menu and click on "Evaluate Notebook". Is there ...
13
votes
1answer
437 views

Unique[] symbol not properly tracked

In a nutshell, why does this work (change y and see how the value updates) ...
3
votes
3answers
204 views

Alternative to using global variables in functions?

Often times I find myself using unevaluated variables (i.e. they show up blue) as dummy variables in whatever I'm returning such that I can evaluate them as needed later on. A simple example is as ...
37
votes
4answers
2k 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 ...
5
votes
2answers
226 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 ...
3
votes
0answers
66 views

Non-preemptive evaluation of a dynamic function? [duplicate]

I want to monitor a long calculation that is triggered by the release of a Slider. While one can indicate running calculations when the main evaluation loop is ...
2
votes
2answers
132 views

How to make Mathematica returns the exact expression I typed

I'm using Mathematica to compare some constants. Before playing around with those constants, I would like to check that I didn't make any mistake in typing them. So my question is the following: "What ...
1
vote
1answer
142 views

Evaluate code to some point

How can I evaluate my code, up to some point? I don't want to evaluate all of my code always. I have to use Shift - Enter for every line from the first cell up to the point I want to be, and it's not ...
10
votes
4answers
349 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 ...
0
votes
0answers
37 views

Define a Plot3D function with custom options [duplicate]

I am trying to define a Plot3D function with custom options, following (this previous SE question), but I'm running into a brick wall. I've narrowed the problem to the following 'toy' code: ...
12
votes
1answer
432 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 ...
1
vote
0answers
54 views

Confusing efficiency and evaluation when returning pure functions? [duplicate]

I have a function that takes some time to evaluate, that's meant to be a polynomial approximation to a function. The polynomial is defined by a list of coefficients, so I have the function ...
10
votes
4answers
185 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: ...
0
votes
1answer
279 views

NumericQ prevents evaluation at a numerical value sometimes

I set up a symbolic integral, to be evaluated only when some of the symbols have been replaced by numbers. The evaluation after assigning numbers to the symbols is still symbolic for some reason. The ...
4
votes
1answer
136 views

Identical code, different answers?

I'm having some trouble with identical code giving different answers. On a fresh kernel (MM 9.0.0.0, Windows 64-bit), running the same code, copy-paste, gives two different answers: ...
0
votes
1answer
218 views

Why won't ContourPlot accept a variable argument? [duplicate]

I have a list of linear inequalities which describe a (polygonal) region. I can use RegionPlot to visualize this region; but I'd also like to overlay this plot with ...
6
votes
3answers
800 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: ...
3
votes
1answer
98 views

Stop TradtionalForm evaluating expression

I'm trying to get this expression to display as typed instead of evaluating the 1/1.121. ...
1
vote
1answer
404 views

Forcing evaluation of ArgMax

How to force evaluation of ArgMax before its output gets used in Solve? Background: I'm trying to solve for the Nash ...
2
votes
1answer
270 views