Asymptote C

Percentage Accurate: 54.9% → 99.6%
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: 54.9% 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.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^{-9}:\\ \;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\ \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-9)
   (/ (- (/ 2.0 x) 3.0) (- x 1.0))
   (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-9) {
		tmp = ((2.0 / x) - 3.0) / (x - 1.0);
	} 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-9)
		tmp = Float64(Float64(Float64(2.0 / x) - 3.0) / Float64(x - 1.0));
	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-9], N[(N[(N[(2.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $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^{-9}:\\
\;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\

\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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1 - x}} \]
      4. sub-negate-revN/A

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} + \frac{x}{x + 1}} \]
      9. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \frac{-1 - x}{x - 1}} \]
      10. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x - 1}} \]
      18. sub-to-fractionN/A

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

        \[\leadsto \color{blue}{\frac{\frac{x}{x + 1} \cdot \left(x - 1\right) - \left(x + 1\right)}{x - 1}} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x}{x - -1}, x - 1, -1 - x\right)}{x - 1}} \]
    6. Taylor expanded in x around inf

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

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

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
    8. Applied rewrites50.2%

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      3. mult-flip-revN/A

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

        \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]
    10. Applied rewrites50.2%

      \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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-fracN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{neg}\left(\left(x - 1\right)\right)} \cdot \left(x + 1\right) + \color{blue}{\frac{x}{x + 1}} \]
      16. 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)} \]
      17. 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) \]
      18. 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) \]
      19. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\mathsf{neg}\left(1\right)}{x - 1}}, x + 1, \frac{x}{x + 1}\right) \]
      20. metadata-eval54.3

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

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, \color{blue}{x + 1}, \frac{x}{x + 1}\right) \]
      22. 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) \]
      23. 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) \]
      24. metadata-eval54.3

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

        \[\leadsto \mathsf{fma}\left(\frac{-1}{x - 1}, x - -1, \frac{x}{\color{blue}{x + 1}}\right) \]
      26. 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) \]
      27. 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) \]
      28. metadata-eval54.3

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

      \[\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.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}\\


\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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1 - x}} \]
      4. sub-negate-revN/A

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} + \frac{x}{x + 1}} \]
      9. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \frac{-1 - x}{x - 1}} \]
      10. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x - 1}} \]
      18. sub-to-fractionN/A

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

        \[\leadsto \color{blue}{\frac{\frac{x}{x + 1} \cdot \left(x - 1\right) - \left(x + 1\right)}{x - 1}} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x}{x - -1}, x - 1, -1 - x\right)}{x - 1}} \]
    6. Taylor expanded in x around inf

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

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

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
    8. Applied rewrites50.2%

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      3. mult-flip-revN/A

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

        \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]
    10. Applied rewrites50.2%

      \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 98.9% 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^{-9}:\\ \;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\ \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-9)
   (/ (- (/ 2.0 x) 3.0) (- x 1.0))
   (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-9) {
		tmp = ((2.0 / x) - 3.0) / (x - 1.0);
	} 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-9)
		tmp = Float64(Float64(Float64(2.0 / x) - 3.0) / Float64(x - 1.0));
	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-9], N[(N[(N[(2.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $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^{-9}:\\
\;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\

\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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1 - x}} \]
      4. sub-negate-revN/A

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} + \frac{x}{x + 1}} \]
      9. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \frac{-1 - x}{x - 1}} \]
      10. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x - 1}} \]
      18. sub-to-fractionN/A

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

        \[\leadsto \color{blue}{\frac{\frac{x}{x + 1} \cdot \left(x - 1\right) - \left(x + 1\right)}{x - 1}} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x}{x - -1}, x - 1, -1 - x\right)}{x - 1}} \]
    6. Taylor expanded in x around inf

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

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

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
    8. Applied rewrites50.2%

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      3. mult-flip-revN/A

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

        \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]
    10. Applied rewrites50.2%

      \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1 - x}} \]
      4. sub-negate-revN/A

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} + \frac{x}{x + 1}} \]
      9. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \frac{-1 - x}{x - 1}} \]
      10. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x - 1}} \]
      18. sub-to-fractionN/A

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

        \[\leadsto \color{blue}{\frac{\frac{x}{x + 1} \cdot \left(x - 1\right) - \left(x + 1\right)}{x - 1}} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x}{x - -1}, x - 1, -1 - x\right)}{x - 1}} \]
    6. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    7. 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-*.f6451.4

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

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    9. 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. lower-fma.f6451.4

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left(1 + 3 \cdot x\right) \cdot x + 3, x, 1\right) \]
      10. lower-fma.f6451.4

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(3 \cdot x + 1, x, 3\right), x, 1\right) \]
      14. lower-fma.f6451.4

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(3, x, 1\right), x, 3\right), x, 1\right) \]
    10. Applied rewrites51.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: 98.8% 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^{-9}:\\ \;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\ \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-9)
   (/ (- (/ 2.0 x) 3.0) (- x 1.0))
   (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-9) {
		tmp = ((2.0 / x) - 3.0) / (x - 1.0);
	} 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-9)
		tmp = Float64(Float64(Float64(2.0 / x) - 3.0) / Float64(x - 1.0));
	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-9], N[(N[(N[(2.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $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^{-9}:\\
\;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\

\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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} - \frac{x}{-1 - x}} \]
    4. Step-by-step derivation
      1. lift--.f64N/A

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

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

        \[\leadsto \frac{-1 - x}{x - 1} - \frac{x}{\color{blue}{-1 - x}} \]
      4. sub-negate-revN/A

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 - x}{x - 1} + \frac{x}{x + 1}} \]
      9. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{x}{x + 1} + \frac{-1 - x}{x - 1}} \]
      10. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x - 1}} \]
      18. sub-to-fractionN/A

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

        \[\leadsto \color{blue}{\frac{\frac{x}{x + 1} \cdot \left(x - 1\right) - \left(x + 1\right)}{x - 1}} \]
    5. Applied rewrites55.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x}{x - -1}, x - 1, -1 - x\right)}{x - 1}} \]
    6. Taylor expanded in x around inf

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

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

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
    8. Applied rewrites50.2%

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

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{2 \cdot \frac{1}{x} - 3}{x - 1} \]
      3. mult-flip-revN/A

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

        \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]
    10. Applied rewrites50.2%

      \[\leadsto \frac{\frac{2}{x} - 3}{x - 1} \]

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\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-+.f6451.7

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

      \[\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.f6451.7

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

      \[\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 5: 98.8% 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^{-9}:\\ \;\;\;\;\frac{\frac{-1}{x} - 3}{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-9)
   (/ (- (/ -1.0 x) 3.0) 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-9) {
		tmp = ((-1.0 / x) - 3.0) / 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-9)
		tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / 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-9], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $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^{-9}:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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-/.f6448.9

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
    4. Applied rewrites48.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. add-flipN/A

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

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

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

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

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

        \[\leadsto \frac{\frac{-1}{x} - 3}{x} \]
      13. lower-/.f6448.9

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

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

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\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-+.f6451.7

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

      \[\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.f6451.7

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

      \[\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: 98.8% 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^{-9}:\\ \;\;\;\;\frac{\frac{-1}{x} - 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-9)
   (/ (- (/ -1.0 x) 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-9) {
		tmp = ((-1.0 / x) - 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-9)
		tmp = Float64(Float64(Float64(-1.0 / x) - 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-9], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $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^{-9}:\\
\;\;\;\;\frac{\frac{-1}{x} - 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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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-/.f6448.9

        \[\leadsto -1 \cdot \frac{3 + \frac{1}{x}}{x} \]
    4. Applied rewrites48.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. add-flipN/A

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

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

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

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

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

        \[\leadsto \frac{\frac{-1}{x} - 3}{x} \]
      13. lower-/.f6448.9

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

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

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\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-+.f6451.7

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

      \[\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.f6451.7

        \[\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--.f6451.7

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

      \[\leadsto \mathsf{fma}\left(x - -3, \color{blue}{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^{-9}:\\ \;\;\;\;\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-9)
   (/ -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-9) {
		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-9)
		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-9], 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^{-9}:\\
\;\;\;\;\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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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-/.f6449.8

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

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

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{-1 - x}{x - 1} - \left(\mathsf{neg}\left(\color{blue}{\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-eval54.9

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

      \[\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-+.f6451.7

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

      \[\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.f6451.7

        \[\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--.f6451.7

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

      \[\leadsto \mathsf{fma}\left(x - -3, \color{blue}{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^{-9}:\\ \;\;\;\;\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-9)
   (/ -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-9) {
		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-9)
		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-9], 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^{-9}:\\
\;\;\;\;\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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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-/.f6449.8

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

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

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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-*.f6451.3

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

      \[\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. lift-*.f64N/A

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

        \[\leadsto x \cdot 3 + 1 \]
      5. lower-fma.f6451.3

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{3}, 1\right) \]
    6. Applied rewrites51.3%

      \[\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^{-9}:\\ \;\;\;\;\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-9) (/ -3.0 x) 1.0))
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 5e-9) {
		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-9) 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-9) {
		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-9:
		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-9)
		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-9)
		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-9], 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^{-9}:\\
\;\;\;\;\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)))) < 5.0000000000000001e-9

    1. Initial program 54.9%

      \[\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-/.f6449.8

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

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

    if 5.0000000000000001e-9 < (-.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 54.9%

      \[\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 rewrites51.8%

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

    Alternative 10: 51.8% 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 54.9%

      \[\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 rewrites51.8%

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

      Reproduce

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