# 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.

1k views

### Integration strategies for oscillatory multidimensional function

I am seeking to integrate a highly oscillatory, multidimensional function. I am currently using NIntegrate's QuasiMonteCarlo approach. However, this is time-consuming and, given my current resources, ...
495 views

### Why does iterating Prime in reverse order require much more time?

Say I would like to display the $10$ greatest primes that are less than $10^5$. I could do the following: ...
334 views

### How can I speed up my compiled RBF interpolating function?

Overview I have a function that acts like the Interpolation on sparse $n$-dimensional data using a simple implementation of RBF interpolation method. I want my ...
481 views

### Is there a faster way to create a matrix of indices from ragged data?

I have data that is given as a list of ordered pairs mixed with scalars. The pairs can contain infinite bounds. My goal is to convert the data into an index used in future computations. ...
863 views

### Split a string at specific positions

Given a string of alphanumerical characters, how to split it simply and quickly at the center of continuous letter-substrings? Is there an elegant and fast solutions out there in the "computational ...
300 views

### How to implement Bresenham’s algorithm as a system of equations?

Bresenham's line drawing algorithm is usually implemented via loops. But in Mathematica we can take advantage of its ability to solve Diophantine equations. From educational viewpoint it is quite ...
428 views

### Highlighting pattern strings in a large text

I would like to apply Style to strings that are matched, for example, with one or more specified patterns or regular expressions, a string or a list of both, ...
212 views

### Major slowdown when using a ColorFunction with more than one named scheme

Problem remains in 10.1 Earlier Kuba noted a major slowdown with code Simon Woods posted. Here is a simplified example. First a color function using two different named gradient schemes: ...
645 views

### FiniteFields package is very slow. Any fast substitute for Mathematica?

I want to compute the inverse of matrix, say with dimensions $100 \times 100$, defined over a large finite field extension such as $GF(2^{120})$. I am using the package FiniteFields, but Mathematica's ...
410 views

### What's fastest way of defining 10^5 down values?

I want to define isGood[___] = False; isGood[#] = True & /@ list where list is a list of several million integers. ...
314 views

### Creating a NearestFunction that returns an index

I use Nearest repeatedly for large data sets. For example pts = RandomReal[{-1, 1}, {1000, 3}]; Nearest[pts, {0, 0, 0}] I ...
214 views

### Export[] performance

Consider this sequence of commands: ...
490 views

### Collatz Tool Box — any speed ups possible?

I have created a tool box for experimenting with the Collatz conjecture. Info here: Wolfram MathWorld and here: Wikipedia The patterns I have found allow us to make the conjecture jump through some ...
2k views

### efficient way to count the number of zeros at the (right) end of a very large number

If I want to count the number of zeros at the (right) end of a large number, like $12345!$, I can use something like: Length[Last[Split[IntegerDigits[12345!]]]] ...
564 views

### Total much slower in version 10

Issue introduced in version 10, fixed in 10.0.2 Compilation nowadays may give very fast functions. Here is an example for finding the sum of a list of machine numbers, just as the built-in function ...
335 views

### Parallelization of distinct array write access from subkernels

I'm working on an implementation of a multivariate FFT, which is (or at least should be) highly parallelizable due to the row-column-algorithm. However, i can't figure out how to implement that. The ...
352 views

### Does NRoots own an abstract counterpart? If not, can we write one?

We know when solving linear algebra equations, despite its abstract syntax, LinearSolve is much faster compared to Solve: ...
306 views

### Implementation of a matrix formula

For the Bézier surface, which owns the following matrix definition: \begin{align*} S(u,v)&=\sum_{i=0}^m \sum_{j=0}^n P_{i,j} B_{m,i}(u) B_{n,j}(v)\\ &=\small \begin{pmatrix}B_{m,0}(u)&\...
299 views

### How to reduce the number of operations needed to evaluate an expression? [duplicate]

For some numerical calculations in C++ I have, for example, this complicated expression to evaluate. Given as Mathematica input, in its original form it is ...
188 views

### Performance: Collapsing repeated contiguous rows & cols from a matrix

In this answer I needed to remove contiguous zero-valued cols and rows from a matrix, leaving only two of them in place, no matter what the original number was. I made up this code: ...
271 views

### A bug in Commonest in version 10

Bug introduced in 10.0.0 and fixed in 10.0.2 m_goldberg demonstrated that in Mathematica 10 Commonest does not behave as the documentation indicates that it will....
394 views

### Memory leak in FE?

A very abridged example of what was originally a major leak ...
397 views

### Generalization to AllTrue, AnyTrue and NoneTrue

I am wondering if there is a natural Mathematica way to generalize those functions. To be specific, All three functions AllTrue, ...
2k views

### MathKernel.exe capped to use only 13% of CPU?

I am using a Windows machine with 8 cores. No other process than Mathematica 8 is using CPU time right now - still the MathKernel.exe CPU usage does not go beyond 13%. My current computation takes ...
452 views

### Variant of the cutting-stock problem in Mathematica

I'm pretty new to Mathematica and am trying to learn to solve problems in a functional way. The problem I was solving was to list the ways in which I could sum elements from a list (with repetitions), ...
253 views

### Complicated symbolic coefficient slows down equation solving

Here's a simple example for Solve: ...
87 views

### Deleting isomorphic graphs efficiently

I'm trying to delete isomorphic graphs from a large list. My solution is as follows: DeleteIsoG1[gl_List]:= Module[{}, DeleteDuplicates[gl,IsomorphicGraphQ]]; ...
652 views

### How to implement the directed Barabasi-Albert algorithm in Mathematica?

Does anyone know how to implement an efficient version of the [directed Barabasi-Albert algorithm][1] in Mathematica that scales until hundred of thousands nodes? The directed network mechanism is ...
184 views

### Efficiency problem with least square algorithm (Error in both variables)

I was informing myself about the least square algorithms with errors in x and y. I found this post and the top answer wasn't ...
167 views

### How I can get faster code for computing a fractional integral?

I use of this code Fractional Integral and wrote the following code: ...
961 views

### What is the fastest way to find an integer-valued row echelon form for a matrix with integer entries?

Let me begin by saying that this is my first post on StackExchange. I apologize in advance if I unwittingly break any of its unwritten rules of etiquette. Recently, I've been trying to understand an ...
2k views

### Improving NDSolve speed for heavily stiff problems

Having looked around the intergoogles and Mathematica.SE, I thought I'd pose a question with a minimum working example. Here is the situation I am trying to improve: I am solving a 4th order non ...
804 views

### Why is parallel slower?

I always assumed that distributing a computation is faster, but it isn't necessarily true. When I do Sum[i,{i,10^4}] I retrieve an answer much faster then if I do <...
110 views

### Huge overhead in RandomPoint[ImplicitRegion]

Commenting answers of this question @JasonB noticed the big overhead of RandomPoint ...
213 views

### Slow exponential evaluation over lists

This question,which is still unanswered, might be relevant because it involves NIntegrate over lists and it also has Exp. In ...
1k views

### MaxSteps and Computing time issue for Solving Differential equation in Mathematica

When we solve differential equation numerically using NDSolve then sometimes we get error like NDSolve::mxst: Maximum steps reached According to Mathematica docs ...
462 views

### Improve the performance of solutions to Project Euler (#14)

Problem I have following code, when n<=10^5 it's not slow, but n>2*10^5 it's became very slow. I think maybe some temp value greater than 2^31-1, so make compile invalid. Could you give any idea ...
242 views

### Speed up Eliminate

I have a set of trig equations, c1,c2,c3 are constants, I excepted the result is c1 c2 c3 r^2 + (c1^2 + c2^2 + c3^2 - 1) r + c1 c2 c3 == 0 but following code ...
202 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 ...
117 views

### Simplifying Expressions for FindMinimum

I am currently trying to apply the FindMinimum function to find the lowest energy of an expression. My current expression as of now is relatively complicated. It is the summation of 48 similar terms, ...
301 views

### AbsoluteTiming affected by surrounding code

In the process of simplifying code posted for another question, I noticed AbsoluteTiming returned different results for the same code being timed, ...
504 views

### Import large amount of data with time stamps

I have a large data file (150 000 lines) which I want to import in Mathematica. The first few lines look like this ...
889 views

### ParallelTable 70 times slower on 16 cores than Table on single core

Consider these code(sorry it's messy), why the ParallelTable version is 70 times slower than the Table version? ...
154 views

### Only perform a symbolic differentiation once

I want to define a function that involves a differentiation step that Mathematica can do easily, which might be of the form ...
282 views

### Slow evaluation of NIntegrate when used as a pure function

I asked a perhaps related question here. Here is my code in below. The goal is that to define a function which must be integrated numerically. The function itself first is calculated over different ...
1k views

### Is this the most effective and efficient programming style for prototyping (a ray tracer) in Mathematica?

I am trying out Mathematica as a prototyping tool. As an initial exercise I have put together a brute force ray tracer, with a view to using Mathematica's built in probability distribution functions ...
935 views

### More efficient way of generating list of occurrence counts?

Given a list, e.g., target = {a, b, c, b, c, d, c, d, e, f, a, h, g}, I want to generate a list containing the occurrence count of the corresponding element of the ...
1k views

### Using the Krylov method for Solve: Speeding up a SparseArray calculation

I'm trying to implement this Total Variation Regularized Numerical Differentiation (TVDiff) code in MMA (which I found through this SO answer): essentially I want to differentiate noisy data. The full ...
I need to get a matrix $\{a(x_i-x_j)\}$, where $x_i$ form a partition of an interval, $a(x)$ is a given function. I use ...