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
3answers
70 views

Keep leading/trailing zeroes (like Defer except with numbers) in a given number

I'm trying to write a function that counts the number of significant figures a given number has so I can ensure my calculations are rounded correctly; however, I am having a lot of trouble preventing ...
0
votes
0answers
46 views

How to determine how much time it will take to finish a cell expression?

I am trying to integrate a large matrix with elements that contain trigonometric expressions. The evaluation is taking a long time--4 days, and it is still running. Is there anything I can do to find ...
1
vote
4answers
117 views

Do not expand matrices in Mathematica calculation

Here is an example of a problem I'm having. Consider that I have defined: omega={{p[t]},{q[t]},{r[t]}} x={{a},{b},{c}} R={{1,2,3},{4,5,6},{7,8,d}} What I would ...
9
votes
2answers
321 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 ...
1
vote
1answer
42 views

problem about Root and Hypergeometric2F1

See these example, why does the output is different? ...
1
vote
0answers
40 views

Why does the same function defined by Set and SetDelayed look different? [duplicate]

I start with the following input: f[n_] = Sum[(1+x)^j, {j,1,n}]; g[n_] := Sum[(1+x)^j, {j,1,n}] When I try to evaluate the code above I get: ...
0
votes
1answer
164 views

Understanding output of multivariable integration

I'm new to Mathematica and I'm trying to integrate this function: ...
-2
votes
1answer
74 views

Why is my function returning 0 when when I try to give it arguments by replacement? [closed]

I tried running a function f with rules and calling it directly with arguments specified directly but the one with rules returns zero while the one with direct ...
3
votes
1answer
109 views

Strange integration

Bug introduced in 9.0 or earlier and fixed in 10.1 Note: Beginning with V10.1, this integral returns unevaluated but without error messages. I tried to evaluate this line ...
1
vote
1answer
50 views

How to achieve fun[Unevaluated[f][Unevaluated[x], Unevaluated[y]] in a more elegant way?

I have defined a function fun[f_[x_,y_]]. When I call it, I want to wrap everything by Unevaluated: ...
20
votes
1answer
541 views

Incorrect result from Integrate

Bug introduced in 8.0 and fixed in 10.0 I attempted to calculate the following integral: ...
6
votes
2answers
94 views

Force evaluation of the right-hand side of a local variable definition

One can do expression = a + 1; f[a_] := Evaluate[expression] but how would one do something like this ...
3
votes
1answer
42 views

SelectionEvaluate executes out of turn

I'm seeing some unexpected (to me) behavior from SelectionEvaluate. I've got a notebook with two sections. In section 2, I've got code that clears the notebook's ...
3
votes
2answers
120 views

Even with Evaluate[], Mathematica is plotting everything in the same color

The code evals[x_?NumericQ] := Eigenvalues[{{x^2, 2 x}, {x, 3 x^2}}]; Plot[Evaluate[evals[x]], {x, -1, 1}] gives both eigenvalues in the same color. I thought ...
48
votes
9answers
2k 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]}] ...
15
votes
2answers
1k views

What happens when you divide by ##?

I've been playing around with sequences a bit. In particular with using ## with unary and binary operators. Let's start simple, the following all make some kind of ...
7
votes
2answers
102 views

Cannot Block Plus

It is customary to use the following idiom to partially evaluate something inside a held expression: ...
13
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 ...
56
votes
4answers
4k views

Plot draws list of curves in same color 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 ...
3
votes
1answer
342 views

Summation of If statements

The following made me curious. Suppose you want to sum the if statement If[x[i] < 1., x[i]^2, 0.] over i=1,2, i.e. ...
7
votes
1answer
152 views

Trouble with polynomial multiplication

Bug introduced in 10.1.0 and persisting through 10.2.0 or later ...
7
votes
2answers
128 views
9
votes
2answers
220 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 ...
2
votes
2answers
161 views

Optimize evaluation time for a Quantum Walk simulation

Here's the problem. I'm trying to simulate a noisy Quantum Walk to obtain results similar to these, experimentally obtained. I wrote my code, and I get results which are in accordance to what I ...
15
votes
3answers
283 views

Can't inject EncryptedObject

Bug status Introduced with Encrypt in 10.0 Still there in 10.2 Here are minimal examples: ...
9
votes
1answer
167 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 ...
4
votes
1answer
100 views

A pre-parsed HoldForm

HoldForm holds an expression's parsed form not its actual "inputted form" e.g. ...
5
votes
2answers
211 views

How do I “evaluate in place” programmatically? Need to evaluate Defer[] result in non-interactive setting

I need to evaluate the result returned from an external package, which contains Defer in it, but do this in a script without user interaction. I am not able to ...
20
votes
7answers
618 views

Elegant high precision `log1p`?

Sometimes it is hard to understand how numerical expressions are evaluated. I remember reading claims by Wolfram on how smart the Kernel is to evaluate expressions trees numerically by recognizing ...
8
votes
2answers
291 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 ...
4
votes
5answers
154 views

Using Through with SlotSequence

I have an expression consisting of a few pure functions added together like so: f+g+h I want to add the bodies of these functions together and make that a pure ...
3
votes
1answer
101 views
7
votes
1answer
116 views

Unevaluated @ {args} versus Unevaluated /@ {args}

Working my way through Robby Villegas's lovely notes on withholding evaluation, I almost got Polish Notation on my first try. Here is my final solution, which seems to work well enough: ...
1
vote
0answers
15 views
6
votes
0answers
139 views

NMinimize with NIntegrate (crash in symbolic evaluation, memory leak)

This is a "common" problem from what I've seen, but with a different spin. I have a function I use often that finds a fit of an expression to another expression with some free parameters (e.g. for ...
2
votes
1answer
49 views

Non-autonomous Dynamical system Sliding mode controller Error

This code is a simulation of a sliding mode controller of a non-autonomous dynamic. When I use ArcTan in input, I receive an error. ...
4
votes
2answers
110 views

Simplifying expression with non-commutating entries

Say I have an expression such as (a + X)**(b-Y) where the variables above possess the following commutation relations [a, b] = [a, X] = [a, Y] = [b, X] = [b, Y] ...
3
votes
0answers
51 views

Why does FreeQ seem not to work with complex numbers?

I guess I do not understand how Mathematica evaluates this simple expression inside FreeQ ...
2
votes
1answer
86 views

Return the incomming expression on false

when I have an expression, that is unknown to mathematica, it is returned exactly the same, as it was called. For example SeeFlyingPigs[1,2] called on the line ...
4
votes
1answer
65 views

How to define an expression which is differently evaluated in calculations and printed

Let's say, we have a list: values = {1.2, 0.04, 0.9}; Is it possible to replace 0.04 by some expression, which displays as ...
1
vote
2answers
100 views

Why does Mathematica not evaluate the difference recurrence using `RSolve` or `RecurrenceTable`?

Mathematica does not evaluate the following recurrence of two variables using RSolve and only echoes the input: ...
1
vote
3answers
60 views

Controlling the evaluation of other arguments in pure functions [duplicate]

I have a piece of code where I would like to do the something like the following: ...
2
votes
1answer
105 views

How to extract a variable names (not values) from a list of transformation rules?

I am trying to extract variable names from a list of transformation rules mapping = {var1 -> 'val1', var2 -> 'val2' }. Variables ...
4
votes
1answer
76 views

Formal Differentiation

I'm trying to formally differentiate an expression. (I am aware of how to differentiate formally?, but am unable to generalize the idea) For example: ...
6
votes
3answers
127 views

Evaluate a expression split in a list

I have a list with this format {integer, sign, integer, sign, integer}, sign being one of these: Plus, Subtract, Times, Divide. For example, let's say: ...
2
votes
2answers
99 views

How can I partially evaluate a function?

I have a multivariable function, from which I'd like to define a marginalization: f(a,b,c,d,...,z) ---> g(a,1,c,d,...,z) Generally, g will have fewer argument than f, possibly none (full ...
3
votes
1answer
207 views

Expanding huge expressions that simplify and factor

The following is for Mathematica 8.0.4 running on Windows 7 laptop (6GB memory). I have eight expressions that are unexpanded multivariate polynomials in 6 variables. They are huge expressions, so ...
1
vote
0answers
75 views

How to Implement a “Function Object” suitable for NDSolve and Finite Element Method?

I have a bunch of methods that shoud return an expression that behave like a function, i.e. an expression that, when supplied with suitable arguments, evaluate to something. A simple ...
3
votes
3answers
103 views

How to force evaluation on the right of an @ operator?

Is there a way to force evaluation on the right before the Prefix operator (@) without using parentheses? I came across this question when I was working with the ...