# Tag Info

26

Actually, I believe the issue reduced to that of implementing PrimePi[]. It is easy to implement Prime[] using PrimePi[] and FindRoot[] — in fact this is done on page 134 of Bressoud and Wagon, "A Course in Computational Number Theory". So all you need is to have a fast implementation of PrimePi[]. The first efficient way was found by Legendre in 1808. The ...

23

The idea The idea is that if we have $\log(a+b),\qquad a\gg b$ , then we can equivalently write this as $\log a + \log(1 + b/a)$ and the second part will be small, so that one can first compare the first part(s). The power towers with base numbers larger than 1 naturally lead to such logarithms when we repeatedly take the $\log$ of them. So, there ...

23

It's due to an implementation-dependent issue. We should try to improve on it. Has not been much clamor to do so, therefore it has not been a high priority. --- edit --- I've had a look at the code. It is quite intentional that the largest is around what you state (I see the constant being set to $7.783516108362\times 10^{12}$). It has to do with this ...

22

We can take advantage of the fact that IntegerDigits is very fast when the base is large. But not too large: no bigger than $2^{63}-1$ on a 64-bit system or $2^{31}-1$ on a 32-bit one, because Mathematica's machine integers are signed. Additionally, non-power-of-two bases require more work to get the result than just partitioning a bit-string, and are ...

21

If you calculate Log[2,Log[2,$MaxNumber]], you'll get 29.999999828017338886225739 which is remarkably close to 30. Therefore I conclude that Mathematica calculates with a 31-bit exponent (1 bit for the exponent's sign). Which means that if Mathematica uses the same ordering as IEEE floats (i.e. first sign bit, then exponent, then mantissa), the first 32 ... 21 We can exploit the built in LogGamma: x = 12345678987654321; Ceiling[LogGamma[N[x + 1]]/Log] 193299018111544064 Edit, Addressing precision: We have naively for$n > 1$, that$n! < n^n$. Taking logs of both sides gives the (not very tight) bound$\log\Gamma(x + 1) < x \log(x)$for$x > 1$. This means if we want the number of digits of$n!$... 19 As it seems to depend on more than machine bits I'm curious what$MaxNumber various Mathematica installs have. If your setup is different please fill in system information and Log2 @ Log2 @ $MaxNumber // Round in the table below: $$\begin{array}{r|c|c|l|c} \text{OS} & \text{Bits} & \text{Version} & \text{\MaxNumber} & \log_2\log_2\\ \... 17 There are any number of discrete statistical distributions defined on the natural set of numbers (positive integers):$$\{1,2,3, ..., \infty\}$$Geometric Perhaps the best known such distribution is the Geometric with pmf:$$P(X=x) = p (1-p)^{x-1} \quad \text{for} \quad x = 1, 2, ...$$with parameter$0<p<1$. Mathematica's implementation of the ... 16 Mathematica 10 introduces IntegerName: IntegerName[n] gives a string containing the full English name of the integer n. IntegerName[n,"type"] gives a string of the specified type. Possible types include: "DigitsWords" a combination of three-digit numbers and words "Words" using only words "Approximate" the first few digits ... 15 Nested WolframAlpha approach, showing the intermediate steps: numberString[a_, k_: 10] := FixedPointList[ StringReplace[#, b : (DigitCharacter ..) :> WolframAlpha["spell " <> b, {{"Result", 1}, "Plaintext"}]] &, a, k] numberString["123456"] (* ==> {"123456", "123 thousand and 456", "one hundred twenty-three \ thousand and ... 13 I wondered if Chip's answer was exactly correct, given Daniel's comment about machine precision. So I did it a little differently with higher precision in a way that gives good confidence in the result. (It turns out that the machine precision answer is correct.) LogGamma can be expanded around infinity thusly: Series[LogGamma[z], {z, Infinity, 4}] to ... 12 I think you underestimate how many digits this number has. Even if you used scientific notation, the exponent would overflow your PC's memory, so you'd need scientific notation for the scientific notation. I'm not sure which number format you expect to get, but I think the form it's already in is probably the most useful. But let's try to get an idea for ... 12 You are losing hugely due to a base 10 implementation. Integers are manipulated in base 2 in Mathematica. So you would want a base 2 variant to get any reasonable behavior. Here is one way to code it. There might be tweaks that improve it. fastSquare[a_] := Catch[Module[ {len = BitLength[a], len2, hi, lo, h2, l2, hl}, If[len < 100, Throw[a^2]]; ... 9 Messy but a working method inWords[n_] := Module[ {r, numNames = {"", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine"}, teenNames = {" ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen"}, tensNames = {"", " ten", " twenty", " ... 9 One way would be to split the large number in smaller chunks, convert each of them to a string, which can be manipulated, and then exporting. bigNumber = 10000!; output = (StringJoin @@ #) & /@ Partition[ToString[#] & /@ IntegerDigits[bigNumber], 40, 40, {1, -1}] ; (* each line has 40 digits *) (* Make font smaller and red for all lines ... 9 However, the only method I've found that ensures numerically exact conversion is the manual one: delete the decimal point, and then divide by 10^z, where z is the number of digits to the right of the decimal. This does not produce an exact conversion because floating point numbers are represented in binary, not in decimal. I tried SetPrecision[a,Infinity]... 8 There are large numbers and you need to increase$MaxExtraPrecision, as well as use non-machine arithmetic. E.g.: $MaxExtraPrecision = 8000; N[de2 /. sol /. r -> -90 /. z -> 4, 20] gives 1.4495694130768246652*10^6429 Alternatively, you could do N[Expand[de2 /. sol /. r -> -90 /. z -> 4]] 8 Never use pattern matching unless you absolutely have to. Using Cases instead of Select can make a huge difference. Vectorize operations. Use Range instead of Table if you can. Test several things at once. And[test1, test2, test3] will abort when it can for maximum efficiency ("short circuit evaluation"). Taking this into consideration your code looks like ... 8 My original answer is incorrect -- it is preserved as a record of my own hubris. :^) Simply, as Rojo points out, the calculation is still being done with 1*^1000, it's just being done at a different time. One may see this by manually observing the time taken for evaluation on an idle machine, or by setting this option which will print the total time taken ... 8 In Mathematica 8 you can use free form input : = Spell 15 and you get "fifteen" Or just write = thirty and you obtain 30 Since for larger numbers this approach yields expressions like {number words number, _ } one could nest this arbitrarily to obtain expressions containing only words. In fact, it is sufficient to nest only two times. For ... 8 Since we are dealing with very large numbers, so one of the option is to use ListLogPlot P[x_]:= Your large expression here ListLogPlot[Table[{x, P[x]}, {x, 0, 100, 10}], PlotRange -> All, Frame -> True] For roots try with NSolve or FindRoot NSolve[P[x] == 0, x] 8 You can use BitLength or IntegerLength: BitLength[number] 4091 IntegerLength[number, 2] 4091 7 Table[1/2 < Floor[Mod[Floor[y/17] 2^(-17 Floor[x] - Mod[Floor[y], 17]), 2]], {x, 0, 106}, {y, n, n + 16}]\[Transpose] // Reverse // Boole // ArrayPlot Note the n + 17 is modified to n + 16. 7 Hmm, I just posted an answer yesterday that overcame just this problem with the undocumented option "SolveDiscreteSolutionBound" that controls a system limit: With[{ropts = SystemOptions["ReduceOptions"]}, Internal`WithLocalSettings[ SetSystemOptions[ "ReduceOptions" -> "SolveDiscreteSolutionBound" -> (1400*10^9)], Solve[y^2 == 441 + 48*x*(... 6 num = 1234567891234567899; triples = Reverse /@ Reverse@Partition[Reverse@IntegerDigits[num], 3, 3, 1, 0]; threePowers = {"septillion", "sextillion", "quintillion", "quadrillion", "trillion", "billion", "million", "thousand", ""}; singleRules = {0 -> "", 1 -> "one", 2 -> "two", 3 -> "three", 4 -> "four", 5 -> "five", 6 -> "... 6 This solution is similar in spirit to Prashant's. Though not particularly elegant, I avoid any calls to W|A and any other form of internet connectivity. Further down the post I also provide a solution to the inverse problem of returning the number when given English words. numberform[n_]:=With[{id=IntegerDigits@n}, Partition[PadLeft[id,... 6 I offer the following as a fast way of testing cubic and higher powers primes = Select[Range, PrimeQ] Get a list of all the relevant powers up to a specified limit list[nmax_] := Sort[Flatten[Table[Range[2, Floor[nmax^(1/p)]]^p, {p, Drop[primes, 1]}]]]; For example list (* {8, 27, 32, 64, 125, 128, 216, 243, 343, 512, 729, 1000} *) Define an ... 5 You should take advantage of the fact that a^b == c^(Log[c,a] b) so that E^(E^(10^72)) == 10^(Log[10,E] E^(10^72)) == 10^(Log[10,E] 10^(Log[10,E] 10^72)) Since Log[10,E] (that is, ln(10)) is about 2.3, the number of digits in your quantity (in base 10) is ~ 2.3 10^(2.3*10^72) 5 There is this way: SetAttributes[test, Listable] test[n_] := FirstPosition[Reverse[#[[2 ;; Ceiling[Length[#]/2]]] &[ Divisors[n]]], _?(IntegerQ[Log[#, n]] &), 0] =!= 0 Pick[#, test[#]] &[Range] 5 Here's one way, using Carl Woll's suggestion of MemoryConstrained, which runs very quickly: Do[ ans[t] = MemoryConstrained[ ReplacePart[pattern, Thread[Position[pattern, o] -> t]], 8*^9, (* depending on how much memory you have *)$Failed[t]], {t, tps} ] General::ovfl: Overflow occurred in computation. You can do this with Map ...

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