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)

4
votes
2answers
76 views

How to speed up Min of DateObjects?

I'm in version 10.0.1 using a Dataset to do some plots and things. For one of the plots I need to get the minimum date of a some filtered set of the ...
0
votes
1answer
69 views

How to speed up execution of this function?

How can I speed up the execution of following function, specifically for larger values of n? ...
4
votes
2answers
217 views

Speed up calculation

First of all thanks to: rm -rf, Mr.Wizard, Simon Woods, Pickett, Piotr Wendykier, Mac, Yves Klett, belisarius, halirutan, bill s, nikie, wxffles, ... Everybody of you helped me (a mathematica ...
2
votes
1answer
103 views

How to use slots and patterns to reduce repetitive calculation?

This is kind of complicated... How can we make MMa calculate values of a function before doing multiple pattern or slot substitutions? Answers to similar questions didn't cover the case where the ...
0
votes
1answer
68 views

Extend a function to all polynomials ( just 2 variables) when one knows its values on monomials

I need your help to make my code faster. I have a formula for computing a value from any monomial $x^i y^j$, say formular1[i_,j_]:=(Gamma[i]/Gamm[j] ). It is just ...
14
votes
2answers
227 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 ...
0
votes
0answers
32 views

Order of evaluation when using Solve and Minimize

I have to solve numerically an integral, that ends up being more or less as follows: Solve[f[x]==a*Sum[Sin[x-i]*(f[i]-f[i-1]),{i,1,x}],f[x]] (not actual ...
1
vote
1answer
77 views

Use Compile to speed up evaluation

I have read, that using Compile command can speed up evaluations in mathematica. I have a mathematical expression, which I evaluate using following command: ...
22
votes
1answer
706 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 ...
1
vote
0answers
92 views

Best way to create symmetric matrices with block structure and additional symmetries of the submatrices

Update: you can now skip the "My attempted solution" part and jump to "My first attempt for improvement" in the end of the question. My question is related to Best way to create symmetric matrices . ...
5
votes
1answer
138 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
1answer
51 views

Performance of Extract-Transform operations

I'm doing simple data analysis. I load some date-time data from a file, it's a simple list: ...
28
votes
2answers
903 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?
6
votes
1answer
248 views

Speeding up the non-negativity algorithm for multilinear function with interval probabilities?

The algorithm is a branch-and-bound algorithm that calculates the non-negativity of a multilinear function with interval probabilities. The lines 9-11 has an optimization that is explained on the ...
31
votes
1answer
525 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: ...
7
votes
4answers
493 views

Suppress connection to Wolfram|Alpha when making unit conversions

I want to speed up calculations with unit conversions. I suspect primarily that some units evaluate from Wolfram|Alpha. Any way to prevent this automatically, so that Mathematica throws ...
3
votes
1answer
82 views

Mathematica taking too long to calculate recursive function

I have been trying to plot those specific recursively defined functions p1 and q1 in Mathematica: ...
4
votes
2answers
268 views

Comparing LetL and Module efficiency

I was recently introduced to the LetL macro thanks to Leonid's answer to one of my prior questions. I was, needless to say, impressed by the simplicity of its ...
1
vote
1answer
76 views

Apply functions to functions yields slow execution speed

I'm trying to write a function that parametrizes a curve c(t) by its arc length. Technicly I'm finished but if I plot the result for an example curve like ...
47
votes
2answers
9k views

How can I use Mathematica's graph functions to cheat at Boggle?

Boggle is a word game played with 16 dice and a 4x4 tray. This question is inspired by a Stack Overflow question about Boggle that I decided to solve using Mathematica. In addition to Mathematica, I ...
7
votes
1answer
62 views

Issuing user-defined messages takes a long time (Message is slow)

Issuing messages takes a very long time in version 9 and version 10. Can others reproduce this? Is there a fix? Update: This is slow only when using the front end, but not when running the kernel ...
4
votes
1answer
82 views

Slowdown of Flat attributed function

I was trying to write an associative function f using the attribute Flat. ...
10
votes
3answers
561 views

What is the most efficient way to map a linked list?

In order to work with lists effectively using common recursive patterns from functional programming, it's often most convenient to worked with the "linked list" representation, that looks like this: ...
12
votes
5answers
3k views

Division by zero is slow

Suppose I have two arrays of data, which I want to divide: ...
0
votes
0answers
41 views
9
votes
1answer
888 views

Hardware Performance Metrics for Mathematica

Dear Mathematica users I am looking into buying a new computer and Mathematica is one of the main applications I run. To help me assess the overwhelming welter of choice out there: I'd like to know ...
6
votes
3answers
175 views

How to get “Signature” of each element of “Permutation” output

I need to sum over all possible permutations, multiplied by the Signature of each permutation of a given list of symbols. But, I don't know how to determine the ...
2
votes
2answers
143 views

Speeding up the generation of all k-edge-coloring of a graph

A $k$-edge-coloring of a graph $G=(V,E)$ is a function from $E$ to $\{1,\ldots,k\}$, so in other words every edge of $G$ receives one of the $k$ colors available. (In particular, note that we are not ...
4
votes
5answers
249 views

Can I generate a “piecewise” list from a list in a fast and elegant way?

Suppose we have a number list a: n = 1000000; a = RandomReal[{0, 1}, {n}]; We want to generate a list ...
2
votes
3answers
117 views

Can you compute more terms in this sequence?

I am trying to identify a sequence related to the von Mangoldt function matrix. Since I believe/conjecture that the columns in the matrix have period lengths as in this sequence b: ...
5
votes
2answers
96 views

Paralleizing the Plot function internally

I have a function of several parameters, funct(a,b,c,d,f,...). Mathematica deals with this function fine but it takes a minute or so to make a data point. I want to plot graphs of funct using code ...
11
votes
4answers
856 views

Integers which are the sum of both two and three consecutive squares

This is a math problem I came across the other day: I would like to know what would be a good way (esp. performance-wise) to check all first, lets say, 1000000, natural numbers if they can be ...
14
votes
1answer
524 views

Has this implementation of FDM touched the speed limit of Mathematica?

Still, I'll use the implementation of the 1D FDTD method (you can simply understand it as a kind of explicit finite difference scheme for the Maxwell's equation) as the example. Just for completeness, ...
13
votes
2answers
334 views

Bad performance of LengthWhile?

A friend of mine showed me this example, it's a test comparing LengthWhile to a self-made lengthwhile written in a direct and ...
5
votes
1answer
225 views

A more perfect Union[]

I was doing a Project Euler problem with my class, and found the following weird fact: Union[] of a list of some 50 million numbers (of which only around 15000 were ...
6
votes
2answers
134 views

Bad performance from SubsetQ?

Can I say this is a bad performance from the new V10 function SubsetQ? Here are some tests comparing it to ...
2
votes
2answers
286 views
0
votes
1answer
132 views

My Baum-Welch algorithm is very slow. Is it due to Mathematica?

I've also posted this question here, since I'm not sure which community is more adequate for this type of question. I've programmed imperatively the Baum-Welch algorithm for a 2 state hidden Markov ...
20
votes
4answers
4k views

Finding Local Minima / Maxima in Noisy Data

I'm trying to find local minima / maxima in noisy data, consisting of data values taken at certain time intervals. Ideally, the function should take a pair of lists (one containing time values and one ...
5
votes
1answer
70 views

Speedup of KL Divergence by Monte Carlo Simulation

I started with Mathematica about just a week, so I don't know how to take all of this environment. What I want to know is if there is a way to speedup my code to compute the KL-Divergence of Gaussian ...
26
votes
1answer
296 views

Exporting extremely large images; arrays generated via TensorProduct use 5 times as much RAM as expected?

I am generating plots of the roots of certain classes of polynomials, in the spirit of the multicolored visuals on the Wiki page on algebraic numbers. I've thus far been able to make some extremely ...
9
votes
3answers
198 views

Improving selection of elements from large multidimensional array

Frequently in my profession I deal with large arrays of data. Typically these are mixed types including integers, strings, dates, and reals. To recreate a typical data array: ...
5
votes
1answer
108 views

Optimizing code containing an infinite sum

I have the following expression. It's based on the negative-log-likelihood of a Poisson-Gaussian noise model, i.e. a convolution of a Poisson & Normal distribution. The value $x_{i}$ is the ...
4
votes
3answers
379 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 ...
4
votes
1answer
153 views

Calculate the covariance of a large matrix

I have to compute the covariance of 50 very large integer matrices (2500x2000 elements). However, according to my estimation this will take around 10 days. Do you have any ideas how to speed things ...
9
votes
2answers
142 views