# Tag Info

10

First of all, it helps a great deal to define f as follows: ClearAll[f] A = Exp[M]; f[x_, y_] := (weight*Exp[-pts*x]).A.(weight*Exp[-pts*y]); Here, using SetDelayed (:=) is better than Set (=), because the latter creates a humongous symbolic expression that is very expensive to numericise. Defining A first ensures that Exp[M] is computed only once. First@...

9

Perhaps this?: Table[1/2 Gamma[(1 + n)/2], {n, 0, Length@# - 1}] . # &@ CoefficientList[poly1*poly2, x] Low-order check: poly1 = LaguerreL[4, x]; poly2 = LaguerreL[5, x]; Table[1/2 Gamma[(1 + n)/2], {n, 0, Length@# - 1}] . # &@ CoefficientList[poly1*poly2, x] (* -(7981/240) + (38645 Sqrt[π])/2048 *) Integrate[Exp[-x^2] poly1*poly2, {x, 0, ...

5

It all depends on "p and q are of roughly equal size". If they differ no more than say 10^6, the following works rather fast. E.g.: fac[big_] := Module[{ne = NextPrime[Sqrt[big] - 1]}, While[Mod[big, ne] > 0, ne = NextPrime[ne]]; {ne,big/ne} ] n = 80; fac[NextPrime[10^n] NextPrime[10^n + 10^6] ] (* {...

4

Interesting problem. The best I have been able to come up so far is this: diffdata = Unitize[Subtract[braVecs, ketVecs]]; diffcounts = Total[diffdata]; F = q \[Function] RandomPrivatePositionsOf[ Plus[ diffcounts, SparseArray[Partition[q, 1] -> -1, ndim, 0].diffdata ], 0 ]; For ndim = 50, the timings on my machine are as ...

3

I am using the IGraph/M package for this answer. Approach 1: Generate Prüfer sequences, convert to trees, filter duplicates based on canonical labelling. In[17]:= Needs["IGraphM"] In[18]:= n = 7; In[19]:= DeleteDuplicatesBy[ IGFromPrufer /@ Tuples[Range[n], n - 2], CanonicalGraph ] // Length // AbsoluteTiming Out[19]= {2.0961, 11} ...

3

Why not just use Solve straight? f[tot_Integer] := Solve[a1 + a2 + a3 + a4 + b1 + b2 + b3 + b4 + c1 + c2 + c3 + c4 == tot && -4 < a1 <= a2 <= a3 <= a4 < 4 && -7 < b1 <= b2 <= b3 <= b4 < 7 && -4 < c1 <= c2 <= c3 <= c4 < 4, {a1, a2, a3, a4, b1, b2, b3, b4, ...

2

Translating some of @gnasher729's suggestions to Mathematica gives indeed a superfast recipe: \$MaxExtraPrecision = 10^3; f[x_Integer] := Module[{y, i, z, s}, y = Floor[Sqrt[x]]; Catch[ i = 0; While[True, z = (2 y + i)^2 - 4 x; If[z >= 0 && IntegerQ[Sqrt[z]], s = i/2 + y + {1, -1} Sqrt[z]/2; If[IntegerQ[s[[1]]...

2

If x is around 10^150, let y = floor(sqrt(x)), and if y^2≠x then solve (y+k+1)(y-k)=x, (y+k+2)(y-k) = x, (y + k + 3)(y - k) = x etc. until you find a k that is an integer. This will cover a huge range, much larger than 10^6. We know 0 <= d = x - y^2 <= 2y ≈ 2 x 10^75. Take for example (y+k+2)(y-k) = y^2 + yk + 2y - ky - k^2 - 2k. We solve 2y - k^2 - 2k ...

2

We can use VertexComponent and FindPath to find all paths from a starting node as follows: ClearAll[f] f[g_, v_, l_] := Join @@ (FindPath[g, v, #, {l-1}, All] & /@ VertexComponent[g, v, l-1]) Example: g = GridGraph[{10, 10}, VertexStyle -> White, VertexLabels -> Placed["Name", Center], VertexSize -> Large]; Multicolumn[f[g, 36, ...

2

To simplify calculations, we introduce an x/y coordinate system x=1..10/y=1..10. The root: 36 reads then: {4,6}. To change from x/y to linear coordinates, we define: Clear[testwalked, step, tolin]; tolin[pos_] := (pos[[2]] + 10 (pos[[1]] - 1)); We further need a routine that checks if a move is acceptable: testwalked[walked_List, dir_] := Module[{pos = Last@...

2

We can use the function SystemDateListPlotDumpDateTicks to generate date ticks. Its argument pattern is: SystemDateListPlotDumpDateTicks[{mindate, maxdate}, ndivisons] (* or *) SystemDateListPlotDump`DateTicks[{mindate, maxdate}, ndivisons, labelformat] Example: data1 = TimeSeries[{1, 1, 2, 3, 5, 8, 11}, {"Jan 1, 2015"}]; data2 = TimeSeries[{...

2

I realized that building a partial prefix trie could actually have significant benefits if done right. There are twos key realizations: by the time you've computed the set of indices that agree over 4 of the dimensions, the number of remaining indices to compare drops by ~1/16th since Complement[Range[ndim], q] is sorted, every prefix string will start with ...

1

I should indicate from the outset that this is not an answer to the question but an option to the OP for exploring different versions of his/her question. I should further indicate that the main function in the following code belongs to @kglr, who has developed it a few years ago. I could not find the link to share with you. Therefore, I give a small example....

Only top voted, non community-wiki answers of a minimum length are eligible