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.

learn more… | top users | synonyms (2)

26
votes
0answers
355 views

Why is StringExpression faster than RegularExpression?

Edit: as noted by Albert Retey the performance difference is only seen when sub expression extraction is performed. If this test is used below the timings are similar: ...
15
votes
0answers
528 views

Fast Spherical Harmonics radiative transfer

This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me. I am using ...
13
votes
0answers
248 views

What Mathematica features and idioms have n^2 complexity or worse

Here are a few: AppendTo[data, elem], Sort[data, test], in some cases use of ___ (as ...
11
votes
0answers
583 views

Mathematica performance on Mac

I recently got a trial version of both Mathematica 9 and MATLAB 13a for Windows. I was stunned by the performance difference in the Windows and the Mac version. It was a simple test in matrix ...
7
votes
0answers
155 views

Improving the performance of a package for working with rational functions

As Mathematica gets slow for large symbolic calculations, the cost of putting terms over a common denominator (Together), in particular, gets too high. It occurred ...
7
votes
0answers
223 views

Using Compile to speed up Function with PermutationProduct

I have the following fairly simple routine dot involving PermutationProduct that I wish to speed up using ...
6
votes
0answers
123 views

Poor CUDALink performance, when calling a kernel multiple times

When working on a project of mine I noticed that CUDALink shows very poor performance when calling CUDA kernels multiple times in a loop-construct. To demonstrate this I put together this little ...
6
votes
0answers
67 views

Slow NIntegrate over complicated domains (sometimes)

Overview I have a very large matrix I need to calculate where each element requires the integration of a product of two functions over some complicated domain. I would like to find a set of options ...
6
votes
0answers
92 views

Compiled function crashes kernel when trying to list over different length arguments

I'm trying to speed up a tally/binning operation that I have to run many times. I have many lists of between 1 and 10 numbers from the range [1,5] and I want to ...
6
votes
0answers
213 views

Faster simplification of linear combinations of some specific functions

After some profiling I've found that my program spends most of its time in the simplification step. The program uses my simplification function many times (over different data). My calculation is not ...
6
votes
0answers
365 views

Optimizing NIntegrate for higher PrecisionGoal

By default, NIntegrate works with MachinePrecision and its PrecisionGoal is set to ...
5
votes
0answers
81 views

Is there something like MaxProcessorUsed?

For standard procedures it is easy to test if the implementation is better or worse than other by using Timing etc. It does not help us with creating ...
5
votes
0answers
68 views

Does one need to be careful about loading multiple (many) contexts or packages in the same session?

I have a number of large pieces of precomputed data which I am considering putting into individual packages in order to load them (via DeclarePackage) and unload ...
5
votes
0answers
79 views

Faster way to perform SameQ[Reduce[…], Reduce[…]]

I'm have some expressions that I need to confirm the equality of. SameQ[Reduce[...], Reduce[...]] works like a charm for the more simple expressions, however when ...
5
votes
0answers
180 views

Parallelizing is much slower than single kernel evaluation?

Starting with a vector of matrices, tVec, I would like to parallelize the multiplication of each element with the same matrix ...
5
votes
0answers
181 views

Speeding up multilinear PRA branch-and-bound algorithm with worst-case exponential time scenario with respect to basic events

The algorithm is a branch-and-bound algorithm that calculates dominances for PRA, probalistic risk assessment. The task was to find faster ways to do it in numerical software such as Matlab but we ...
4
votes
0answers
100 views

Efficient Generation of Subgraphs (or, unfriend a friend a day)

NB: If you're not interested in the back-story, you could simply jump forward to the code which I'm seeking to optimize. Also, I believe this code would only work for MMA 8.0 and above. My friends ...
3
votes
0answers
90 views

What can I do to improve the performance of my calculations?

I'm trying to express a simple probability problem in Mathematica, but am having trouble getting my calculations to execute at a reasonable speed. I have an object whose unknown location is modeled ...
3
votes
0answers
97 views

“Off-label use” of Mathematica functions for performance

Assisting an acquaintance with a simulation where a very large number of binomial probability calculations are required, I pointed them to a slightly obscure function to dramatically speed up their ...
3
votes
0answers
602 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 ...
2
votes
0answers
46 views

Why does setting $Assumptions make my Fourier transforms slow?

Consider these Fourier transforms ...
2
votes
0answers
45 views

LibraryLink parallel performance

I'm trying to use a LibraryLink function in parallel. It is an embarrassingly parallel problem, so that no dependency between those parallel tasks. However I can only get the parallel efficiency about ...
2
votes
0answers
156 views

Taking real and imaginary parts of indexed functions and speeding up ComplexExpand

I am setting up a large system of ODEs and in order to use the IDA method (which is sig. faster for my system and thus attractive), I must split my equations into real and imaginary parts. I am ...
2
votes
0answers
84 views

Speed improvement in string distance function

I'm using this distance function to compare distance between strings: ...
2
votes
0answers
96 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? ...
2
votes
0answers
69 views

Is there a way to output the number of operations done?

Analogous to //Timing, I would like to be able to see how many operations my program goes through before producing an output. Does anybody know of a way to do this? ...
2
votes
0answers
182 views

why version 9 is much slower than version 8 in producing these graphics

Consider this example(taken from Thomas's question here) ...
2
votes
0answers
121 views

Speeding up a numerical constrained quadratic optimization

I'm trying to solve a quadratic optimization problem in 35 variables, $\vec{α} = \left< α_1, \ldots, α_{35}\right>$: $$ \begin{aligned} &\operatorname*{maximize}_\vec{α}&&1.0\cdot ...
2
votes
0answers
92 views

Significant platform-dependent efficiency when importing data?

I'm curious, as I understand that answer this way: If you are using a Linux derivative or something like cygwin on Windows, then this is an efficient solution for reading only the third field ...
2
votes
0answers
118 views

Is there documentation on the comparative performance of Mathematica functions?

Recently I have been solving some Project Euler problems. I find there are always several ways to do the same thing. For example, one could join two lists like this: ...
2
votes
0answers
226 views

FindRoot - Speed and errors

I am using FindRoot[] to solve a complicated equation. It seems I get the correct answer even though I get errors about an ...
1
vote
0answers
35 views

Linear interpolation over 2 variables

I'm tuning a function to data over 4-5 variables using Differential Evolution. The objective function calls frequently interpolation function. I came to a point, where compiling the objective function ...
1
vote
0answers
44 views

Speed up MinimalPolynomial

My Mathematica code runs slowly MinimalPolynomial[Sqrt[2] + Sqrt[3]+ Sqrt[5]+ Sqrt[7]+ Sqrt[11]+ Sqrt[13], x] runs slowly, but the Maple version ...
1
vote
0answers
92 views

Solve[] unexpectedly giving empty solution sets for extremely large problems

I was calculating the set of lattice vectors in $\mathbb{Z}^4$ which have taxicab norm $r$. For example, executing ...
1
vote
0answers
94 views

Sum slowing down computations

I am trying to compute higher order Casimir invariants for some representations of certain groups. I can get the quadratic, cubic and quartic but beyond that things are taking too long to the point I ...
1
vote
0answers
118 views

Optimization of power tower fractal generator

I tried to optimize the code for generating power tower fractals from here. As the author suggested, I tried to memorize the points already tested in a list. Here is my code : ...
1
vote
0answers
69 views

Is the TCPIP link type compressed?

Since I'm already piping a MathLink connection in a ssh tunnel (connect back is a pain!), I wonder if it makes sense to compress the data in the stream (ssh -C). As ...
1
vote
0answers
369 views

How can I speed up numerical integration of multidimensional integral?

I am numerically solving an integral equation that contains a double integral. I have managed to get a solution but it takes forever. I am wondering if there is a way to speed up numerical integration ...
1
vote
0answers
197 views

Vector computation instead of iterating over a list

I am 'Map'ping over a list. I would like to do the computation in one single iteration. Is it possible? Can 'Apply' be used here? In what way is it different from 'Map' especially in this case? ...
0
votes
0answers
62 views

Optimization of vector manipulation

I'm trying to implement an upwind scheme for solving transport equation (at first, I work with no right hand side and the simpliest case possible - velocity is constant, initial data is smooth, etc). ...
0
votes
0answers
41 views

Approximate to the speed of Build-In functions

In Mathematica, there is a function PowerMod[a,b,m], which computes a^b mod m. I will concern only this case: ...
0
votes
0answers
28 views

trying to speed up sequential use of NDSolve for large system of ODEs

I don't have a basic example just yet but I'll describe the problem for now. I have a large system (>100) of coupled first order ODEs. Where the output from one solution becomes the ICs for the next ...
0
votes
0answers
143 views

Code performance problem

Could anyone help me with the attached code? How would you speed up my attached code in some degree? Your comments are highly welcome. ...
0
votes
0answers
89 views

Need Help with Output/Code Optimization Conparative Statics with System of Equations and Matrices

I have a system of equations (equilibrium conditions) and would like to evaluate how changes of exogenous variables affect the endogenous values. In step 1, I state the equilibrium equations and some ...
0
votes
0answers
54 views

Can you set up a remote kernel for computation and a local kernel for predictive interface?

I am able to launch remote kernels from my Windows box to our Linux cluster that has the data I need and the capacity to run analysis (numerous & speedy cores, spacious memory, etc.). Works ...
0
votes
0answers
42 views

Calculate Shapely Shubic power index for larger datasets (enhance performance of code)

I want to calculate the Shapely Shubik Power Index for larger datasets. The code I have (from wolfram demonstration project) runs forever on my mac with a dataset of 15 elements, eventually my ...
0
votes
0answers
120 views

My algorithm produces too many permutations

Imagine the following problem. A population of size $n$ consists of $i$ men and $n-i$ women. The population goes to the casino. Call $g_m$ ,$g_w$ the amount of money won by men and women respectively. ...
0
votes
0answers
88 views

Inconsistent results in fits from NArgMin

EDIT: Just realized I had misspelled "inconsistent." I'm using version 7.0. I'm trying to fit a (noisy) data set to a large-order polynomial. (Just for context: there isn't a model for the ...