# Automatic identification and substitution of fundamental mathematical constants

In some cases Mathematica expresses the result of calculations using fundamental constants. For example:

4 Sum[2/((4 n + 1) (4 n + 3)), {n, 0, \[Infinity]}]


(* $$\pi$$ *)

or

Sum[1/n!, {n, 0, \[Infinity]}]


(* $$e$$ *)

But in others, it does not:

13/8 + Sum[((-1)^(n + 1) (2 n + 1)!)/((n + 2)! n! 4^(2 n + 3)),
{n, 0, \[Infinity]}]


(* $$\frac{13}{8}+\frac{1}{8} \left(4 \sqrt{5}-9\right)$$ *)

You can apply Simplify to that result to see that it is:

(* $$\frac{1}{2} \left(1+\sqrt{5}\right)$$ *)

Exactly.

But this is the GoldenRatio, $$\varphi$$.

Why didn't Mathematica express the summation in terms of $$\varphi$$?

More specifically: Why does Mathematica express (simplify) some results using mathematical constants but not others? How can I computationally force or convert or express results to be expressed in mathematical constants, if possible?

How can I computationally force or convert or express results to be expressed in mathematical constants, if possible?

For the GoldenRatio, it shows up as $$\phi$$ only in TraditionalForm. So it is not a built in symbol like there is for $$e$$ and $$\pi$$. Typing GoldenRatio just echoes back GoldenRatio.

So only way I see to force the output to be $$\phi$$, which is GoldenRatio but written as a symbol, is to use your own transformation rules

myRules = # /. 1/2 (1 + Sqrt) -> TraditionalForm[GoldenRatio] &;
s = 13/8 + Sum[((-1)^(n + 1) (2 n + 1)!)/((n + 2)! n! 4^(2 n + 3)), {n, 0, ∞}];
Simplify[s, TransformationFunctions -> {Automatic, myRules}]


Gives Which is still GoldenRatio

 N[%] You could have the rule be the following if you prefer.

myRules = # /. 1/2 (1 + Sqrt) -> GoldenRatio &;
s = 13/8 + Sum[((-1)^(n + 1) (2 n + 1)!)/((n + 2)! n! 4^(2 n + 3)), {n, 0, ∞}];
Simplify[s, TransformationFunctions -> {Automatic, myRules}] As to why it does not do that automatically, my guess is that it is probably very expensive computationally to always check for these values in the output and replace them with known constants each time. There are 100's of known Mathematical constants And having to check for each buried value inside long expressions each time and replace these with known built-in symbols (if these exist in Mathematica to start with), it will slow down the computation. It also depends on the form of the expression and how it is written to detect these.

But one can always use their own transformation rules as above.

• Perfect. Thorough. Clear. Scholarly. Helpful. ($\checkmark$) Aug 13 at 19:45
• Since replacements are done structurally, Sqrt :> 2*GoldenRatio - 1 would match more general cases. Aug 14 at 16:26