Tagged Questions

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

122 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 ...
55 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: ...
650 views

Incorrect result from Integrate

Bug introduced in 8.0 and fixed in 10.0 I attempted to calculate the following integral: ...
122 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 ...
65 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 ...
153 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 ...
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 ...
110 views

Cannot Block Plus

It is customary to use the following idiom to partially evaluate something inside a held expression: ...
412 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. ...
140 views

Inserting symbols' definitions during read time of the code

Let's say we've got a package: ...
184 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 ...
186 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 ...
276 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 ...
789 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 ...
327 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 ...
165 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 ...
105 views

Some _atomic elements' TreeForm looks confusing with Level in appearance

In[1]:= Level[1/2,{-1}] Out[1]= {1/2} TreeForm[1/2] ...
130 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: ...
19 views

Manipulate inside Module - “Order of evaluation conflicts” [duplicate]

In this example, Manipulate is contained within a Module: ...
73 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. ...
136 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] =...
54 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 ...
89 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 ...
69 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 <...
171 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: ...
64 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: ...
124 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 ...
108 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: ...
143 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: ...
169 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 evaluation)....
365 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 ...
119 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 ...
108 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 ...
59 views

Display a part of a notebook when MMA has done evaluating it

When you evaluate a notebook, it begins to slide upward and shows you a different part of your code, several cells upstream of the notebook... I was wondering if there is a command that could always ...
81 views

Failure in the use of FullSimplify

My question is about an apparent failure of the function "FullSimplify" to simplify an easy algebraic expression. This is the expression that I ask Mathematica to evaluate: ...
81 views

A With and ContourPlot difficulty

Consider: sys = {u (1 - u + a v), r v (1 - v + b u)}; With[{a = 2, b = 3, r = 1}, Evaluate[Thread[sys == {0, 0}]]] Which gives the output: ...
219 views

Evaluation of the second argument to NIntegrate

The expression Integrate[x^2, Flatten[{{x},{1,2}}]] evaluates properly, to $\frac{7}{3}$. However, ...
188 views

Can I define an axiomatic (Boolean algebra) system and prove theorems using Mathematica?

The general question is Can I define an axiomatic system and prove theorems using Mathematica? The more concrete one is about Boolean algebra. I consider this axiomatic Boolean algebra system (...
1k views

How do you set attributes on SubValues?

SubValues, as discussed in a previous question, are declared as follows ...
369 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 ...
86 views

How to force evaluation of an expression with Part left unnevaluated?

My goal is to minimize a real valued multi-variable function averageFreeEnergyDensity. The function accepts an integer argument n...
168 views

Force Dispatch to generate dispatch tables

Dispatch creates hash tables only for lists of length larger than 3. Is there any way to force MMA to create hash tables even for lists of length smaller than 4? ...
154 views

How to map Unevaluated over a list

I have a list {a1, a2, ...... , an}, in which all as have been initialized to a number. I want to get: ...
170 views

When are numerical expressions identical

Very elementary: 2 + 3 == 5 evaluates to True and 5 == 5 evaluates to ...
43 views

Find the numerator of 6/8 [duplicate]

The statement Numerator[6/8] evaluates to 3. Numerator[Hold[6/8] does not work. What function NewNumerator[6/8] evaluates to 6?
616 views

Quit the Kernel and start new session automatically

The question is how to quit the kernel, start a new session automatically, and to be able to run such procedure from e.g. Button. This is especially useful when ...
81 views

Evaluation speed of apparently equivalent functions

Consider the following expressions: f[x_Integer] := x, f[x_] := x /; x ∈ Integers, f[x_?IntegerQ] := x All of the expressions above (and probably others which ...
69 views

How to print unevaluated arguments in the form they were originally typed in?

I'm looking for a way to print a function's arguments, not only unevaluated, but also in the way they were originally typed in. By way of experimentation, I tried stuff like this: ...