# Tagged Questions

Questions on optimizing Mathematica code for higher performance. This may mean faster execution, lower memory usage or both. Not to be confused with mathematical optimization.

71 views

### Get position from one list and choose element of another list in Compile

How can do it? ...
27 views

### Coefficient of function with general argument

I would like to obtain the coefficients of a general function f in a list. For example, the coefficient list of ...
264 views

### Why is SatisfiabilityCount faster than SatisfiableQ?

Consider the following (large) Boolean expression, which arose in a SAT problem. (The expression is not satisfiable.) ...
52 views

### Compilation error: “Could not complete external evaluation at…”

I'm pretty new to trying to use Compile[], and I just can't see why I'm getting this error. I have two functions to define beforehand; one of them is a bit odd: ...
70 views

### How can I obtain the same result without using any loop?

I have a piece of code as below: For[i = 1; t = x, i^2 < 10, i++, t = t^2 + i; Print[t]] and the result is: ...
290 views

### How to “inform” successive ContourPlot calculations?

I need to draw some contour plots of very non-linear functions. As a simple example, take a Mandelbrot Set divergence contour near $z\approx i$. (Just to be clear, I'm not trying to write a ...
163 views

### How to find the derivative value at $(\pi,0)$ for this implicit function $n$ times?

I am trying to take the implicit derivative at $\sin(x+y)+\sin(x)=y$ and substitute $x=\pi$ and $y=0$ at least 6-7 times since I need to find the Taylor series for this function. Since I barely ...
224 views

### Speed up construction of a dense matrix

I wish to find the numerical eigenvalues of a relatively small (100 dimensional) Hermitian matrix. While the eigenvalue calculation itself is fast, the construction of the matrix is taking longer than ...
131 views

### Call Magma in Mathematica

I've written some code in Mathematica, related to some group theory questions I have. Subsequently, I found that part of the code could be significantly sped up if I could just call a routine in ...
90 views

### Is it possible to prohibit unnecessary CopyTensor in Compile? Just like .noalias() in Eigen library?

Turn on Needs["CompiledFunctionTools"] First example ...
116 views

### How to increase the evaluation speed of this somewhat complicated table / matrix operation?

I'd like to calculate the following one-dimensional array: OneDimArray = Table[(Norm[Sum[ MatrixA[[i,j]]VectorB[[j]],{j,N}]])^2,{i,N}] However this takes a very ...
53 views

### Invoking functions in other kernels

Suppose one wants to parallelize as much as possible N tasks, each task produces a graphics via ParametricPlot or something like that. If the system is allowed to ...
172 views

### What kind of patterns in a list of rules would benefit from being Dispatched?

I have a long list of rules for manipulating expressions. They are of the form: ...
102 views

### How does InternalPolynomialFunctionQ work?

I found that InternalPolynomialFunctionQ performs much better than PolynomialQ. Here is a huge random polynomial in 12 ...
40 views

### Speedup ListCorrelation when using generalized correlation function

ImageCorrelation provides several general function that can be used to replace the default Dot function. For example, in the documentation of ImageCorrelation, ...
129 views

### Extracting PNG images from AVI movie

I have written the following code to extract all images from an uncompressed AVI movie and to save them as sequential PNGs. ...
118 views

### Randomly generate points on a van der Waals surface

I'm looking to randomly place an atom $\mathbf{A}$ onto a van der Waals surface formed by atoms $\mathbf{B}$, such that the distance between the randomly-generated atom $\mathbf{A}$ and the nearest ...
197 views

### How to compile this code?

Could somebody teach me how to compile this code? ...
194 views

### Evolution of a trait in an asexual population (performance tuning)

I just coded a simple simulation module that looks at the evolution of a continuous trait in a haploid asexually reproducing population under density dependent competition in discrete time (i.e. ...
135 views

### Find random $n$ combinations of values with a given sum

This problem is described in the related StackOverflow question: Find all combinations of coins when given some dollar value. I would like generate a list of $n$ combinations of values that sum up to ...
306 views

### Which elements of a large array are part of a set?

I have a large integer packed array arr. My array is multidimensional, but for simplicity let's consider 1D arrays for now. ...
198 views

### Tracing 2d coordinates by using Nearest function

In 5 digital images I have determined the 2d coordinates of detected objects. The resulting coordinate list can be downloaded from here: http://pastebin.com/7bE0CEJ5 ...
87 views

### Faster square test for integers

This question was asked already in Jan '12 and the most recent answer is from Oct '12, so it's several Mathematica versions out of date. What is a faster test for whether an integer is a perfect ...
175 views

### Optimizing a series of basic matrix operations—scaling doesn't seem right with matrix size

I have a simple operation that I'd like to apply to an n×n matrix. My problem (well, one of them...) is that it runs in, say, 4 seconds for a 100×100 matrix, but it took five and a half minutes to run ...
81 views

### How to make this code involving Hypergeometric functions to run faster?

This question is followed up from this Question. I would like to thank Dr. Hintze and I_Mariusz for the comments and help. I am pretty new to mathematica ( I just learned it 4 days ago) so I would ...
110 views

### Generate a 3D grid data table

I would like to generate a 3D Grid, not for displaying, but to do computations on it, so no draw functions I guess. I have a simple version of what I am thinking, however, it is terribly slow: ...
53 views

### Timing and memory use is critical:fast partitioning of binary sparse array

I do experiments were I measure a signal, and I need to know at what time points it is above a threshold. If at a given time point, the signal is above the threshold, then a '1' gets put into the ...
160 views

### Numerically evaluating an integral related to Cantor's staircase

Cantor's staircase $F_C(x)$ is a well-known "pathological" function: Plot[CantorStaircase[x], {x, 0, 1}] The MathWorld link given above claims that \int_0^1 ...
140 views

### How to remove duplicate elements from two separated lists efficiently?

I have two lists of elements: indices = {Prime /@ Range[5000], Prime /@ Range[100, 300]} // Flatten; values = RandomReal[100, 3] & /@ Range[Length[indices]]; ...
99 views

148 views

### default RGB coloring

I am playing with some basic genetic algorithms to recreate input images by transparent plane figures (similar like here:). Everything would work great but the speed is terrible. I was looking for a ...
146 views

### strange timing result of LinearAlgebraBLAS` in mathematica? [closed]

BLAS is short for "Basic Linear Algebra Subprograms". It is a famous collection of routines for doing linear algebra. I just know from Oleksandr R. that mma can directly call BLAS under the context ...
209 views

### My introduction to Compile

I am reading Fractals from the Newton-Raphson method from Peter Young's page [http://young.physics.ucsc.edu/115/]{http://young.physics.ucsc.edu/115/}. I've tried: ...
45 views

### Multivariate remainder of polynomial in respect to a set of polynomials

I would like to have a really fast routine that computes the so called Normal Form of a multivariate polynomial f in respect to a set of other multivariate ...