Tag Info

New answers tagged

0

You could always use brute force: max = 10^12; ( sq2 = Range[Floor[Sqrt[max/2]]]^2; sq2 = sq2[[2 ;;]] + sq2[[ ;; -2]]; sq3 = Range[Floor[Sqrt[max/3]]]^2; sq3 = sq3[[3 ;;]] + sq3[[2 ;; -2]] + sq3[[;; -3]]; Intersection[sq2, sq3] ) // Timing {0.046800, {365, 35645, 3492725, 342251285, 33537133085}} Not as elegant as the others, but quite ...


0

Solutions can be greatly simplified simply computing the next number. For the equation: $$n^2+(n+1)^2=k^2+(k+1)^2+(k+2)^2$$ Using the first number. $(p_1 ; s_1) - (1 ; 0 )$ Let's use these numbers. Which are the sequence. The following is found using the previous value according to the formula. $$p_2=5p_1+12s_1$$ $$s_2=2p_1+5s_1$$ Using the ...


3

Consider also 'Sort' and 'First' > (your expression here...) // Sort // First Max also suffers poor performance on DateObjects that can remedied in similar form: > (your expression here...) //Sort // Last To comment on the OP situation: at this time (MMA 10.0.2) short lists also suffer unacceptable delays. For example, applying Min or Max to a ...


2

This seems to be somewhat faster. I use N[] or equivalent thereof in some places. Also removed a Floor since the argument had to be integral anyway. Clear[f, fr] f[n_, 0, s_, a_] := 1 fr[n_, s_] := fr[n, s] = Sum[m^-s, {m, 1., n}] f[n_, 1, s_, a_] := f[n, 1, s, a] = fr[n, s] - fr[a, s] f[n_, k_, s_, a_] := f[n, k, s, a] = N[Sum[Binomial[k, j] ...


5

This seems quicker. Importing the images is the slowest bit, there's probably not much you can do about that. fNames = FileNames["*.png"]; n = Length @ fNames; bins = Table[ Clip[Import[fNames[[i]], "GrayLevels"], {0.18, 0.18}, {0, i/n}] , {i, n}]; Colorize[ Image[Map[Max, Transpose[bins, {3, 1, 2}], {2}]], ColorFunction -> "TemperatureMap"]


6

This one takes less than one third of the time in my machine. The main idea is NOT converting to ImageData[] to speed up image ops. imgs = Import /@ fNames; fun[img_, idx_] := ImageApply[UnitStep[# - .18]/number idx &, img]; imgs1 = MapIndexed[fun[#1, #2[[1]]] &, imgs]; fold = Fold[ ImageAdd[ImageSubtract[#1, ImageMultiply[#1, Binarize[#2, 0]]], ...


1

I didn't go deep to the possible repetitive calculation of f[x] and its derivative (actually I doubt if they are the bottleneck of speed, due to my… intuition), but your code got a 1.25X speed up in my computer with the Together in your integrand[t] being taken away: gauMix[means_, vars_] := Total[Apply[(1/(Sqrt[2*Pi*#2]*Length[vars]))* E^-(((x - ...


2

Update As noted by @user565739, my earlier solution does not work when i or j are unity (because the internal representation of z^1 does not involve Power). A simple generalization is as follows. f = x^3 y^4 + x^7 y^2; f /. {z1_^i_ z2_^j_ -> formular1[i, j], z1_ z2_^j_ -> formular1[1, j], z1_^i_ z2_ -> formular1[i, 1], z1_ z2_ -> ...


4

bug fixed in 10.0.2. WIndows 7, 64 bit Commonest[{1, 2, 3, 1, 2, 3}, 1] (*should return {1}*)


3

As mentioned by blochwave, your code can't benefit from compilation. To speed up your code, take Rolf Mertig's advise may be the best. Making use of the Listable attribute of those arithmetical function will also help a little: (* Tested under n = 1000, dual-core laptop *) pk1 = Table[ Sum[Binomial[a, i]*StirlingS2[i, r]*(n - c)^(-i), {i, r, a}], {r, 1, ...


0

Calculation of R involves general recursion that is not optimized in Mathematica. Try to use memoisation to avoid stack bloat when calculate R functions. R is defined recursively and recursive calls are not even in the tail position. Another advice - look at using Compile for your numeric functions.


1

l = ConstantArray[{"26.11.2014 13:56:17", "26.11.2014 13:56:18" , "26.11.2014 13:56:20"}, {10000}] // Flatten; I can get 20x speed up by converting it to DateList form: AbsoluteTime[ ToExpression@StringSplit[#, " " | "." | ":"][[{3, 2, 1, 4, 5, 6}]] ]& /@ l; // Timing {1.684811, Null}


5

Since we can not see the source code of Mathematica, we don't know the detailed algorithm Mathematica use to do string pattern searching. But in most other languages, they use KMP algorithm to do explicit string matching. KMP is in fact a very compact design of the DFA pattern matching algorithm. You can find a comparison here. You can see that the ...



Top 50 recent answers are included