Asymptote C

Percentage Accurate: 53.2% → 99.7%
Time: 3.0s
Alternatives: 10
Speedup: 0.7×

Specification

?
\[\begin{array}{l} \\ \frac{x}{x + 1} - \frac{x + 1}{x - 1} \end{array} \]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.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
    code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x):
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x)
	return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0)))
end
function tmp = code(x)
	tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}

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: 53.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x}{x + 1} - \frac{x + 1}{x - 1} \end{array} \]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.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
    code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x):
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x)
	return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0)))
end
function tmp = code(x)
	tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}

Alternative 1: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - -1}\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ (- (* -1.0 (/ (+ 1.0 (* 3.0 (/ 1.0 x))) x)) 3.0) x)
   (fma (/ -1.0 (- x 1.0)) (- x -1.0) (/ x (- x -1.0)))))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = ((-1.0 * ((1.0 + (3.0 * (1.0 / x))) / x)) - 3.0) / x;
	} else {
		tmp = fma((-1.0 / (x - 1.0)), (x - -1.0), (x / (x - -1.0)));
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(Float64(Float64(-1.0 * Float64(Float64(1.0 + Float64(3.0 * Float64(1.0 / x))) / x)) - 3.0) / x);
	else
		tmp = fma(Float64(-1.0 / Float64(x - 1.0)), Float64(x - -1.0), Float64(x / Float64(x - -1.0)));
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[(N[(-1.0 * N[(N[(1.0 + N[(3.0 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(-1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision] * N[(x - -1.0), $MachinePrecision] + N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - -1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{\color{blue}{x}} \]
      2. lower--.f64N/A

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

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

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

        \[\leadsto \frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x} \]
      6. lower-*.f64N/A

        \[\leadsto \frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x} \]
      7. lower-/.f6451.8

        \[\leadsto \frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x} \]
    4. Applied rewrites51.8%

      \[\leadsto \color{blue}{\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

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

        \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{x + 1}{x - 1}}\right)\right) + \frac{x}{x + 1} \]
      5. distribute-neg-frac2N/A

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

        \[\leadsto \frac{x + 1}{\mathsf{neg}\left(\left(x - 1\right)\right)} + \color{blue}{\frac{x}{x + 1}} \]
      7. mult-flipN/A

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

        \[\leadsto \left(x + 1\right) \cdot \frac{1}{\mathsf{neg}\left(\left(x - 1\right)\right)} + \color{blue}{\frac{x}{x + 1}} \]
      9. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{1}{\mathsf{neg}\left(\left(x - 1\right)\right)} \cdot \left(x + 1\right)} + \frac{x}{x + 1} \]
      10. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\mathsf{neg}\left(\left(x - 1\right)\right)}, x + 1, \frac{x}{x + 1}\right)} \]
      11. distribute-neg-frac2N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(\frac{1}{x - 1}\right)}, x + 1, \frac{x}{x + 1}\right) \]
      12. distribute-neg-fracN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\mathsf{neg}\left(1\right)}{x - 1}}, x + 1, \frac{x}{x + 1}\right) \]
      13. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\mathsf{neg}\left(1\right)}{x - 1}}, x + 1, \frac{x}{x + 1}\right) \]
      14. metadata-eval52.5

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{-1}}{x - 1}, x + 1, \frac{x}{x + 1}\right) \]
      15. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, \color{blue}{x + 1}, \frac{x}{x + 1}\right) \]
      16. add-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, \color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}, \frac{x}{x + 1}\right) \]
      17. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, \color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}, \frac{x}{x + 1}\right) \]
      18. metadata-eval52.5

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - \color{blue}{-1}, \frac{x}{x + 1}\right) \]
      19. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{\color{blue}{x + 1}}\right) \]
      20. add-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{\color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
      21. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{\color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
      22. metadata-eval52.5

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - \color{blue}{-1}}\right) \]
    3. Applied rewrites52.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - -1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - -1}\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ (- -3.0 (/ 1.0 x)) x)
   (fma (/ -1.0 (- x 1.0)) (- x -1.0) (/ x (- x -1.0)))))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = (-3.0 - (1.0 / x)) / x;
	} else {
		tmp = fma((-1.0 / (x - 1.0)), (x - -1.0), (x / (x - -1.0)));
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(Float64(-3.0 - Float64(1.0 / x)) / x);
	else
		tmp = fma(Float64(-1.0 / Float64(x - 1.0)), Float64(x - -1.0), Float64(x / Float64(x - -1.0)));
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[(-3.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(-1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision] * N[(x - -1.0), $MachinePrecision] + N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - -1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. lower-/.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{\color{blue}{x}} \]
      3. lower-+.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
      4. lower-/.f6450.9

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
    4. Applied rewrites50.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{\color{blue}{x}} \]
      5. lower-/.f64N/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{x} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) + \left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}{x} \]
      8. sub-flip-reverseN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      10. metadata-eval50.9

        \[\leadsto \frac{-3 - \frac{1}{x}}{x} \]
    6. Applied rewrites50.9%

      \[\leadsto \frac{-3 - \frac{1}{x}}{\color{blue}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

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

        \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{x + 1}{x - 1}}\right)\right) + \frac{x}{x + 1} \]
      5. distribute-neg-frac2N/A

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

        \[\leadsto \frac{x + 1}{\mathsf{neg}\left(\left(x - 1\right)\right)} + \color{blue}{\frac{x}{x + 1}} \]
      7. mult-flipN/A

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

        \[\leadsto \left(x + 1\right) \cdot \frac{1}{\mathsf{neg}\left(\left(x - 1\right)\right)} + \color{blue}{\frac{x}{x + 1}} \]
      9. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{1}{\mathsf{neg}\left(\left(x - 1\right)\right)} \cdot \left(x + 1\right)} + \frac{x}{x + 1} \]
      10. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\mathsf{neg}\left(\left(x - 1\right)\right)}, x + 1, \frac{x}{x + 1}\right)} \]
      11. distribute-neg-frac2N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(\frac{1}{x - 1}\right)}, x + 1, \frac{x}{x + 1}\right) \]
      12. distribute-neg-fracN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\mathsf{neg}\left(1\right)}{x - 1}}, x + 1, \frac{x}{x + 1}\right) \]
      13. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\mathsf{neg}\left(1\right)}{x - 1}}, x + 1, \frac{x}{x + 1}\right) \]
      14. metadata-eval52.5

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{-1}}{x - 1}, x + 1, \frac{x}{x + 1}\right) \]
      15. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, \color{blue}{x + 1}, \frac{x}{x + 1}\right) \]
      16. add-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, \color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}, \frac{x}{x + 1}\right) \]
      17. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, \color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}, \frac{x}{x + 1}\right) \]
      18. metadata-eval52.5

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - \color{blue}{-1}, \frac{x}{x + 1}\right) \]
      19. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{\color{blue}{x + 1}}\right) \]
      20. add-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{\color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
      21. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{\color{blue}{x - \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
      22. metadata-eval52.5

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - \color{blue}{-1}}\right) \]
    3. Applied rewrites52.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{x - -1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 99.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(3, x, 1\right), x, 3\right), x, 1\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ (- -3.0 (/ 1.0 x)) x)
   (fma (fma (fma 3.0 x 1.0) x 3.0) x 1.0)))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = (-3.0 - (1.0 / x)) / x;
	} else {
		tmp = fma(fma(fma(3.0, x, 1.0), x, 3.0), x, 1.0);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(Float64(-3.0 - Float64(1.0 / x)) / x);
	else
		tmp = fma(fma(fma(3.0, x, 1.0), x, 3.0), x, 1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[(-3.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(3.0 * x + 1.0), $MachinePrecision] * x + 3.0), $MachinePrecision] * x + 1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(3, x, 1\right), x, 3\right), x, 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. lower-/.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{\color{blue}{x}} \]
      3. lower-+.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
      4. lower-/.f6450.9

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
    4. Applied rewrites50.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{\color{blue}{x}} \]
      5. lower-/.f64N/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{x} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) + \left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}{x} \]
      8. sub-flip-reverseN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      10. metadata-eval50.9

        \[\leadsto \frac{-3 - \frac{1}{x}}{x} \]
    6. Applied rewrites50.9%

      \[\leadsto \frac{-3 - \frac{1}{x}}{\color{blue}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

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

        \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{\frac{x}{x + 1}} \]
      5. mult-flipN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{x \cdot \frac{1}{x + 1}} \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1}} \]
      7. lower--.f64N/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{x + 1}{x - 1}}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      9. distribute-neg-fracN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      10. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      11. lift-+.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      12. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      13. sub-negateN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      14. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      15. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{-1} - x}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      16. mult-flip-revN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{\mathsf{neg}\left(x\right)}{x + 1}} \]
      17. distribute-neg-fracN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\left(\mathsf{neg}\left(\frac{x}{x + 1}\right)\right)} \]
      18. distribute-neg-frac2N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{x}{\mathsf{neg}\left(\left(x + 1\right)\right)}} \]
      19. lower-/.f64N/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)} \]
      21. add-flipN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
      22. sub-negateN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      23. lower--.f64N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      24. metadata-eval53.2

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1} - x} \]
    3. Applied rewrites53.2%

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    5. Step-by-step derivation
      1. lower-+.f64N/A

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

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

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

        \[\leadsto 1 + x \cdot \left(3 + x \cdot \color{blue}{\left(1 + 3 \cdot x\right)}\right) \]
      5. lower-+.f64N/A

        \[\leadsto 1 + x \cdot \left(3 + x \cdot \left(1 + \color{blue}{3 \cdot x}\right)\right) \]
      6. lower-*.f6449.4

        \[\leadsto 1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot \color{blue}{x}\right)\right) \]
    6. Applied rewrites49.4%

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    7. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) + \color{blue}{1} \]
      3. lift-*.f64N/A

        \[\leadsto x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) + 1 \]
      4. *-commutativeN/A

        \[\leadsto \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) \cdot x + 1 \]
      5. *-rgt-identityN/A

        \[\leadsto \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) \cdot \left(x \cdot 1\right) + 1 \]
      6. associate-*r*N/A

        \[\leadsto \left(\left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) \cdot x\right) \cdot 1 + 1 \]
      7. *-commutativeN/A

        \[\leadsto \left(x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)\right) \cdot 1 + 1 \]
      8. lift-*.f64N/A

        \[\leadsto \left(x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)\right) \cdot 1 + 1 \]
      9. lift-*.f64N/A

        \[\leadsto \left(x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)\right) \cdot 1 + 1 \]
      10. *-commutativeN/A

        \[\leadsto \left(\left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) \cdot x\right) \cdot 1 + 1 \]
      11. associate-*r*N/A

        \[\leadsto \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) \cdot \left(x \cdot 1\right) + 1 \]
      12. *-rgt-identityN/A

        \[\leadsto \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right) \cdot x + 1 \]
      13. lower-fma.f6449.4

        \[\leadsto \mathsf{fma}\left(3 + x \cdot \left(1 + 3 \cdot x\right), \color{blue}{x}, 1\right) \]
    8. Applied rewrites49.4%

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(3, x, 1\right), x, 3\right), \color{blue}{x}, 1\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 99.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, 1\right) \cdot \mathsf{fma}\left(3, x, 1\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ (- -3.0 (/ 1.0 x)) x)
   (* (fma x x 1.0) (fma 3.0 x 1.0))))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = (-3.0 - (1.0 / x)) / x;
	} else {
		tmp = fma(x, x, 1.0) * fma(3.0, x, 1.0);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(Float64(-3.0 - Float64(1.0 / x)) / x);
	else
		tmp = Float64(fma(x, x, 1.0) * fma(3.0, x, 1.0));
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[(-3.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(x * x + 1.0), $MachinePrecision] * N[(3.0 * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 1\right) \cdot \mathsf{fma}\left(3, x, 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. lower-/.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{\color{blue}{x}} \]
      3. lower-+.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
      4. lower-/.f6450.9

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
    4. Applied rewrites50.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{\color{blue}{x}} \]
      5. lower-/.f64N/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{x} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) + \left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}{x} \]
      8. sub-flip-reverseN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      10. metadata-eval50.9

        \[\leadsto \frac{-3 - \frac{1}{x}}{x} \]
    6. Applied rewrites50.9%

      \[\leadsto \frac{-3 - \frac{1}{x}}{\color{blue}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

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

        \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{\frac{x}{x + 1}} \]
      5. mult-flipN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{x \cdot \frac{1}{x + 1}} \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1}} \]
      7. lower--.f64N/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{x + 1}{x - 1}}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      9. distribute-neg-fracN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      10. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      11. lift-+.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      12. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      13. sub-negateN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      14. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      15. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{-1} - x}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      16. mult-flip-revN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{\mathsf{neg}\left(x\right)}{x + 1}} \]
      17. distribute-neg-fracN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\left(\mathsf{neg}\left(\frac{x}{x + 1}\right)\right)} \]
      18. distribute-neg-frac2N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{x}{\mathsf{neg}\left(\left(x + 1\right)\right)}} \]
      19. lower-/.f64N/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)} \]
      21. add-flipN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
      22. sub-negateN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      23. lower--.f64N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      24. metadata-eval53.2

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1} - x} \]
    3. Applied rewrites53.2%

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    5. Step-by-step derivation
      1. lower-+.f64N/A

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

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

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

        \[\leadsto 1 + x \cdot \left(3 + x \cdot \color{blue}{\left(1 + 3 \cdot x\right)}\right) \]
      5. lower-+.f64N/A

        \[\leadsto 1 + x \cdot \left(3 + x \cdot \left(1 + \color{blue}{3 \cdot x}\right)\right) \]
      6. lower-*.f6449.4

        \[\leadsto 1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot \color{blue}{x}\right)\right) \]
    6. Applied rewrites49.4%

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    7. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto 1 + x \cdot \color{blue}{\left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
      3. lift-+.f64N/A

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

        \[\leadsto 1 + \left(3 \cdot x + \color{blue}{\left(x \cdot \left(1 + 3 \cdot x\right)\right) \cdot x}\right) \]
      5. lift-*.f64N/A

        \[\leadsto 1 + \left(3 \cdot x + \color{blue}{\left(x \cdot \left(1 + 3 \cdot x\right)\right)} \cdot x\right) \]
      6. associate-+r+N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \color{blue}{\left(x \cdot \left(1 + 3 \cdot x\right)\right) \cdot x} \]
      7. lift-+.f64N/A

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

        \[\leadsto \left(1 + 3 \cdot x\right) + x \cdot \color{blue}{\left(x \cdot \left(1 + 3 \cdot x\right)\right)} \]
      9. lift-*.f64N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + x \cdot \left(x \cdot \color{blue}{\left(1 + 3 \cdot x\right)}\right) \]
      10. associate-*r*N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \left(x \cdot x\right) \cdot \color{blue}{\left(1 + 3 \cdot x\right)} \]
      11. distribute-rgt1-inN/A

        \[\leadsto \left(x \cdot x + 1\right) \cdot \color{blue}{\left(1 + 3 \cdot x\right)} \]
      12. lift-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(\color{blue}{1} + 3 \cdot x\right) \]
      13. lower-*.f6449.4

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \color{blue}{\left(1 + 3 \cdot x\right)} \]
      14. lift-+.f64N/A

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

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

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(3 \cdot x + 1\right) \]
      17. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(3 \cdot \left(x \cdot 1\right) + 1\right) \]
      18. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(\left(3 \cdot x\right) \cdot 1 + 1\right) \]
      19. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(\left(3 \cdot x\right) \cdot 1 + 1\right) \]
    8. Applied rewrites49.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, 1\right) \cdot \mathsf{fma}\left(3, x, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 99.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 3, \mathsf{fma}\left(x, x, 1\right)\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ (- -3.0 (/ 1.0 x)) x)
   (fma x 3.0 (fma x x 1.0))))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = (-3.0 - (1.0 / x)) / x;
	} else {
		tmp = fma(x, 3.0, fma(x, x, 1.0));
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(Float64(-3.0 - Float64(1.0 / x)) / x);
	else
		tmp = fma(x, 3.0, fma(x, x, 1.0));
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[(-3.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(x * 3.0 + N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, \mathsf{fma}\left(x, x, 1\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. lower-/.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{\color{blue}{x}} \]
      3. lower-+.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
      4. lower-/.f6450.9

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
    4. Applied rewrites50.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{\color{blue}{x}} \]
      5. lower-/.f64N/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{x} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) + \left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}{x} \]
      8. sub-flip-reverseN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      10. metadata-eval50.9

        \[\leadsto \frac{-3 - \frac{1}{x}}{x} \]
    6. Applied rewrites50.9%

      \[\leadsto \frac{-3 - \frac{1}{x}}{\color{blue}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

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

        \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{\frac{x}{x + 1}} \]
      5. mult-flipN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{x \cdot \frac{1}{x + 1}} \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1}} \]
      7. lower--.f64N/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{x + 1}{x - 1}}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      9. distribute-neg-fracN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      10. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      11. lift-+.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      12. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      13. sub-negateN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      14. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      15. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{-1} - x}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      16. mult-flip-revN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{\mathsf{neg}\left(x\right)}{x + 1}} \]
      17. distribute-neg-fracN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\left(\mathsf{neg}\left(\frac{x}{x + 1}\right)\right)} \]
      18. distribute-neg-frac2N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{x}{\mathsf{neg}\left(\left(x + 1\right)\right)}} \]
      19. lower-/.f64N/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)} \]
      21. add-flipN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
      22. sub-negateN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      23. lower--.f64N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      24. metadata-eval53.2

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1} - x} \]
    3. Applied rewrites53.2%

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]
    5. Step-by-step derivation
      1. lower-+.f64N/A

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

        \[\leadsto 1 + x \cdot \color{blue}{\left(3 + x\right)} \]
      3. lower-+.f6449.8

        \[\leadsto 1 + x \cdot \left(3 + \color{blue}{x}\right) \]
    6. Applied rewrites49.8%

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]
    7. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto x \cdot \left(3 + x\right) + \color{blue}{1} \]
      3. lift-*.f64N/A

        \[\leadsto x \cdot \left(3 + x\right) + 1 \]
      4. lift-+.f64N/A

        \[\leadsto x \cdot \left(3 + x\right) + 1 \]
      5. distribute-lft-inN/A

        \[\leadsto \left(x \cdot 3 + x \cdot x\right) + 1 \]
      6. associate-+l+N/A

        \[\leadsto x \cdot 3 + \color{blue}{\left(x \cdot x + 1\right)} \]
      7. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{3}, x \cdot x + 1\right) \]
      8. lower-fma.f6449.8

        \[\leadsto \mathsf{fma}\left(x, 3, \mathsf{fma}\left(x, x, 1\right)\right) \]
    8. Applied rewrites49.8%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{3}, \mathsf{fma}\left(x, x, 1\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 99.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x - -3, x, 1\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ (- -3.0 (/ 1.0 x)) x)
   (fma (- x -3.0) x 1.0)))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = (-3.0 - (1.0 / x)) / x;
	} else {
		tmp = fma((x - -3.0), x, 1.0);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(Float64(-3.0 - Float64(1.0 / x)) / x);
	else
		tmp = fma(Float64(x - -3.0), x, 1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[(-3.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(x - -3.0), $MachinePrecision] * x + 1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - -3, x, 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. lower-/.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{\color{blue}{x}} \]
      3. lower-+.f64N/A

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
      4. lower-/.f6450.9

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
    4. Applied rewrites50.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{\frac{3 + \frac{1}{x}}{x}} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{neg}\left(\frac{3 + \frac{1}{x}}{x}\right) \]
      4. distribute-neg-fracN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{\color{blue}{x}} \]
      5. lower-/.f64N/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}{x} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) + \left(\mathsf{neg}\left(\frac{1}{x}\right)\right)}{x} \]
      8. sub-flip-reverseN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(3\right)\right) - \frac{1}{x}}{x} \]
      10. metadata-eval50.9

        \[\leadsto \frac{-3 - \frac{1}{x}}{x} \]
    6. Applied rewrites50.9%

      \[\leadsto \frac{-3 - \frac{1}{x}}{\color{blue}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

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

        \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{\frac{x}{x + 1}} \]
      5. mult-flipN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{x \cdot \frac{1}{x + 1}} \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1}} \]
      7. lower--.f64N/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{x + 1}{x - 1}}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      9. distribute-neg-fracN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      10. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      11. lift-+.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      12. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      13. sub-negateN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      14. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      15. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{-1} - x}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      16. mult-flip-revN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{\mathsf{neg}\left(x\right)}{x + 1}} \]
      17. distribute-neg-fracN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\left(\mathsf{neg}\left(\frac{x}{x + 1}\right)\right)} \]
      18. distribute-neg-frac2N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{x}{\mathsf{neg}\left(\left(x + 1\right)\right)}} \]
      19. lower-/.f64N/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)} \]
      21. add-flipN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
      22. sub-negateN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      23. lower--.f64N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      24. metadata-eval53.2

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1} - x} \]
    3. Applied rewrites53.2%

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]
    5. Step-by-step derivation
      1. lower-+.f64N/A

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

        \[\leadsto 1 + x \cdot \color{blue}{\left(3 + x\right)} \]
      3. lower-+.f6449.8

        \[\leadsto 1 + x \cdot \left(3 + \color{blue}{x}\right) \]
    6. Applied rewrites49.8%

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]
    7. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto x \cdot \left(3 + x\right) + \color{blue}{1} \]
      3. lift-*.f64N/A

        \[\leadsto x \cdot \left(3 + x\right) + 1 \]
      4. *-commutativeN/A

        \[\leadsto \left(3 + x\right) \cdot x + 1 \]
      5. lower-fma.f6449.8

        \[\leadsto \mathsf{fma}\left(3 + x, \color{blue}{x}, 1\right) \]
      6. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(3 + x, x, 1\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x + 3, x, 1\right) \]
      8. add-flipN/A

        \[\leadsto \mathsf{fma}\left(x - \left(\mathsf{neg}\left(3\right)\right), x, 1\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(x - -3, x, 1\right) \]
      10. lower--.f6449.8

        \[\leadsto \mathsf{fma}\left(x - -3, x, 1\right) \]
    8. Applied rewrites49.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - -3, x, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 98.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x - -3, x, 1\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ -3.0 x)
   (fma (- x -3.0) x 1.0)))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = -3.0 / x;
	} else {
		tmp = fma((x - -3.0), x, 1.0);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(-3.0 / x);
	else
		tmp = fma(Float64(x - -3.0), x, 1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(-3.0 / x), $MachinePrecision], N[(N[(x - -3.0), $MachinePrecision] * x + 1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - -3, x, 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{-3}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f6451.6

        \[\leadsto \frac{-3}{\color{blue}{x}} \]
    4. Applied rewrites51.6%

      \[\leadsto \color{blue}{\frac{-3}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

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

        \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \]
      2. sub-flipN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{\frac{x}{x + 1}} \]
      5. mult-flipN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) + \color{blue}{x \cdot \frac{1}{x + 1}} \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{x + 1}{x - 1}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1}} \]
      7. lower--.f64N/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{x + 1}{x - 1}}\right)\right) - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      9. distribute-neg-fracN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      10. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + 1\right)\right)}{x - 1}} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      11. lift-+.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      12. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      13. sub-negateN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      14. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      15. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{-1} - x}{x - 1} - \left(\mathsf{neg}\left(x\right)\right) \cdot \frac{1}{x + 1} \]
      16. mult-flip-revN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{\mathsf{neg}\left(x\right)}{x + 1}} \]
      17. distribute-neg-fracN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\left(\mathsf{neg}\left(\frac{x}{x + 1}\right)\right)} \]
      18. distribute-neg-frac2N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \color{blue}{\frac{x}{\mathsf{neg}\left(\left(x + 1\right)\right)}} \]
      19. lower-/.f64N/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x + 1\right)}\right)} \]
      21. add-flipN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
      22. sub-negateN/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      23. lower--.f64N/A

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{\left(\mathsf{neg}\left(1\right)\right) - x}} \]
      24. metadata-eval53.2

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1} - x} \]
    3. Applied rewrites53.2%

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]
    5. Step-by-step derivation
      1. lower-+.f64N/A

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

        \[\leadsto 1 + x \cdot \color{blue}{\left(3 + x\right)} \]
      3. lower-+.f6449.8

        \[\leadsto 1 + x \cdot \left(3 + \color{blue}{x}\right) \]
    6. Applied rewrites49.8%

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]
    7. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto x \cdot \left(3 + x\right) + \color{blue}{1} \]
      3. lift-*.f64N/A

        \[\leadsto x \cdot \left(3 + x\right) + 1 \]
      4. *-commutativeN/A

        \[\leadsto \left(3 + x\right) \cdot x + 1 \]
      5. lower-fma.f6449.8

        \[\leadsto \mathsf{fma}\left(3 + x, \color{blue}{x}, 1\right) \]
      6. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(3 + x, x, 1\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x + 3, x, 1\right) \]
      8. add-flipN/A

        \[\leadsto \mathsf{fma}\left(x - \left(\mathsf{neg}\left(3\right)\right), x, 1\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(x - -3, x, 1\right) \]
      10. lower--.f6449.8

        \[\leadsto \mathsf{fma}\left(x - -3, x, 1\right) \]
    8. Applied rewrites49.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - -3, x, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 98.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 3, 1\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7)
   (/ -3.0 x)
   (fma x 3.0 1.0)))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = -3.0 / x;
	} else {
		tmp = fma(x, 3.0, 1.0);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(-3.0 / x);
	else
		tmp = fma(x, 3.0, 1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(-3.0 / x), $MachinePrecision], N[(x * 3.0 + 1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{-3}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f6451.6

        \[\leadsto \frac{-3}{\color{blue}{x}} \]
    4. Applied rewrites51.6%

      \[\leadsto \color{blue}{\frac{-3}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + 3 \cdot x} \]
    3. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto 1 + \color{blue}{3 \cdot x} \]
      2. lower-*.f6449.4

        \[\leadsto 1 + 3 \cdot \color{blue}{x} \]
    4. Applied rewrites49.4%

      \[\leadsto \color{blue}{1 + 3 \cdot x} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto 1 + \color{blue}{3 \cdot x} \]
      2. +-commutativeN/A

        \[\leadsto 3 \cdot x + \color{blue}{1} \]
      3. add-flipN/A

        \[\leadsto 3 \cdot x - \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
      4. rgt-mult-inverseN/A

        \[\leadsto 3 \cdot x - \left(\mathsf{neg}\left(x \cdot \frac{1}{x}\right)\right) \]
      5. lift-/.f64N/A

        \[\leadsto 3 \cdot x - \left(\mathsf{neg}\left(x \cdot \frac{1}{x}\right)\right) \]
      6. add-flipN/A

        \[\leadsto 3 \cdot x + \color{blue}{x \cdot \frac{1}{x}} \]
      7. lift-*.f64N/A

        \[\leadsto 3 \cdot x + \color{blue}{x} \cdot \frac{1}{x} \]
      8. *-commutativeN/A

        \[\leadsto x \cdot 3 + \color{blue}{x} \cdot \frac{1}{x} \]
      9. distribute-lft-outN/A

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

        \[\leadsto 3 \cdot x + \color{blue}{\frac{1}{x} \cdot x} \]
      11. remove-double-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(3\right)\right)\right)\right) \cdot x + \frac{\color{blue}{1}}{x} \cdot x \]
      12. distribute-lft-neg-outN/A

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

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + \color{blue}{\frac{1}{x}} \cdot x \]
      14. lift-/.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + \frac{1}{x} \cdot x \]
      15. lft-mult-inverseN/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + 1 \]
      16. metadata-evalN/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + {\left(\mathsf{neg}\left(x\right)\right)}^{\color{blue}{0}} \]
      17. metadata-evalN/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + {\left(\mathsf{neg}\left(x\right)\right)}^{\left(-1 + \color{blue}{1}\right)} \]
      18. pow-plusN/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + {\left(\mathsf{neg}\left(x\right)\right)}^{-1} \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \]
      19. inv-powN/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + \frac{1}{\mathsf{neg}\left(x\right)} \cdot \left(\mathsf{neg}\left(\color{blue}{x}\right)\right) \]
      20. distribute-neg-frac2N/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + \left(\mathsf{neg}\left(\frac{1}{x}\right)\right) \cdot \left(\mathsf{neg}\left(\color{blue}{x}\right)\right) \]
      21. lift-/.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(3\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) + \left(\mathsf{neg}\left(\frac{1}{x}\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right) \]
      22. distribute-rgt-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(3\right)\right) \cdot x\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right)} \cdot \left(\mathsf{neg}\left(x\right)\right) \]
      23. distribute-lft-neg-outN/A

        \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(3\right)\right)\right)\right) \cdot x + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right)} \cdot \left(\mathsf{neg}\left(x\right)\right) \]
      24. remove-double-negN/A

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

        \[\leadsto x \cdot 3 + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right)} \cdot \left(\mathsf{neg}\left(x\right)\right) \]
    6. Applied rewrites49.4%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{3}, 1\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 97.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 5e-7) (/ -3.0 x) 1.0))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = -3.0 / x;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
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) :: tmp
    if (((x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))) <= 5d-7) then
        tmp = (-3.0d0) / x
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7) {
		tmp = -3.0 / x;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if ((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7:
		tmp = -3.0 / x
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 5e-7)
		tmp = Float64(-3.0 / x);
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-7)
		tmp = -3.0 / x;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-7], N[(-3.0 / x), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3}{x}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 4.99999999999999977e-7

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{-3}{x}} \]
    3. Step-by-step derivation
      1. lower-/.f6451.6

        \[\leadsto \frac{-3}{\color{blue}{x}} \]
    4. Applied rewrites51.6%

      \[\leadsto \color{blue}{\frac{-3}{x}} \]

    if 4.99999999999999977e-7 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64))))

    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1} \]
    3. Step-by-step derivation
      1. Applied rewrites50.0%

        \[\leadsto \color{blue}{1} \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 10: 50.0% accurate, 18.4× speedup?

    \[\begin{array}{l} \\ 1 \end{array} \]
    (FPCore (x) :precision binary64 1.0)
    double code(double x) {
    	return 1.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
        code = 1.0d0
    end function
    
    public static double code(double x) {
    	return 1.0;
    }
    
    def code(x):
    	return 1.0
    
    function code(x)
    	return 1.0
    end
    
    function tmp = code(x)
    	tmp = 1.0;
    end
    
    code[x_] := 1.0
    
    \begin{array}{l}
    
    \\
    1
    \end{array}
    
    Derivation
    1. Initial program 53.2%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1} \]
    3. Step-by-step derivation
      1. Applied rewrites50.0%

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

      Reproduce

      ?
      herbie shell --seed 2025150 
      (FPCore (x)
        :name "Asymptote C"
        :precision binary64
        (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))