Hyperbolic tangent

Percentage Accurate: 9.0% → 100.0%
Time: 7.5s
Alternatives: 10
Speedup: 422.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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x)
use fmin_fmax_functions
    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 10 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: 9.0% 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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x)
use fmin_fmax_functions
    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: 100.0% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \tanh x \end{array} \]
(FPCore (x) :precision binary64 (tanh x))
double code(double x) {
	return tanh(x);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = tanh(x)
end function
public static double code(double x) {
	return Math.tanh(x);
}
def code(x):
	return math.tanh(x)
function code(x)
	return tanh(x)
end
function tmp = code(x)
	tmp = tanh(x);
end
code[x_] := N[Tanh[x], $MachinePrecision]
\begin{array}{l}

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

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}} \]
    2. lift--.f64N/A

      \[\leadsto \frac{\color{blue}{e^{x} - e^{-x}}}{e^{x} + e^{-x}} \]
    3. lift-exp.f64N/A

      \[\leadsto \frac{\color{blue}{e^{x}} - e^{-x}}{e^{x} + e^{-x}} \]
    4. lift-neg.f64N/A

      \[\leadsto \frac{e^{x} - e^{\color{blue}{\mathsf{neg}\left(x\right)}}}{e^{x} + e^{-x}} \]
    5. lift-exp.f64N/A

      \[\leadsto \frac{e^{x} - \color{blue}{e^{\mathsf{neg}\left(x\right)}}}{e^{x} + e^{-x}} \]
    6. lift-+.f64N/A

      \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{\color{blue}{e^{x} + e^{-x}}} \]
    7. lift-exp.f64N/A

      \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{\color{blue}{e^{x}} + e^{-x}} \]
    8. lift-neg.f64N/A

      \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{e^{x} + e^{\color{blue}{\mathsf{neg}\left(x\right)}}} \]
    9. lift-exp.f64N/A

      \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{e^{x} + \color{blue}{e^{\mathsf{neg}\left(x\right)}}} \]
    10. tanh-undefN/A

      \[\leadsto \color{blue}{\tanh x} \]
    11. lower-tanh.f64100.0

      \[\leadsto \color{blue}{\tanh x} \]
  4. Applied rewrites100.0%

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

Alternative 2: 97.5% accurate, 4.8× speedup?

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

\\
\frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0003968253968253968, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.002777777777777778, 0.08333333333333333\right) \cdot x, x, 1\right), x \cdot x, 2\right)}
\end{array}
Derivation
  1. Initial program 9.8%

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

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right)}}{e^{x} + e^{-x}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
    2. lower-*.f64N/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
  5. Applied rewrites97.1%

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}}{e^{x} + e^{-x}} \]
  6. Taylor expanded in x around 0

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right)}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) + \color{blue}{2}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) \cdot {x}^{2} + 2} \]
    3. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right), \color{blue}{{x}^{2}}, 2\right)} \]
    4. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left({x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) + 1, {\color{blue}{x}}^{2}, 2\right)} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) \cdot {x}^{2} + 1, {x}^{2}, 2\right)} \]
    6. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}, {x}^{2}, 1\right), {\color{blue}{x}}^{2}, 2\right)} \]
    7. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360} \cdot {x}^{2} + \frac{1}{12}, {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    8. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, {x}^{2}, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    9. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    10. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    11. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    12. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    13. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
    14. lift-*.f6497.2

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
  8. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)}} \]
  9. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot \color{blue}{x}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  10. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{2}, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0003968253968253968, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  11. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    2. lift-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1, \color{blue}{x} \cdot x, 2\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1, x \cdot x, 2\right)} \]
    4. lift-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1, x \cdot x, 2\right)} \]
    5. associate-*r*N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot x\right) \cdot x + 1, x \cdot x, 2\right)} \]
    6. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot x, x, 1\right), \color{blue}{x} \cdot x, 2\right)} \]
    7. lower-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot x, x, 1\right), x \cdot x, 2\right)} \]
    8. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \frac{1}{360} + \frac{1}{12}\right) \cdot x, x, 1\right), x \cdot x, 2\right)} \]
    9. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{2520}, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{360}, \frac{1}{12}\right) \cdot x, x, 1\right), x \cdot x, 2\right)} \]
    10. lift-*.f6497.2

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0003968253968253968, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.002777777777777778, 0.08333333333333333\right) \cdot x, x, 1\right), x \cdot x, 2\right)} \]
  12. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0003968253968253968, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.002777777777777778, 0.08333333333333333\right) \cdot x, x, 1\right), \color{blue}{x} \cdot x, 2\right)} \]
  13. Add Preprocessing

Alternative 3: 97.5% accurate, 5.1× speedup?

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

\\
\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.002777777777777778, 0.08333333333333333\right), x \cdot x, 1\right) \cdot x, x, 2\right)}
\end{array}
Derivation
  1. Initial program 9.8%

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

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right)}}{e^{x} + e^{-x}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
    2. lower-*.f64N/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
  5. Applied rewrites97.1%

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}}{e^{x} + e^{-x}} \]
  6. Taylor expanded in x around 0

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right)}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) + \color{blue}{2}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) \cdot {x}^{2} + 2} \]
    3. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right), \color{blue}{{x}^{2}}, 2\right)} \]
    4. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left({x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) + 1, {\color{blue}{x}}^{2}, 2\right)} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) \cdot {x}^{2} + 1, {x}^{2}, 2\right)} \]
    6. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}, {x}^{2}, 1\right), {\color{blue}{x}}^{2}, 2\right)} \]
    7. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360} \cdot {x}^{2} + \frac{1}{12}, {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    8. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, {x}^{2}, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    9. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    10. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    11. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    12. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    13. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
    14. lift-*.f6497.2

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
  8. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)}} \]
  9. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
    2. lift-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right) \cdot \left(x \cdot x\right) + \color{blue}{2}} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right) \cdot \left(x \cdot x\right) + 2} \]
    4. lift-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1\right) \cdot \left(x \cdot x\right) + 2} \]
    5. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1\right) \cdot \left(x \cdot x\right) + 2} \]
    6. lift-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1\right) \cdot \left(x \cdot x\right) + 2} \]
    7. associate-*r*N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1\right) \cdot x\right) \cdot x + 2} \]
    8. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1\right) \cdot x, \color{blue}{x}, 2\right)} \]
    9. lower-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}\right) \cdot \left(x \cdot x\right) + 1\right) \cdot x, x, 2\right)} \]
    10. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360} \cdot \left(x \cdot x\right) + \frac{1}{12}, x \cdot x, 1\right) \cdot x, x, 2\right)} \]
    11. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{1}{360} + \frac{1}{12}, x \cdot x, 1\right) \cdot x, x, 2\right)} \]
    12. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{360}, \frac{1}{12}\right), x \cdot x, 1\right) \cdot x, x, 2\right)} \]
    13. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{360}, \frac{1}{12}\right), x \cdot x, 1\right) \cdot x, x, 2\right)} \]
    14. lift-*.f6497.2

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.002777777777777778, 0.08333333333333333\right), x \cdot x, 1\right) \cdot x, x, 2\right)} \]
  10. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.002777777777777778, 0.08333333333333333\right), x \cdot x, 1\right) \cdot x, \color{blue}{x}, 2\right)} \]
  11. Add Preprocessing

Alternative 4: 97.4% accurate, 5.5× speedup?

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

\\
\frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(x \cdot x, 0.016666666666666666, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)}
\end{array}
Derivation
  1. Initial program 9.8%

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

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right)}}{e^{x} + e^{-x}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
    2. lower-*.f64N/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
  5. Applied rewrites97.1%

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}}{e^{x} + e^{-x}} \]
  6. Taylor expanded in x around 0

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right)}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) + \color{blue}{2}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) \cdot {x}^{2} + 2} \]
    3. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right), \color{blue}{{x}^{2}}, 2\right)} \]
    4. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left({x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) + 1, {\color{blue}{x}}^{2}, 2\right)} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) \cdot {x}^{2} + 1, {x}^{2}, 2\right)} \]
    6. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}, {x}^{2}, 1\right), {\color{blue}{x}}^{2}, 2\right)} \]
    7. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360} \cdot {x}^{2} + \frac{1}{12}, {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    8. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, {x}^{2}, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    9. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    10. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    11. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    12. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    13. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
    14. lift-*.f6497.2

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
  8. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)}} \]
  9. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot \color{blue}{x}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  10. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(x, \color{blue}{2}, \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0003968253968253968, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  11. Taylor expanded in x around 0

    \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\left(\frac{1}{3} + \frac{1}{60} \cdot {x}^{2}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  12. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\left(\frac{1}{3} + \frac{1}{60} \cdot {x}^{2}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\left(\frac{1}{3} + \frac{1}{60} \cdot {x}^{2}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    3. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\left(\frac{1}{3} + \frac{1}{60} \cdot {x}^{2}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    4. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\left(\frac{1}{60} \cdot {x}^{2} + \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    5. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\left(\frac{1}{60} \cdot \left(x \cdot x\right) + \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    6. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\left(\left(x \cdot x\right) \cdot \frac{1}{60} + \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    7. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(x \cdot x, \frac{1}{60}, \frac{1}{3}\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    8. lift-*.f6497.1

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(x \cdot x, 0.016666666666666666, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  13. Applied rewrites97.1%

    \[\leadsto \frac{\mathsf{fma}\left(x, 2, \left(\left(\mathsf{fma}\left(x \cdot x, 0.016666666666666666, 0.3333333333333333\right) \cdot x\right) \cdot x\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  14. Add Preprocessing

Alternative 5: 97.4% accurate, 5.9× speedup?

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

\\
\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.016666666666666666, x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)}
\end{array}
Derivation
  1. Initial program 9.8%

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

    \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right)}}{e^{x} + e^{-x}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
    2. lower-*.f64N/A

      \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
  5. Applied rewrites97.1%

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}}{e^{x} + e^{-x}} \]
  6. Taylor expanded in x around 0

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right)}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) + \color{blue}{2}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) \cdot {x}^{2} + 2} \]
    3. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right), \color{blue}{{x}^{2}}, 2\right)} \]
    4. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left({x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) + 1, {\color{blue}{x}}^{2}, 2\right)} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) \cdot {x}^{2} + 1, {x}^{2}, 2\right)} \]
    6. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}, {x}^{2}, 1\right), {\color{blue}{x}}^{2}, 2\right)} \]
    7. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360} \cdot {x}^{2} + \frac{1}{12}, {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    8. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, {x}^{2}, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    9. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    10. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
    11. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    12. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
    13. pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
    14. lift-*.f6497.2

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
  8. Applied rewrites97.2%

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)}} \]
  9. Taylor expanded in x around 0

    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
  10. Step-by-step derivation
    1. Applied rewrites97.0%

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.016666666666666666, x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    2. Add Preprocessing

    Alternative 6: 97.4% accurate, 6.9× speedup?

    \[\begin{array}{l} \\ \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.016666666666666666, x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.08333333333333333, 1\right), x \cdot x, 2\right)} \end{array} \]
    (FPCore (x)
     :precision binary64
     (/
      (* (fma (fma 0.016666666666666666 (* x x) 0.3333333333333333) (* x x) 2.0) x)
      (fma (fma (* x x) 0.08333333333333333 1.0) (* x x) 2.0)))
    double code(double x) {
    	return (fma(fma(0.016666666666666666, (x * x), 0.3333333333333333), (x * x), 2.0) * x) / fma(fma((x * x), 0.08333333333333333, 1.0), (x * x), 2.0);
    }
    
    function code(x)
    	return Float64(Float64(fma(fma(0.016666666666666666, Float64(x * x), 0.3333333333333333), Float64(x * x), 2.0) * x) / fma(fma(Float64(x * x), 0.08333333333333333, 1.0), Float64(x * x), 2.0))
    end
    
    code[x_] := N[(N[(N[(N[(0.016666666666666666 * N[(x * x), $MachinePrecision] + 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] * x), $MachinePrecision] / N[(N[(N[(x * x), $MachinePrecision] * 0.08333333333333333 + 1.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.016666666666666666, x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.08333333333333333, 1\right), x \cdot x, 2\right)}
    \end{array}
    
    Derivation
    1. Initial program 9.8%

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

      \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right)}}{e^{x} + e^{-x}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
    5. Applied rewrites97.1%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}}{e^{x} + e^{-x}} \]
    6. Taylor expanded in x around 0

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\color{blue}{2 + {x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right)}} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) + \color{blue}{2}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right)\right) \cdot {x}^{2} + 2} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(1 + {x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right), \color{blue}{{x}^{2}}, 2\right)} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left({x}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) + 1, {\color{blue}{x}}^{2}, 2\right)} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}\right) \cdot {x}^{2} + 1, {x}^{2}, 2\right)} \]
      6. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{12} + \frac{1}{360} \cdot {x}^{2}, {x}^{2}, 1\right), {\color{blue}{x}}^{2}, 2\right)} \]
      7. +-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360} \cdot {x}^{2} + \frac{1}{12}, {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, {x}^{2}, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
      9. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
      10. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), {x}^{2}, 1\right), {x}^{2}, 2\right)} \]
      11. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
      12. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), {x}^{2}, 2\right)} \]
      13. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
      14. lift-*.f6497.2

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
    8. Applied rewrites97.2%

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)}} \]
    9. Taylor expanded in x around 0

      \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{360}, x \cdot x, \frac{1}{12}\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
    10. Step-by-step derivation
      1. Applied rewrites97.0%

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.016666666666666666, x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.002777777777777778, x \cdot x, 0.08333333333333333\right), x \cdot x, 1\right), x \cdot x, 2\right)} \]
      2. Taylor expanded in x around 0

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\color{blue}{2 + {x}^{2} \cdot \left(1 + \frac{1}{12} \cdot {x}^{2}\right)}} \]
      3. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{{x}^{2} \cdot \left(1 + \frac{1}{12} \cdot {x}^{2}\right) + \color{blue}{2}} \]
        2. pow2N/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(x \cdot x\right) \cdot \left(1 + \frac{1}{12} \cdot {x}^{2}\right) + 2} \]
        3. *-commutativeN/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\left(1 + \frac{1}{12} \cdot {x}^{2}\right) \cdot \left(x \cdot x\right) + 2} \]
        4. lower-fma.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(1 + \frac{1}{12} \cdot {x}^{2}, \color{blue}{x \cdot x}, 2\right)} \]
        5. +-commutativeN/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\frac{1}{12} \cdot {x}^{2} + 1, \color{blue}{x} \cdot x, 2\right)} \]
        6. pow2N/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\frac{1}{12} \cdot \left(x \cdot x\right) + 1, x \cdot x, 2\right)} \]
        7. *-commutativeN/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{1}{12} + 1, x \cdot x, 2\right)} \]
        8. lower-fma.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{12}, 1\right), \color{blue}{x} \cdot x, 2\right)} \]
        9. lift-*.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{60}, x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \frac{1}{12}, 1\right), x \cdot x, 2\right)} \]
        10. lift-*.f6497.0

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.016666666666666666, x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.08333333333333333, 1\right), x \cdot \color{blue}{x}, 2\right)} \]
      4. Applied rewrites97.0%

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(0.016666666666666666, x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.08333333333333333, 1\right), x \cdot x, 2\right)}} \]
      5. Add Preprocessing

      Alternative 7: 97.2% accurate, 12.4× speedup?

      \[\begin{array}{l} \\ \frac{\mathsf{fma}\left(x \cdot x, 0.3333333333333333, 2\right) \cdot x}{\mathsf{fma}\left(x, x, 2\right)} \end{array} \]
      (FPCore (x)
       :precision binary64
       (/ (* (fma (* x x) 0.3333333333333333 2.0) x) (fma x x 2.0)))
      double code(double x) {
      	return (fma((x * x), 0.3333333333333333, 2.0) * x) / fma(x, x, 2.0);
      }
      
      function code(x)
      	return Float64(Float64(fma(Float64(x * x), 0.3333333333333333, 2.0) * x) / fma(x, x, 2.0))
      end
      
      code[x_] := N[(N[(N[(N[(x * x), $MachinePrecision] * 0.3333333333333333 + 2.0), $MachinePrecision] * x), $MachinePrecision] / N[(x * x + 2.0), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{\mathsf{fma}\left(x \cdot x, 0.3333333333333333, 2\right) \cdot x}{\mathsf{fma}\left(x, x, 2\right)}
      \end{array}
      
      Derivation
      1. Initial program 9.8%

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

        \[\leadsto \frac{\color{blue}{x \cdot \left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right)}}{e^{x} + e^{-x}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
        2. lower-*.f64N/A

          \[\leadsto \frac{\left(2 + {x}^{2} \cdot \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {x}^{2}\right)\right)\right) \cdot \color{blue}{x}}{e^{x} + e^{-x}} \]
      5. Applied rewrites97.1%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}}{e^{x} + e^{-x}} \]
      6. Taylor expanded in x around 0

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{\color{blue}{2 + {x}^{2}}} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{{x}^{2} + \color{blue}{2}} \]
        2. pow2N/A

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2520}, x \cdot x, \frac{1}{60}\right), x \cdot x, \frac{1}{3}\right), x \cdot x, 2\right) \cdot x}{x \cdot x + 2} \]
        3. lower-fma.f6496.6

          \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\mathsf{fma}\left(x, \color{blue}{x}, 2\right)} \]
      8. Applied rewrites96.6%

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0003968253968253968, x \cdot x, 0.016666666666666666\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 2\right) \cdot x}{\color{blue}{\mathsf{fma}\left(x, x, 2\right)}} \]
      9. Taylor expanded in x around 0

        \[\leadsto \frac{\color{blue}{x \cdot \left(2 + \frac{1}{3} \cdot {x}^{2}\right)}}{\mathsf{fma}\left(x, x, 2\right)} \]
      10. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{\left(2 + \frac{1}{3} \cdot {x}^{2}\right) \cdot \color{blue}{x}}{\mathsf{fma}\left(x, x, 2\right)} \]
        2. lower-*.f64N/A

          \[\leadsto \frac{\left(2 + \frac{1}{3} \cdot {x}^{2}\right) \cdot \color{blue}{x}}{\mathsf{fma}\left(x, x, 2\right)} \]
        3. +-commutativeN/A

          \[\leadsto \frac{\left(\frac{1}{3} \cdot {x}^{2} + 2\right) \cdot x}{\mathsf{fma}\left(x, x, 2\right)} \]
        4. pow2N/A

          \[\leadsto \frac{\left(\frac{1}{3} \cdot \left(x \cdot x\right) + 2\right) \cdot x}{\mathsf{fma}\left(x, x, 2\right)} \]
        5. *-commutativeN/A

          \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot \frac{1}{3} + 2\right) \cdot x}{\mathsf{fma}\left(x, x, 2\right)} \]
        6. lower-fma.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, \frac{1}{3}, 2\right) \cdot x}{\mathsf{fma}\left(x, x, 2\right)} \]
        7. lift-*.f6496.7

          \[\leadsto \frac{\mathsf{fma}\left(x \cdot x, 0.3333333333333333, 2\right) \cdot x}{\mathsf{fma}\left(x, x, 2\right)} \]
      11. Applied rewrites96.7%

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

      Alternative 8: 97.2% accurate, 14.1× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x \end{array} \]
      (FPCore (x)
       :precision binary64
       (*
        (fma (- (* 0.13333333333333333 (* x x)) 0.3333333333333333) (* x x) 1.0)
        x))
      double code(double x) {
      	return fma(((0.13333333333333333 * (x * x)) - 0.3333333333333333), (x * x), 1.0) * x;
      }
      
      function code(x)
      	return Float64(fma(Float64(Float64(0.13333333333333333 * Float64(x * x)) - 0.3333333333333333), Float64(x * x), 1.0) * x)
      end
      
      code[x_] := N[(N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x
      \end{array}
      
      Derivation
      1. Initial program 9.8%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}} \]
        2. lift--.f64N/A

          \[\leadsto \frac{\color{blue}{e^{x} - e^{-x}}}{e^{x} + e^{-x}} \]
        3. lift-exp.f64N/A

          \[\leadsto \frac{\color{blue}{e^{x}} - e^{-x}}{e^{x} + e^{-x}} \]
        4. lift-neg.f64N/A

          \[\leadsto \frac{e^{x} - e^{\color{blue}{\mathsf{neg}\left(x\right)}}}{e^{x} + e^{-x}} \]
        5. lift-exp.f64N/A

          \[\leadsto \frac{e^{x} - \color{blue}{e^{\mathsf{neg}\left(x\right)}}}{e^{x} + e^{-x}} \]
        6. lift-+.f64N/A

          \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{\color{blue}{e^{x} + e^{-x}}} \]
        7. lift-exp.f64N/A

          \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{\color{blue}{e^{x}} + e^{-x}} \]
        8. lift-neg.f64N/A

          \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{e^{x} + e^{\color{blue}{\mathsf{neg}\left(x\right)}}} \]
        9. lift-exp.f64N/A

          \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{e^{x} + \color{blue}{e^{\mathsf{neg}\left(x\right)}}} \]
        10. tanh-undefN/A

          \[\leadsto \color{blue}{\tanh x} \]
        11. lower-tanh.f64100.0

          \[\leadsto \color{blue}{\tanh x} \]
      4. Applied rewrites100.0%

        \[\leadsto \color{blue}{\tanh x} \]
      5. Taylor expanded in x around 0

        \[\leadsto \color{blue}{x \cdot \left(1 + {x}^{2} \cdot \left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}\right)\right)} \]
      6. Step-by-step derivation
        1. tanh-undefN/A

          \[\leadsto \color{blue}{x} \cdot \left(1 + {x}^{2} \cdot \left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}\right)\right) \]
        2. *-commutativeN/A

          \[\leadsto \left(1 + {x}^{2} \cdot \left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}\right)\right) \cdot \color{blue}{x} \]
        3. lower-*.f64N/A

          \[\leadsto \left(1 + {x}^{2} \cdot \left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}\right)\right) \cdot \color{blue}{x} \]
        4. +-commutativeN/A

          \[\leadsto \left({x}^{2} \cdot \left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}\right) + 1\right) \cdot x \]
        5. *-commutativeN/A

          \[\leadsto \left(\left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}\right) \cdot {x}^{2} + 1\right) \cdot x \]
        6. lower-fma.f64N/A

          \[\leadsto \mathsf{fma}\left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}, {x}^{2}, 1\right) \cdot x \]
        7. lower--.f64N/A

          \[\leadsto \mathsf{fma}\left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}, {x}^{2}, 1\right) \cdot x \]
        8. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\frac{2}{15} \cdot {x}^{2} - \frac{1}{3}, {x}^{2}, 1\right) \cdot x \]
        9. pow2N/A

          \[\leadsto \mathsf{fma}\left(\frac{2}{15} \cdot \left(x \cdot x\right) - \frac{1}{3}, {x}^{2}, 1\right) \cdot x \]
        10. lift-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\frac{2}{15} \cdot \left(x \cdot x\right) - \frac{1}{3}, {x}^{2}, 1\right) \cdot x \]
        11. pow2N/A

          \[\leadsto \mathsf{fma}\left(\frac{2}{15} \cdot \left(x \cdot x\right) - \frac{1}{3}, x \cdot x, 1\right) \cdot x \]
        12. lift-*.f6496.7

          \[\leadsto \mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x \]
      7. Applied rewrites96.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.13333333333333333 \cdot \left(x \cdot x\right) - 0.3333333333333333, x \cdot x, 1\right) \cdot x} \]
      8. Add Preprocessing

      Alternative 9: 96.8% accurate, 24.8× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, -0.3333333333333333, x\right) \end{array} \]
      (FPCore (x) :precision binary64 (fma (* (* x x) x) -0.3333333333333333 x))
      double code(double x) {
      	return fma(((x * x) * x), -0.3333333333333333, x);
      }
      
      function code(x)
      	return fma(Float64(Float64(x * x) * x), -0.3333333333333333, x)
      end
      
      code[x_] := N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * -0.3333333333333333 + x), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, -0.3333333333333333, x\right)
      \end{array}
      
      Derivation
      1. Initial program 9.8%

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

        \[\leadsto \color{blue}{x \cdot \left(1 + \frac{-1}{3} \cdot {x}^{2}\right)} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto x \cdot \left(\frac{-1}{3} \cdot {x}^{2} + \color{blue}{1}\right) \]
        2. distribute-rgt-inN/A

          \[\leadsto \left(\frac{-1}{3} \cdot {x}^{2}\right) \cdot x + \color{blue}{1 \cdot x} \]
        3. *-commutativeN/A

          \[\leadsto x \cdot \left(\frac{-1}{3} \cdot {x}^{2}\right) + \color{blue}{1} \cdot x \]
        4. *-commutativeN/A

          \[\leadsto x \cdot \left({x}^{2} \cdot \frac{-1}{3}\right) + 1 \cdot x \]
        5. associate-*r*N/A

          \[\leadsto \left(x \cdot {x}^{2}\right) \cdot \frac{-1}{3} + \color{blue}{1} \cdot x \]
        6. unpow2N/A

          \[\leadsto \left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{-1}{3} + 1 \cdot x \]
        7. cube-multN/A

          \[\leadsto {x}^{3} \cdot \frac{-1}{3} + 1 \cdot x \]
        8. *-lft-identityN/A

          \[\leadsto {x}^{3} \cdot \frac{-1}{3} + x \]
        9. lower-fma.f64N/A

          \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{\frac{-1}{3}}, x\right) \]
        10. lower-pow.f6496.3

          \[\leadsto \mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right) \]
      5. Applied rewrites96.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right)} \]
      6. Step-by-step derivation
        1. lift-pow.f64N/A

          \[\leadsto \mathsf{fma}\left({x}^{3}, \frac{-1}{3}, x\right) \]
        2. unpow3N/A

          \[\leadsto \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{3}, x\right) \]
        3. pow2N/A

          \[\leadsto \mathsf{fma}\left({x}^{2} \cdot x, \frac{-1}{3}, x\right) \]
        4. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left({x}^{2} \cdot x, \frac{-1}{3}, x\right) \]
        5. pow2N/A

          \[\leadsto \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{3}, x\right) \]
        6. lift-*.f6496.3

          \[\leadsto \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, -0.3333333333333333, x\right) \]
      7. Applied rewrites96.3%

        \[\leadsto \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, -0.3333333333333333, x\right) \]
      8. Add Preprocessing

      Alternative 10: 96.7% accurate, 422.0× speedup?

      \[\begin{array}{l} \\ x \end{array} \]
      (FPCore (x) :precision binary64 x)
      double code(double x) {
      	return x;
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(x)
      use fmin_fmax_functions
          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.8%

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

        \[\leadsto \color{blue}{x} \]
      4. Step-by-step derivation
        1. Applied rewrites96.2%

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

        Reproduce

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