Tag Info

Hot answers tagged

11

You can just step through $i$ and $j$ while trying to simultaneously satisfy: $$i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$$ Just loop and if the inequality is too small on the left, increment $i$. If it's too small on the right, increment $j$. That looks like this: Clear[f, g, i, j]; f[i_] = i^2 + (i + 1)^2; g[j_] = j^2 + (j + 1)^2 + (j + 2)^2; max = 10^6; i = 1; j ...


8

Update: the lhs of $i^2+(i+1)^2=j^2+(j+1)^2+(j+2)^2$ is always odd so $j$ should be even. The fastest solution I found: max = 10^12; {(Sqrt[3 + 6 (# + 1)^2] - 1)/2, #, #^2 + (# + 1)^2 + (# + 2)^2} & @@@ (2 Position[#, 0]) &@UnitStep[Abs[# - Round[#]] - 1.*^-10] &[ Sqrt[0.75 + 1.5 #^2] - 0.5] &@ Range[3., Sqrt[max/3.], 2] // ...


7

A nice trick to force Mathematica to use a given precision is to use Block and make $MinPrecision equal to $MaxPrecision. So you can write your result1 as: Block[{$MinPrecision = 10, $MaxPrecision = 10}, FixedPointList[N[1/2 Sqrt[10 - #^3] &, 10], 1.5`10]] {1.500000000, 1.286953768, 1.402540804, 1.345458374, 1.375170253, 1.360094193, ...


7

Clear[fa, ga]; fa = Total[{#, # + 1}^2] &; ga = Total[{#, # + 1, # + 2}^2] &; Update: A closed form function soln = Assuming[{C[1] ∈ Integers && C[1] >= 0 && x > 0 && y > 0}, Simplify@ Reduce[Total[{x, x + 1}^2] == Total[{y, y + 1, y + 2}^2], {x, y}, Integers]] /. C[1] -> n; ...


6

Mathematica is using an exhaustive search for your first example, testing each value of n from 2 to 2^10. By default it won't use this method if the number of test cases exceeds 10000. So in your second example it cannot resolve the Exists expression and returns it unchanged. You can increase the maximum number of points for the exhaustive search using ...


5

The best analytic built-in approximation is the Riemann Prime Counting Function; it is implemented in Mathematica as RiemannR. So far we know exact values of $\pi$ prime counting function for n < 10^25, however in Mathematica its counterpart PrimePi[n] can be computed exactly to much lower values i.e. up to 25 10^13 -1, see e.g. What is so special about ...


4

RiemannR seems to be a better choice than LogIntegral based on this plot: Plot[{PrimePi[n], LogIntegral[n], RiemannR[n]}, {n, 1, 5000}, PlotStyle -> {Black, Blue, Red}] RiemannR[1.*10^1000] 4.344832576401197453*10^996


3

This is not particularly fast but works: f = (-1 + Sqrt[3 + 6 #^2])/2 &; q = IntegerQ /@ (f /@ Range[1000000]); answer = Pick[Range[1000000], q] yields the triples : {1, 11, 109, 1079, 10681, 105731} fanswer = f /@ answer {1, 13, 133, 1321, 13081, 129493} Dropping first case which is 0^2+1^2+2^2=1^2+2^2: trip = Rest[{(# - 1), #, # + 1} & /@ ...


2

Mathematical operations on numbers of a given precision cannot guarantee the output to maintain the precision of the input numbers. In general precision will decrease. The amount of decrease depends on the operations and some operations will cause precision to decrease significantly. If you want a specific precision on the final result then the working ...


1

Factoring algorithms work by finding a prime factor, then dividing by it, then continuing on the result, and so the prime factors are found in essentially random order, unless your algorithm is trial division (which I hope to God mathematica does not use). So, the answer to your question is: filtering is your only solution. EDIT On the other hand, the OP's ...


1

I have tried using FindInstance for take-time saving. ClearAll[g] g[v_, n_, p_] := With[{k = FindInstance[Sum[i^p, {i, a, a + n - 1}] == v && a > 0, a, Integers, 2]}, If[k =!= {}, Range[a, a + n - 1] /. k]] g[365, 3, 2] {{10, 11, 12}} g[33537133085, 3, 2] {{105730, 105731, 105732}}



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