Hyperbolic tangent

Percentage Accurate: 8.9% → 97.8%
Time: 20.4s
Alternatives: 8
Speedup: 409.0×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ \frac{e^{x} - t\_0}{e^{x} + t\_0} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x)))) (/ (- (exp x) t_0) (+ (exp x) t_0))))
double code(double x) {
	double t_0 = exp(-x);
	return (exp(x) - t_0) / (exp(x) + t_0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = exp(-x)
    code = (exp(x) - t_0) / (exp(x) + t_0)
end function
public static double code(double x) {
	double t_0 = Math.exp(-x);
	return (Math.exp(x) - t_0) / (Math.exp(x) + t_0);
}
def code(x):
	t_0 = math.exp(-x)
	return (math.exp(x) - t_0) / (math.exp(x) + t_0)
function code(x)
	t_0 = exp(Float64(-x))
	return Float64(Float64(exp(x) - t_0) / Float64(exp(x) + t_0))
end
function tmp = code(x)
	t_0 = exp(-x);
	tmp = (exp(x) - t_0) / (exp(x) + t_0);
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, N[(N[(N[Exp[x], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
\frac{e^{x} - t\_0}{e^{x} + t\_0}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 8.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ \frac{e^{x} - t\_0}{e^{x} + t\_0} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x)))) (/ (- (exp x) t_0) (+ (exp x) t_0))))
double code(double x) {
	double t_0 = exp(-x);
	return (exp(x) - t_0) / (exp(x) + t_0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = exp(-x)
    code = (exp(x) - t_0) / (exp(x) + t_0)
end function
public static double code(double x) {
	double t_0 = Math.exp(-x);
	return (Math.exp(x) - t_0) / (Math.exp(x) + t_0);
}
def code(x):
	t_0 = math.exp(-x)
	return (math.exp(x) - t_0) / (math.exp(x) + t_0)
function code(x)
	t_0 = exp(Float64(-x))
	return Float64(Float64(exp(x) - t_0) / Float64(exp(x) + t_0))
end
function tmp = code(x)
	t_0 = exp(-x);
	tmp = (exp(x) - t_0) / (exp(x) + t_0);
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, N[(N[(N[Exp[x], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
\frac{e^{x} - t\_0}{e^{x} + t\_0}
\end{array}
\end{array}

Alternative 1: 97.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + {x}^{2} \cdot 0.0003968253968253968\right)\right)\right)}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (*
   x
   (+
    2.0
    (*
     (pow x 2.0)
     (+
      0.3333333333333333
      (*
       (pow x 2.0)
       (+ 0.016666666666666666 (* (pow x 2.0) 0.0003968253968253968)))))))
  (+
   2.0
   (*
    (pow x 2.0)
    (+
     1.0
     (*
      (pow x 2.0)
      (+ 0.08333333333333333 (* (pow x 2.0) 0.002777777777777778))))))))
double code(double x) {
	return (x * (2.0 + (pow(x, 2.0) * (0.3333333333333333 + (pow(x, 2.0) * (0.016666666666666666 + (pow(x, 2.0) * 0.0003968253968253968))))))) / (2.0 + (pow(x, 2.0) * (1.0 + (pow(x, 2.0) * (0.08333333333333333 + (pow(x, 2.0) * 0.002777777777777778))))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * (2.0d0 + ((x ** 2.0d0) * (0.3333333333333333d0 + ((x ** 2.0d0) * (0.016666666666666666d0 + ((x ** 2.0d0) * 0.0003968253968253968d0))))))) / (2.0d0 + ((x ** 2.0d0) * (1.0d0 + ((x ** 2.0d0) * (0.08333333333333333d0 + ((x ** 2.0d0) * 0.002777777777777778d0))))))
end function
public static double code(double x) {
	return (x * (2.0 + (Math.pow(x, 2.0) * (0.3333333333333333 + (Math.pow(x, 2.0) * (0.016666666666666666 + (Math.pow(x, 2.0) * 0.0003968253968253968))))))) / (2.0 + (Math.pow(x, 2.0) * (1.0 + (Math.pow(x, 2.0) * (0.08333333333333333 + (Math.pow(x, 2.0) * 0.002777777777777778))))));
}
def code(x):
	return (x * (2.0 + (math.pow(x, 2.0) * (0.3333333333333333 + (math.pow(x, 2.0) * (0.016666666666666666 + (math.pow(x, 2.0) * 0.0003968253968253968))))))) / (2.0 + (math.pow(x, 2.0) * (1.0 + (math.pow(x, 2.0) * (0.08333333333333333 + (math.pow(x, 2.0) * 0.002777777777777778))))))
function code(x)
	return Float64(Float64(x * Float64(2.0 + Float64((x ^ 2.0) * Float64(0.3333333333333333 + Float64((x ^ 2.0) * Float64(0.016666666666666666 + Float64((x ^ 2.0) * 0.0003968253968253968))))))) / Float64(2.0 + Float64((x ^ 2.0) * Float64(1.0 + Float64((x ^ 2.0) * Float64(0.08333333333333333 + Float64((x ^ 2.0) * 0.002777777777777778)))))))
end
function tmp = code(x)
	tmp = (x * (2.0 + ((x ^ 2.0) * (0.3333333333333333 + ((x ^ 2.0) * (0.016666666666666666 + ((x ^ 2.0) * 0.0003968253968253968))))))) / (2.0 + ((x ^ 2.0) * (1.0 + ((x ^ 2.0) * (0.08333333333333333 + ((x ^ 2.0) * 0.002777777777777778))))));
end
code[x_] := N[(N[(x * N[(2.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.016666666666666666 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.08333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.002777777777777778), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + {x}^{2} \cdot 0.0003968253968253968\right)\right)\right)}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + 0.002777777777777778 \cdot {x}^{2}\right)\right)}} \]
  4. Step-by-step derivation
    1. *-commutative7.9%

      \[\leadsto \frac{e^{x} - e^{-x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + \color{blue}{{x}^{2} \cdot 0.002777777777777778}\right)\right)} \]
  5. Simplified7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
  6. Taylor expanded in x around 0 97.3%

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + 0.0003968253968253968 \cdot {x}^{2}\right)\right)\right)}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  7. Step-by-step derivation
    1. *-commutative97.3%

      \[\leadsto \frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + \color{blue}{{x}^{2} \cdot 0.0003968253968253968}\right)\right)\right)}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  8. Simplified97.3%

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + {x}^{2} \cdot 0.0003968253968253968\right)\right)\right)}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  9. Add Preprocessing

Alternative 2: 97.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot 0.016666666666666666\right)\right)}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (*
   x
   (+
    2.0
    (*
     (pow x 2.0)
     (+ 0.3333333333333333 (* (pow x 2.0) 0.016666666666666666)))))
  (+
   2.0
   (*
    (pow x 2.0)
    (+
     1.0
     (*
      (pow x 2.0)
      (+ 0.08333333333333333 (* (pow x 2.0) 0.002777777777777778))))))))
double code(double x) {
	return (x * (2.0 + (pow(x, 2.0) * (0.3333333333333333 + (pow(x, 2.0) * 0.016666666666666666))))) / (2.0 + (pow(x, 2.0) * (1.0 + (pow(x, 2.0) * (0.08333333333333333 + (pow(x, 2.0) * 0.002777777777777778))))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * (2.0d0 + ((x ** 2.0d0) * (0.3333333333333333d0 + ((x ** 2.0d0) * 0.016666666666666666d0))))) / (2.0d0 + ((x ** 2.0d0) * (1.0d0 + ((x ** 2.0d0) * (0.08333333333333333d0 + ((x ** 2.0d0) * 0.002777777777777778d0))))))
end function
public static double code(double x) {
	return (x * (2.0 + (Math.pow(x, 2.0) * (0.3333333333333333 + (Math.pow(x, 2.0) * 0.016666666666666666))))) / (2.0 + (Math.pow(x, 2.0) * (1.0 + (Math.pow(x, 2.0) * (0.08333333333333333 + (Math.pow(x, 2.0) * 0.002777777777777778))))));
}
def code(x):
	return (x * (2.0 + (math.pow(x, 2.0) * (0.3333333333333333 + (math.pow(x, 2.0) * 0.016666666666666666))))) / (2.0 + (math.pow(x, 2.0) * (1.0 + (math.pow(x, 2.0) * (0.08333333333333333 + (math.pow(x, 2.0) * 0.002777777777777778))))))
function code(x)
	return Float64(Float64(x * Float64(2.0 + Float64((x ^ 2.0) * Float64(0.3333333333333333 + Float64((x ^ 2.0) * 0.016666666666666666))))) / Float64(2.0 + Float64((x ^ 2.0) * Float64(1.0 + Float64((x ^ 2.0) * Float64(0.08333333333333333 + Float64((x ^ 2.0) * 0.002777777777777778)))))))
end
function tmp = code(x)
	tmp = (x * (2.0 + ((x ^ 2.0) * (0.3333333333333333 + ((x ^ 2.0) * 0.016666666666666666))))) / (2.0 + ((x ^ 2.0) * (1.0 + ((x ^ 2.0) * (0.08333333333333333 + ((x ^ 2.0) * 0.002777777777777778))))));
end
code[x_] := N[(N[(x * N[(2.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.08333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.002777777777777778), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot 0.016666666666666666\right)\right)}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + 0.002777777777777778 \cdot {x}^{2}\right)\right)}} \]
  4. Step-by-step derivation
    1. *-commutative7.9%

      \[\leadsto \frac{e^{x} - e^{-x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + \color{blue}{{x}^{2} \cdot 0.002777777777777778}\right)\right)} \]
  5. Simplified7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
  6. Taylor expanded in x around 0 97.2%

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + 0.016666666666666666 \cdot {x}^{2}\right)\right)}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  7. Step-by-step derivation
    1. *-commutative97.2%

      \[\leadsto \frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + \color{blue}{{x}^{2} \cdot 0.016666666666666666}\right)\right)}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  8. Simplified97.2%

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot 0.016666666666666666\right)\right)}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  9. Add Preprocessing

Alternative 3: 97.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + {x}^{2} \cdot 0.0003968253968253968\right)\right)\right)}{e^{x} + e^{-x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (*
   x
   (+
    2.0
    (*
     (pow x 2.0)
     (+
      0.3333333333333333
      (*
       (pow x 2.0)
       (+ 0.016666666666666666 (* (pow x 2.0) 0.0003968253968253968)))))))
  (+ (exp x) (exp (- x)))))
double code(double x) {
	return (x * (2.0 + (pow(x, 2.0) * (0.3333333333333333 + (pow(x, 2.0) * (0.016666666666666666 + (pow(x, 2.0) * 0.0003968253968253968))))))) / (exp(x) + exp(-x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * (2.0d0 + ((x ** 2.0d0) * (0.3333333333333333d0 + ((x ** 2.0d0) * (0.016666666666666666d0 + ((x ** 2.0d0) * 0.0003968253968253968d0))))))) / (exp(x) + exp(-x))
end function
public static double code(double x) {
	return (x * (2.0 + (Math.pow(x, 2.0) * (0.3333333333333333 + (Math.pow(x, 2.0) * (0.016666666666666666 + (Math.pow(x, 2.0) * 0.0003968253968253968))))))) / (Math.exp(x) + Math.exp(-x));
}
def code(x):
	return (x * (2.0 + (math.pow(x, 2.0) * (0.3333333333333333 + (math.pow(x, 2.0) * (0.016666666666666666 + (math.pow(x, 2.0) * 0.0003968253968253968))))))) / (math.exp(x) + math.exp(-x))
function code(x)
	return Float64(Float64(x * Float64(2.0 + Float64((x ^ 2.0) * Float64(0.3333333333333333 + Float64((x ^ 2.0) * Float64(0.016666666666666666 + Float64((x ^ 2.0) * 0.0003968253968253968))))))) / Float64(exp(x) + exp(Float64(-x))))
end
function tmp = code(x)
	tmp = (x * (2.0 + ((x ^ 2.0) * (0.3333333333333333 + ((x ^ 2.0) * (0.016666666666666666 + ((x ^ 2.0) * 0.0003968253968253968))))))) / (exp(x) + exp(-x));
end
code[x_] := N[(N[(x * N[(2.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.016666666666666666 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + {x}^{2} \cdot 0.0003968253968253968\right)\right)\right)}{e^{x} + e^{-x}}
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 97.1%

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + 0.0003968253968253968 \cdot {x}^{2}\right)\right)\right)}}{e^{x} + e^{-x}} \]
  4. Step-by-step derivation
    1. *-commutative97.3%

      \[\leadsto \frac{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + \color{blue}{{x}^{2} \cdot 0.0003968253968253968}\right)\right)\right)}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  5. Simplified97.1%

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.016666666666666666 + {x}^{2} \cdot 0.0003968253968253968\right)\right)\right)}}{e^{x} + e^{-x}} \]
  6. Add Preprocessing

Alternative 4: 97.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{2 \cdot \sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (* 2.0 (sinh x))
  (+
   2.0
   (*
    (pow x 2.0)
    (+
     1.0
     (*
      (pow x 2.0)
      (+ 0.08333333333333333 (* (pow x 2.0) 0.002777777777777778))))))))
double code(double x) {
	return (2.0 * sinh(x)) / (2.0 + (pow(x, 2.0) * (1.0 + (pow(x, 2.0) * (0.08333333333333333 + (pow(x, 2.0) * 0.002777777777777778))))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (2.0d0 * sinh(x)) / (2.0d0 + ((x ** 2.0d0) * (1.0d0 + ((x ** 2.0d0) * (0.08333333333333333d0 + ((x ** 2.0d0) * 0.002777777777777778d0))))))
end function
public static double code(double x) {
	return (2.0 * Math.sinh(x)) / (2.0 + (Math.pow(x, 2.0) * (1.0 + (Math.pow(x, 2.0) * (0.08333333333333333 + (Math.pow(x, 2.0) * 0.002777777777777778))))));
}
def code(x):
	return (2.0 * math.sinh(x)) / (2.0 + (math.pow(x, 2.0) * (1.0 + (math.pow(x, 2.0) * (0.08333333333333333 + (math.pow(x, 2.0) * 0.002777777777777778))))))
function code(x)
	return Float64(Float64(2.0 * sinh(x)) / Float64(2.0 + Float64((x ^ 2.0) * Float64(1.0 + Float64((x ^ 2.0) * Float64(0.08333333333333333 + Float64((x ^ 2.0) * 0.002777777777777778)))))))
end
function tmp = code(x)
	tmp = (2.0 * sinh(x)) / (2.0 + ((x ^ 2.0) * (1.0 + ((x ^ 2.0) * (0.08333333333333333 + ((x ^ 2.0) * 0.002777777777777778))))));
end
code[x_] := N[(N[(2.0 * N[Sinh[x], $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.08333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.002777777777777778), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{2 \cdot \sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + 0.002777777777777778 \cdot {x}^{2}\right)\right)}} \]
  4. Step-by-step derivation
    1. *-commutative7.9%

      \[\leadsto \frac{e^{x} - e^{-x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + \color{blue}{{x}^{2} \cdot 0.002777777777777778}\right)\right)} \]
  5. Simplified7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
  6. Step-by-step derivation
    1. sinh-undef97.1%

      \[\leadsto \frac{\color{blue}{2 \cdot \sinh x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
    2. *-un-lft-identity97.1%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{1 \cdot \left(2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)\right)}} \]
    3. times-frac97.1%

      \[\leadsto \color{blue}{\frac{2}{1} \cdot \frac{\sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
    4. metadata-eval97.1%

      \[\leadsto \color{blue}{2} \cdot \frac{\sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
    5. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\color{blue}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right) + 2}} \]
    6. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\color{blue}{\mathsf{fma}\left({x}^{2}, 1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right), 2\right)}} \]
    7. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \color{blue}{{x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right) + 1}, 2\right)} \]
    8. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \color{blue}{\mathsf{fma}\left({x}^{2}, 0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778, 1\right)}, 2\right)} \]
    9. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \color{blue}{{x}^{2} \cdot 0.002777777777777778 + 0.08333333333333333}, 1\right), 2\right)} \]
    10. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \color{blue}{\mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right)}, 1\right), 2\right)} \]
  7. Applied egg-rr97.1%

    \[\leadsto \color{blue}{2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  8. Step-by-step derivation
    1. associate-*r/97.1%

      \[\leadsto \color{blue}{\frac{2 \cdot \sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  9. Simplified97.1%

    \[\leadsto \color{blue}{\frac{2 \cdot \sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  10. Taylor expanded in x around 0 97.1%

    \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + 0.002777777777777778 \cdot {x}^{2}\right)\right)}} \]
  11. Final simplification97.1%

    \[\leadsto \frac{2 \cdot \sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
  12. Add Preprocessing

Alternative 5: 97.6% accurate, 1.9× speedup?

\[\begin{array}{l} \\ x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.13333333333333333 - 0.3333333333333333\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (*
  x
  (+
   1.0
   (*
    (pow x 2.0)
    (- (* (pow x 2.0) 0.13333333333333333) 0.3333333333333333)))))
double code(double x) {
	return x * (1.0 + (pow(x, 2.0) * ((pow(x, 2.0) * 0.13333333333333333) - 0.3333333333333333)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (1.0d0 + ((x ** 2.0d0) * (((x ** 2.0d0) * 0.13333333333333333d0) - 0.3333333333333333d0)))
end function
public static double code(double x) {
	return x * (1.0 + (Math.pow(x, 2.0) * ((Math.pow(x, 2.0) * 0.13333333333333333) - 0.3333333333333333)));
}
def code(x):
	return x * (1.0 + (math.pow(x, 2.0) * ((math.pow(x, 2.0) * 0.13333333333333333) - 0.3333333333333333)))
function code(x)
	return Float64(x * Float64(1.0 + Float64((x ^ 2.0) * Float64(Float64((x ^ 2.0) * 0.13333333333333333) - 0.3333333333333333))))
end
function tmp = code(x)
	tmp = x * (1.0 + ((x ^ 2.0) * (((x ^ 2.0) * 0.13333333333333333) - 0.3333333333333333)));
end
code[x_] := N[(x * N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(N[Power[x, 2.0], $MachinePrecision] * 0.13333333333333333), $MachinePrecision] - 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.13333333333333333 - 0.3333333333333333\right)\right)
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 97.0%

    \[\leadsto \color{blue}{x \cdot \left(1 + {x}^{2} \cdot \left(0.13333333333333333 \cdot {x}^{2} - 0.3333333333333333\right)\right)} \]
  4. Final simplification97.0%

    \[\leadsto x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.13333333333333333 - 0.3333333333333333\right)\right) \]
  5. Add Preprocessing

Alternative 6: 97.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \frac{2 \cdot \left(x + 0.16666666666666666 \cdot {x}^{3}\right)}{\mathsf{fma}\left(x, x, 2\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (* 2.0 (+ x (* 0.16666666666666666 (pow x 3.0)))) (fma x x 2.0)))
double code(double x) {
	return (2.0 * (x + (0.16666666666666666 * pow(x, 3.0)))) / fma(x, x, 2.0);
}
function code(x)
	return Float64(Float64(2.0 * Float64(x + Float64(0.16666666666666666 * (x ^ 3.0)))) / fma(x, x, 2.0))
end
code[x_] := N[(N[(2.0 * N[(x + N[(0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * x + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{2 \cdot \left(x + 0.16666666666666666 \cdot {x}^{3}\right)}{\mathsf{fma}\left(x, x, 2\right)}
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + 0.002777777777777778 \cdot {x}^{2}\right)\right)}} \]
  4. Step-by-step derivation
    1. *-commutative7.9%

      \[\leadsto \frac{e^{x} - e^{-x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + \color{blue}{{x}^{2} \cdot 0.002777777777777778}\right)\right)} \]
  5. Simplified7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
  6. Step-by-step derivation
    1. sinh-undef97.1%

      \[\leadsto \frac{\color{blue}{2 \cdot \sinh x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
    2. *-un-lft-identity97.1%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{1 \cdot \left(2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)\right)}} \]
    3. times-frac97.1%

      \[\leadsto \color{blue}{\frac{2}{1} \cdot \frac{\sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
    4. metadata-eval97.1%

      \[\leadsto \color{blue}{2} \cdot \frac{\sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
    5. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\color{blue}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right) + 2}} \]
    6. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\color{blue}{\mathsf{fma}\left({x}^{2}, 1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right), 2\right)}} \]
    7. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \color{blue}{{x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right) + 1}, 2\right)} \]
    8. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \color{blue}{\mathsf{fma}\left({x}^{2}, 0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778, 1\right)}, 2\right)} \]
    9. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \color{blue}{{x}^{2} \cdot 0.002777777777777778 + 0.08333333333333333}, 1\right), 2\right)} \]
    10. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \color{blue}{\mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right)}, 1\right), 2\right)} \]
  7. Applied egg-rr97.1%

    \[\leadsto \color{blue}{2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  8. Step-by-step derivation
    1. associate-*r/97.1%

      \[\leadsto \color{blue}{\frac{2 \cdot \sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  9. Simplified97.1%

    \[\leadsto \color{blue}{\frac{2 \cdot \sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  10. Taylor expanded in x around 0 96.6%

    \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{2 + {x}^{2}}} \]
  11. Step-by-step derivation
    1. +-commutative96.6%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{{x}^{2} + 2}} \]
    2. unpow296.6%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{x \cdot x} + 2} \]
    3. fma-define96.6%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{\mathsf{fma}\left(x, x, 2\right)}} \]
  12. Simplified96.6%

    \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{\mathsf{fma}\left(x, x, 2\right)}} \]
  13. Taylor expanded in x around 0 96.9%

    \[\leadsto \frac{2 \cdot \color{blue}{\left(x \cdot \left(1 + 0.16666666666666666 \cdot {x}^{2}\right)\right)}}{\mathsf{fma}\left(x, x, 2\right)} \]
  14. Step-by-step derivation
    1. distribute-rgt-in96.9%

      \[\leadsto \frac{2 \cdot \color{blue}{\left(1 \cdot x + \left(0.16666666666666666 \cdot {x}^{2}\right) \cdot x\right)}}{\mathsf{fma}\left(x, x, 2\right)} \]
    2. *-lft-identity96.9%

      \[\leadsto \frac{2 \cdot \left(\color{blue}{x} + \left(0.16666666666666666 \cdot {x}^{2}\right) \cdot x\right)}{\mathsf{fma}\left(x, x, 2\right)} \]
    3. associate-*l*96.9%

      \[\leadsto \frac{2 \cdot \left(x + \color{blue}{0.16666666666666666 \cdot \left({x}^{2} \cdot x\right)}\right)}{\mathsf{fma}\left(x, x, 2\right)} \]
    4. unpow296.9%

      \[\leadsto \frac{2 \cdot \left(x + 0.16666666666666666 \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot x\right)\right)}{\mathsf{fma}\left(x, x, 2\right)} \]
    5. unpow396.9%

      \[\leadsto \frac{2 \cdot \left(x + 0.16666666666666666 \cdot \color{blue}{{x}^{3}}\right)}{\mathsf{fma}\left(x, x, 2\right)} \]
  15. Simplified96.9%

    \[\leadsto \frac{2 \cdot \color{blue}{\left(x + 0.16666666666666666 \cdot {x}^{3}\right)}}{\mathsf{fma}\left(x, x, 2\right)} \]
  16. Add Preprocessing

Alternative 7: 97.3% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \frac{2 \cdot \sinh x}{\mathsf{fma}\left(x, x, 2\right)} \end{array} \]
(FPCore (x) :precision binary64 (/ (* 2.0 (sinh x)) (fma x x 2.0)))
double code(double x) {
	return (2.0 * sinh(x)) / fma(x, x, 2.0);
}
function code(x)
	return Float64(Float64(2.0 * sinh(x)) / fma(x, x, 2.0))
end
code[x_] := N[(N[(2.0 * N[Sinh[x], $MachinePrecision]), $MachinePrecision] / N[(x * x + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{2 \cdot \sinh x}{\mathsf{fma}\left(x, x, 2\right)}
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + 0.002777777777777778 \cdot {x}^{2}\right)\right)}} \]
  4. Step-by-step derivation
    1. *-commutative7.9%

      \[\leadsto \frac{e^{x} - e^{-x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + \color{blue}{{x}^{2} \cdot 0.002777777777777778}\right)\right)} \]
  5. Simplified7.9%

    \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
  6. Step-by-step derivation
    1. sinh-undef97.1%

      \[\leadsto \frac{\color{blue}{2 \cdot \sinh x}}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
    2. *-un-lft-identity97.1%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{1 \cdot \left(2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)\right)}} \]
    3. times-frac97.1%

      \[\leadsto \color{blue}{\frac{2}{1} \cdot \frac{\sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)}} \]
    4. metadata-eval97.1%

      \[\leadsto \color{blue}{2} \cdot \frac{\sinh x}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right)} \]
    5. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\color{blue}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right)\right) + 2}} \]
    6. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\color{blue}{\mathsf{fma}\left({x}^{2}, 1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right), 2\right)}} \]
    7. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \color{blue}{{x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778\right) + 1}, 2\right)} \]
    8. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \color{blue}{\mathsf{fma}\left({x}^{2}, 0.08333333333333333 + {x}^{2} \cdot 0.002777777777777778, 1\right)}, 2\right)} \]
    9. +-commutative97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \color{blue}{{x}^{2} \cdot 0.002777777777777778 + 0.08333333333333333}, 1\right), 2\right)} \]
    10. fma-define97.1%

      \[\leadsto 2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \color{blue}{\mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right)}, 1\right), 2\right)} \]
  7. Applied egg-rr97.1%

    \[\leadsto \color{blue}{2 \cdot \frac{\sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  8. Step-by-step derivation
    1. associate-*r/97.1%

      \[\leadsto \color{blue}{\frac{2 \cdot \sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  9. Simplified97.1%

    \[\leadsto \color{blue}{\frac{2 \cdot \sinh x}{\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)}} \]
  10. Taylor expanded in x around 0 96.6%

    \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{2 + {x}^{2}}} \]
  11. Step-by-step derivation
    1. +-commutative96.6%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{{x}^{2} + 2}} \]
    2. unpow296.6%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{x \cdot x} + 2} \]
    3. fma-define96.6%

      \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{\mathsf{fma}\left(x, x, 2\right)}} \]
  12. Simplified96.6%

    \[\leadsto \frac{2 \cdot \sinh x}{\color{blue}{\mathsf{fma}\left(x, x, 2\right)}} \]
  13. Add Preprocessing

Alternative 8: 97.0% accurate, 409.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x) :precision binary64 x)
double code(double x) {
	return x;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x
end function
public static double code(double x) {
	return x;
}
def code(x):
	return x
function code(x)
	return x
end
function tmp = code(x)
	tmp = x;
end
code[x_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 9.2%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 96.6%

    \[\leadsto \color{blue}{x} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2024107 
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))