Tag Info

13

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.783516108362e12). It has to do with this being ...

11

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 ...

11

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 ... 11 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 ...

10

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", " ...

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

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 ...

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}, ...

4

Preface I want to emphasis the comment of @DanielLichtblau I think the Miller-Rabin type of testing makes more sense than endless divisibility tests Furthermore, I won't go into discussing your programming style with setting global variables in Modulearized functions, using parameter-names like N which are clearly built-in symbols, etc. Solution I ...

3

I used the following to solve Problem 17 from Project Euler (hint hint). It's working on numbers up to 1000, but the grammar of larger numbers is trivial compared to small numbers and should easily be able to be implemented. Usage: numberToWord /@ {14, 271, 944} {"fourteen", "two hundred and seventy-one", "nine hundred and forty-four"} Source: ...

2

You could define your own definitions for formatting numbers and variables. For example WriteInput1[file_, var_, eqlist_] := Module[{text, removewhite, eq2, gg, hh, format}, format[a_?NumericQ] := Block[{Format}, ToString@NumberForm[a, 10, NumberFormat -> (Module[{man}, man = #1; If[StringTake[#1, -1] === ".", man = man ...

2

For me SetAttributes[ParallelTrialFactorFreeQ, HoldAll] does the trick and reduces the measured time your function needs to evaluate down to what you would expect. Additionally I noticed that specifying the method used by ParallelDo brings down the timing slightly. By try and error i figured that Method -> "CoarsestGrained" works best on my ...

1

I've come up with the idea of expressing any number n as 2^Exp + B. The idea can be generalized to any other base, too. FastSquare2[a_] := ( TotalLen = IntegerLength[a]; If[TotalLen == 1, Return[a*a]]; Exp = Ceiling[Log[10, (a)]*Log[10.]/Log[2.]]; If[2^Exp > a, Exp--]; B = a - 2^Exp; Result = 2^(2 Exp) + 2*(2^Exp)*B + B^2; ...

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