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.
1
vote
2answers
129 views
Combining lists with common elements efficiently [duplicate]
Possible Duplicate:
Computing the equivalence classes of the symmetric transitive closure of a relation
I am required to process sets consisting of 2-element subsets of integers by ...
15
votes
0answers
353 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 ...
4
votes
2answers
314 views
Trying to extract information from an MDB file. Import is too slow
I am running a Linux box and as usual the documentation for this type of box is not great.
I am trying to open up and extract and possibly include later on information from a "mdb" file. The file ...
8
votes
0answers
178 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 ...
15
votes
2answers
493 views
Efficient way of finding shortest distance between two sets of points in mathematica
I have two sets of 3D points, say
a = RandomReal[1, {10, 3}];
b = RandomReal[1, {10, 3}];
I wanna find the first N pairs that have shortest distance between the ...
32
votes
2answers
9k views
How can I use Mathematica's graph functions to cheat at Boggle?
This question is inspired by a Stack Overflow question that I decided to solve using Mathematica. In addition to Mathematica, I thought I'd use some of the new version's graph-related functionality, ...
15
votes
4answers
271 views
Function that caches when it returns unevaluated
How would you go about implementing a function that caches not the result but the fact that it didn't match a pattern? So that it doesn't waste time recomputing a complex time-consuming pattern ...
7
votes
1answer
293 views
8
votes
1answer
375 views
GeoDirection and GeoDistance Memory Leaks: How to Recover the Memory?
The functions GeoDirection and GeoDistance have memory leaks. To see this, run the example functions below and watch as the Physical Memory Available in the Windows Task Manager, Performance tab, ...
7
votes
1answer
251 views
Very fast way to do a coordinate frame transform
I need a function that rotates and translates a huge amount of line segments.
For example, I have a set of line segments in the form {{x0,y0,z0},{x1,y1,z1}}
...
6
votes
0answers
217 views
Optimizing NIntegrate for higher PrecisionGoal
By default, NIntegrate works with MachinePrecision and its PrecisionGoal is set to ...
33
votes
2answers
852 views
Performance tuning for game solving (peg solitaire | senku)
There's a game I saw at a friend's yesterday, that I often see at people's homes, but never for enough time to think on it too hard. It's called peg solitaire (thanks @R.M).
So I came home and I ...
16
votes
3answers
845 views
Data fitting with Image processing feature detection
I have some 2D data that once plotted looks like the following
...
3
votes
1answer
474 views
Methods to speed up numerical NDSolve, NIntegrate,
I am not very used to do numerical simulations on Mathematica. Do you have any ideas how to improve i.e. speed up my code?
...
8
votes
1answer
417 views
Rapidly binning 3D data
I have a set of data (about 20 million datapoints for my real data) of the form {x, y, z, m}. There are 3 spatial coordinates x, ...
2
votes
1answer
340 views
Speeding up a slow indefinite integral
I have found an alternative way to express an old solution:
...
17
votes
1answer
343 views
How can I effectively performance-profile Dynamics?
How to optimize performance-wise a complex dynamic expression (like a GUI) with lots of dynamically updated components, which require different update-frequencies?
I was hesitant to ask this question ...
7
votes
3answers
397 views
PolarPlot render oddities
I apologize if this is a obvious question and answer, I don't often use Mathematica to display plots or graphics in general to be honest. So, I was tutoring my cousin yesterday in relation to Polar ...
10
votes
5answers
893 views
Best way to create symmetric matrices
From time to time I need to generate symmetric matrices with relatively expensive cost of element evaluation. Most frequently these are Gram matrices where elements are $L_2$ dot products. Here are ...
20
votes
2answers
584 views
Can a Trie be implemented efficiently?
What is the most space and time efficient way to implement a Trie in Mathematica?
Will it be practically faster than what is natively available in appropriate cases?
33
votes
1answer
561 views
Profiling from Mathematica
I've always wished I could do some profiling like you get in Wolfram Workbench, but directly from Mathematica, without using or having Workbench.
How can I do it? How? It would be really nice!! ...
8
votes
3answers
236 views
Faster Alternatives to DateDifference
I need a faster implementation of FractionOfYear and FractionOfMonth, which do the following:
Input: A time/date specified by ...
9
votes
1answer
391 views
How to tell mathematica not to resolve stiffness issues
Very often I solve partial differential equations that are nonlinear and could be up to 4th order. In these cases, it is usual for the solution determined by ...
20
votes
2answers
272 views
Are there guidelines for avoiding the unpacking of a packed array?
Packed arrays are very useful because they save memory and generally allow speedier and more efficient calculation times. If a list of data currently stored as a packed array is unpacked, it can slow ...
6
votes
1answer
279 views
Tridiagonal symmetric matrix eigenvalue using bisection
I know that Eigenvalues is already quite well implemented in Mathematica, nor am I foolishly trying to improve on it. In order to improve my programming skills, I ...
11
votes
1answer
314 views
Space-efficient null space of sparse array
I have a roughly 100,000 × 3,000 matrix (as a SparseArray) that I'd like to find the kernel (null space) of.
It has about 500,000 nonzero entries, all -1 or 1.
...
1
vote
1answer
122 views
Interprocedural optimization
Lets say I want to build a list of the first 1000000 primes. This is simple enough, I can just do:
AbsoluteTiming[plist = Table[Prime[i], {i, 1000000}];] and it ...
10
votes
1answer
215 views
Memory Leak in RowReduce?
Recently I tried to do what I thought was a fairly small (relative to the 6 GB of RAM that I have on my machine) row reduction calculation on a matrix representing an undetermined linear system and ...
8
votes
4answers
213 views
Plotting the components of a function that returns a list in different colors without redundant evaluations of the function
I have a function f which takes a number as input, and returns a list of numbers (the length of the list is constant). f is hard ...
21
votes
1answer
2k views
Finding long strings of identical digits in transcendental numbers
Introduction
Describing the three main streams of present-day mathematical philosophy (formalism, Platonism and intuitionism) in a well-known book, The Emperor's New Mind, R. Penrose says:
...it ...
49
votes
8answers
11k views
How to make an inkblot?
How to effectively create a polygon that looks like a realistic inkblot? So far, I could come up with this (borrowing from Ed Pegg Jr.'s Rorschach demonstration):
...
11
votes
1answer
330 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 ...
8
votes
1answer
151 views
Reducing the memory footprint of lists of machine numbers
I have a large 1D dataset of double precision numbers that are stored in many external database files. In order to load the whole dataset into Mathematica 8 I iterate over the files ...
4
votes
1answer
100 views
How to speed up mouse events?
Grids of dynamic objects responding to mouseovers seem to be quite slow in general, for instance:
...
4
votes
1answer
191 views
Noticeable slowdown in graphical performance when using manipulate
I have been making these mathematica 3D objects that involve a molecule with some sort of surface displayed above them. This is done fairly easily by:
...
7
votes
2answers
392 views
Working with large data, pass-by-reference, compiled functions
I think I know the answer to this, but after two days of Googling, this is my last effort before going down an unwanted path...
I have a function that takes lots of large data as arguments as well as ...
11
votes
2answers
119 views
How do you determine the optimal autocompilation length on your system
When you pack lists there is an overhead therefore packing a list with, say, 2 elements is likely to cost more than you get back in efficiency. Mathematica has default list lengths for which functions ...
29
votes
2answers
862 views
What is a Mathematica packed array?
A simple sounding question with a few sub questions:
What is the difference between unpacked vs packed array?
Are packed arrays more space efficent, how much so?
Are packed arrays more time ...
21
votes
1answer
340 views
How are MemberQ and FreeQ so fast?
I would like to understand the implementation that allows MemberQ and FreeQ to be as fast as they are.
I noticed this thanks to ...
5
votes
1answer
186 views
Can we know the background code associated with basic mathematica functions
I wanted to know how computers calculate basic functions like Sqrt so first I checked how humans do it I found that they use something called "Newton's method" that ...
9
votes
3answers
366 views
Improve speed for calculating a recursive sequence
I want to calculate following recursive sequence:
$\alpha_{0}=0,\\
\cos(\alpha_{i})=\cos(\alpha_{i-1})\cdot\cos(\beta_{i})+\sin(\alpha_{i-1})\cdot\sin(\beta_{i})\cdot\cos(\gamma_{i}).$
In ...
13
votes
4answers
484 views
How to collect result continuously (interruptible calculation) when running parallel calculations?
This is the most common pattern to compute a table of results:
Table[function[p], {p, parameters}]
(regardless of how it's implemented, it could be a ...
6
votes
2answers
141 views
Control which variables get embedded inside Manipulate
While trying to analyse several different datasets I got what I thought was a good idea: define a "function" that returns a Manipulate object. But this has some ...
8
votes
1answer
231 views
Speed up DensityHistogram rendering (display)
When I tried to present some pre-calculated density histograms inside Manipulate I noticed that the display of DensityHistogram is extremely slow. Here is a simple ...
11
votes
2answers
560 views
Speeding up random walk for many particles
I am trying to speed up this code for many particles to take a random walk. I'm not sure why it is so slow for such a simple task.
I got a few hints from colleagues to reduce the precision of the ...
6
votes
2answers
419 views
Speeding up mathematica by subsitituting numerical values
According to this Wolfram Blog post, one can speed up Mathematica code by substituting numerical values as soon as possible.
How does one substitute before the main expression is evaluated? The ...
7
votes
1answer
164 views
Why do images in a PopupMenu sometimes make a program load sluggishly?
In a demonstration, I would like to display a PopupMenu with a list of small PDF images, each weighing in at approximately 50k. The code of interest is below:
...
16
votes
6answers
524 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 ...
40
votes
6answers
4k views
7
votes
2answers
156 views
Speed up Fourier for Booleans
I'm calculating a bit of the power spectrum of a two color cellular automaton using:
...


