Can Mathematica propose an exact value based on an approximate one?
Here's some code that I used recently, based on code by Paul Abbott [1, 2].
Clear[TranscendentalRecognize]
TranscendentalRecognize[num_Real, basis_List, ord_?Positive, debug:(True|False):False] :=
Module[{vect, mat, lr, ans},
vect = Round[10^Floor[ord - 1] Join[{num}, N[basis, ord]]];
mat = Append[IdentityMatrix[Length[vect]], vect];
lr = LatticeReduce[Transpose[mat]];
If[debug, Print[lr // TableForm]];
(* If a row of lr starts with zero, then it's just a relationship between the basis
element. We move such rows to the end. *)
While[lr[[1, 1]] === 0, lr = RotateLeft[lr]];
(* Now that the first element of the first row is nonzero, we choose it as our best
solution and normalize the answer *)
ans = First[lr[[1]]]^-1 Most[Rest[lr[[1]]]].basis;
Sign[N@ans] Sign[num] ans]
TranscendentalRecognize[num_Real, basis_List] :=
TranscendentalRecognize[num, basis, Precision[num]]
Then, we can identify your number using something like
num = Sum[1/(2`50*n!), {n, 0, 100}]
TranscendentalRecognize[num, {E, Pi, EulerGamma}]
(* Returns
1.3591409142295226176801437356763312488786235468500
E/2 *)
Compare with
WolframAlpha[ToString[num], IncludePods -> "PossibleClosedForm"]
This code can be cleaned up a little and made more efficient by using the PSLQ based algorithm FindIntegerNullVector
introduced in Mathematica version 8.
This is probably something like that which Wolfram|Alpha does. It just tries a combination of various common transcendentals until it comes up with something that looks close. To see some code on how you might write something like that, look at the mpmath (Python) implementation - Number Identification. For example, here's a quick IPython session:
In [1]: from mpmath import *
In [2]: mp.dps = 20;
In [3]: identify(1.35914091422952261768014, ['e', 'pi'])
Out[3]: '((1/2)*e)'
I can offer a round-about method.
First compute the numerical approximation. I obtain, to high precision,
In[24]:= N[Sum[1/(2*n!), {n, 0, 100}], 100]
Out[24]= 1.\
3591409142295226176801437356763312488786235468499797874834838138620383\
15176773797285691089262583214
Now paste that into a Wolfram|Alpha query, accessed by clicking on the '+' sign at upper left of a fresh input cell. This gives, among other things, possible closed forms.
To the best of my knowledge, the heuristic methods used by W|A for this task are not directly exposed in any other way in Mathematica proper.
Following up on Simon's note in his answer:
This code can be cleaned up a little and made more efficient by using the PSLQ-based algorithm
FindIntegerNullVector[]
introduced in Mathematica version 8.
here is a re-implementation of Abbott's TranscendentalRecognize[]
:
TranscendentalRecognize[num_?NumericQ, basis_?VectorQ] := Module[{lr, ans},
lr = FindIntegerNullVector[Prepend[N[basis, Precision[num]], num]];
ans = Rest[lr].basis/First[lr];
Sign[N[ans]] Sign[num] ans]
As already noted, this will only work for recognizing linear combinations of any constant given in the list basis
(it thus can't be used to recognize $\pi/e$ from its decimal expansion, for instance).
To use the same example:
TranscendentalRecognize[1.35914091422952261768014, {Pi, E}]
E/2