Guest User

Decimal notation to se-notation

a guest
Oct 11th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 18.74 KB | None | 0 0
  1.    
  2.  
  3.      
  4.     %%%%%%%%%% Most numbers up to 20 characters  
  5. %%%%%%%%%%%%%%%%%%%% Mathematica code to generate the strings
  6.      
  7.     gen[n_] :=
  8.      Select[
  9.       StringJoin /@ (# /. {1 -> "s", -1 -> "e"} & /@
  10.          (Prepend[#,
  11.              1] & /@ (Append[#, -1] & /@ (
  12.               Select[      
  13.                Permutations[
  14.                 Join[ConstantArray[1, n - 1], ConstantArray[-1, n - 1]]],          
  15.                FreeQ[Table[Plus @@ Take[#, k] >= 0, {k, 1, Length@#}],
  16.                  False] &
  17.                ]
  18.               )))),
  19.       StringFreeQ[#, "esee"] &]
  20.      
  21.      
  22.     SortBy[
  23.       Flatten[
  24.        Table[{If[# > 10^100, ">10^100", #] &@eval[#], #} & /@ gen[n], {n,
  25.          1, 10}],
  26.        1],
  27.       First] // TableForm
  28.      
  29.     %%%%%%%%%%%%%%%%%%%% Mathematica code to translate the strings to decimal
  30.      
  31.     R = 10^50;
  32.      
  33.     primePower[exps_] :=
  34.      Times @@ Thread@Power[Prime@Range@Length@exps, exps]
  35.      
  36.     stringPrimePower[string_] :=
  37.      If[# < R || # == "abort", ToString@#, "abort"] &@(primePower@
  38.         Cases[ToExpression[
  39.           StringCases[string, DigitCharacter ..]], _Integer])
  40.      
  41.     powersToNumber[string_] :=
  42.      If[StringFreeQ[string, "abort"],
  43.       StringReplace[
  44.        StringReplace[
  45.         string,
  46.         RegularExpression["s" <> "([^se]+)" <> "e"] -> "(" <> "$1" <> ")"],
  47.        "(" ~~ x__ ~~ ")" :> "S" <> stringPrimePower[x] <> "E"],
  48.       "abort"]
  49.      
  50.     eval[string_] :=
  51.      ToExpression@StringDrop[StringDrop[
  52.         FixedPoint[powersToNumber,
  53.          StringReplace[StringReplace[string, "se" -> "S0E"],
  54.           "sS0Ee" -> "S1E"]],
  55.         1], -1]
Advertisement
Add Comment
Please, Sign In to add comment