sqrt(x*(x-1))/(x-2)

Percentage Accurate: 99.9% → 99.9%
Time: 3.7s
Alternatives: 12
Speedup: 1.0×

Specification

?
\[-10000000000 \leq x \land x \leq 10000000000\]
\[\begin{array}{l} \\ \frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \end{array} \]
(FPCore (x) :precision binary64 (/ (sqrt (* x (- x 1.0))) (- x 2.0)))
double code(double x) {
	return sqrt((x * (x - 1.0))) / (x - 2.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((x * (x - 1.0d0))) / (x - 2.0d0)
end function
public static double code(double x) {
	return Math.sqrt((x * (x - 1.0))) / (x - 2.0);
}
def code(x):
	return math.sqrt((x * (x - 1.0))) / (x - 2.0)
function code(x)
	return Float64(sqrt(Float64(x * Float64(x - 1.0))) / Float64(x - 2.0))
end
function tmp = code(x)
	tmp = sqrt((x * (x - 1.0))) / (x - 2.0);
end
code[x_] := N[(N[Sqrt[N[(x * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 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: 99.9% accurate, 1.0× speedup?

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

\\
\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2}
\end{array}

Alternative 1: 99.9% accurate, 0.8× speedup?

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

\\
\frac{\left(x - -2\right) \cdot \sqrt{\left(x - 1\right) \cdot x}}{\mathsf{fma}\left(x, x, -4\right)}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

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

      \[\leadsto \frac{\sqrt{x \cdot \left(x - 1\right)}}{\color{blue}{x - 2}} \]
    3. flip--N/A

      \[\leadsto \frac{\sqrt{x \cdot \left(x - 1\right)}}{\color{blue}{\frac{x \cdot x - 2 \cdot 2}{x + 2}}} \]
    4. associate-/r/N/A

      \[\leadsto \color{blue}{\frac{\sqrt{x \cdot \left(x - 1\right)}}{x \cdot x - 2 \cdot 2} \cdot \left(x + 2\right)} \]
    5. associate-*l/N/A

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

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

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

      \[\leadsto \frac{\color{blue}{\left(x + 2\right) \cdot \sqrt{x \cdot \left(x - 1\right)}}}{x \cdot x - 2 \cdot 2} \]
    9. metadata-evalN/A

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(x - -2\right) \cdot \sqrt{\color{blue}{\left(x - 1\right) \cdot x}}}{x \cdot x - 2 \cdot 2} \]
    17. sub-negN/A

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

      \[\leadsto \frac{\left(x - -2\right) \cdot \sqrt{\left(x - 1\right) \cdot x}}{\color{blue}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(2 \cdot 2\right)\right)}} \]
    19. metadata-evalN/A

      \[\leadsto \frac{\left(x - -2\right) \cdot \sqrt{\left(x - 1\right) \cdot x}}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\color{blue}{4}\right)\right)} \]
    20. metadata-eval99.9

      \[\leadsto \frac{\left(x - -2\right) \cdot \sqrt{\left(x - 1\right) \cdot x}}{\mathsf{fma}\left(x, x, \color{blue}{-4}\right)} \]
  4. Applied rewrites99.9%

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

Alternative 2: 94.9% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \leq -5 \cdot 10^{-155}:\\
\;\;\;\;\frac{\sqrt{x \cdot x - x}}{-2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sqrt.f64 (*.f64 x (-.f64 x #s(literal 1 binary64)))) (-.f64 x #s(literal 2 binary64))) < -4.9999999999999999e-155

    1. Initial program 99.9%

      \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \frac{\sqrt{x \cdot \color{blue}{\left(x - 1\right)}}}{x - 2} \]
      3. distribute-lft-out--N/A

        \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x - x \cdot 1}}}{x - 2} \]
      4. *-rgt-identityN/A

        \[\leadsto \frac{\sqrt{x \cdot x - \color{blue}{x}}}{x - 2} \]
      5. lower--.f64N/A

        \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x - x}}}{x - 2} \]
      6. lower-*.f6499.9

        \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x} - x}}{x - 2} \]
    4. Applied rewrites99.9%

      \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x - x}}}{x - 2} \]
    5. Taylor expanded in x around 0

      \[\leadsto \frac{\sqrt{x \cdot x - x}}{\color{blue}{-2}} \]
    6. Step-by-step derivation
      1. Applied rewrites94.0%

        \[\leadsto \frac{\sqrt{x \cdot x - x}}{\color{blue}{-2}} \]

      if -4.9999999999999999e-155 < (/.f64 (sqrt.f64 (*.f64 x (-.f64 x #s(literal 1 binary64)))) (-.f64 x #s(literal 2 binary64)))

      1. Initial program 99.3%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

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

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

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

          \[\leadsto \left(\frac{3}{2} \cdot \frac{1}{x} + \color{blue}{\frac{\frac{\frac{23}{8}}{x}}{x}}\right) + 1 \]
        4. metadata-evalN/A

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

          \[\leadsto \left(\frac{3}{2} \cdot \frac{1}{x} + \frac{\color{blue}{\frac{23}{8} \cdot \frac{1}{x}}}{x}\right) + 1 \]
        6. associate-*l/N/A

          \[\leadsto \left(\frac{3}{2} \cdot \frac{1}{x} + \color{blue}{\frac{\frac{23}{8}}{x} \cdot \frac{1}{x}}\right) + 1 \]
        7. metadata-evalN/A

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\frac{1}{x}, \color{blue}{\frac{23}{8} \cdot \frac{1}{x} + \frac{3}{2}}, 1\right) \]
        14. associate-*r/N/A

          \[\leadsto \mathsf{fma}\left(\frac{1}{x}, \color{blue}{\frac{\frac{23}{8} \cdot 1}{x}} + \frac{3}{2}, 1\right) \]
        15. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\frac{1}{x}, \frac{\color{blue}{\frac{23}{8}}}{x} + \frac{3}{2}, 1\right) \]
        16. lower-/.f6492.1

          \[\leadsto \mathsf{fma}\left(\frac{1}{x}, \color{blue}{\frac{2.875}{x}} + 1.5, 1\right) \]
      5. Applied rewrites92.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{x}, \frac{2.875}{x} + 1.5, 1\right)} \]
    7. Recombined 2 regimes into one program.
    8. Final simplification94.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \leq -5 \cdot 10^{-155}:\\ \;\;\;\;\frac{\sqrt{x \cdot x - x}}{-2}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({x}^{-1}, \frac{2.875}{x} + 1.5, 1\right)\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 99.9% accurate, 0.8× speedup?

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

      \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{\sqrt{x \cdot \left(x - 1\right)}}{\color{blue}{x - 2}} \]
      3. flip--N/A

        \[\leadsto \frac{\sqrt{x \cdot \left(x - 1\right)}}{\color{blue}{\frac{x \cdot x - 2 \cdot 2}{x + 2}}} \]
      4. associate-/r/N/A

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

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

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

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

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

        \[\leadsto \frac{\sqrt{\color{blue}{\left(x - 1\right) \cdot x}}}{x \cdot x - 2 \cdot 2} \cdot \left(x + 2\right) \]
      10. sub-negN/A

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

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

        \[\leadsto \frac{\sqrt{\left(x - 1\right) \cdot x}}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\color{blue}{4}\right)\right)} \cdot \left(x + 2\right) \]
      13. metadata-evalN/A

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

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

        \[\leadsto \frac{\sqrt{\left(x - 1\right) \cdot x}}{\mathsf{fma}\left(x, x, -4\right)} \cdot \left(x + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(2\right)\right)}\right)\right)\right) \]
      16. sub-negN/A

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

        \[\leadsto \frac{\sqrt{\left(x - 1\right) \cdot x}}{\mathsf{fma}\left(x, x, -4\right)} \cdot \color{blue}{\left(x - \left(\mathsf{neg}\left(2\right)\right)\right)} \]
      18. metadata-eval99.9

        \[\leadsto \frac{\sqrt{\left(x - 1\right) \cdot x}}{\mathsf{fma}\left(x, x, -4\right)} \cdot \left(x - \color{blue}{-2}\right) \]
    4. Applied rewrites99.9%

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

    Alternative 4: 95.1% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{-x}}{x - 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-0.5 - \frac{0.125}{x}\right) + x}{x - 2}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= x -1e-308)
       (/ (sqrt (- x)) (- x 2.0))
       (/ (+ (- -0.5 (/ 0.125 x)) x) (- x 2.0))))
    double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = sqrt(-x) / (x - 2.0);
    	} else {
    		tmp = ((-0.5 - (0.125 / x)) + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= (-1d-308)) then
            tmp = sqrt(-x) / (x - 2.0d0)
        else
            tmp = (((-0.5d0) - (0.125d0 / x)) + x) / (x - 2.0d0)
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = Math.sqrt(-x) / (x - 2.0);
    	} else {
    		tmp = ((-0.5 - (0.125 / x)) + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= -1e-308:
    		tmp = math.sqrt(-x) / (x - 2.0)
    	else:
    		tmp = ((-0.5 - (0.125 / x)) + x) / (x - 2.0)
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= -1e-308)
    		tmp = Float64(sqrt(Float64(-x)) / Float64(x - 2.0));
    	else
    		tmp = Float64(Float64(Float64(-0.5 - Float64(0.125 / x)) + x) / Float64(x - 2.0));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= -1e-308)
    		tmp = sqrt(-x) / (x - 2.0);
    	else
    		tmp = ((-0.5 - (0.125 / x)) + x) / (x - 2.0);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, -1e-308], N[(N[Sqrt[(-x)], $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-0.5 - N[(0.125 / x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\
    \;\;\;\;\frac{\sqrt{-x}}{x - 2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{\left(-0.5 - \frac{0.125}{x}\right) + x}{x - 2}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -9.9999999999999991e-309

      1. Initial program 99.9%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \frac{\sqrt{\color{blue}{-1 \cdot x}}}{x - 2} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \frac{\sqrt{\color{blue}{\mathsf{neg}\left(x\right)}}}{x - 2} \]
        2. lower-neg.f6494.4

          \[\leadsto \frac{\sqrt{\color{blue}{-x}}}{x - 2} \]
      5. Applied rewrites94.4%

        \[\leadsto \frac{\sqrt{\color{blue}{-x}}}{x - 2} \]

      if -9.9999999999999991e-309 < x

      1. Initial program 99.2%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

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

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

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

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

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

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

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

          \[\leadsto \frac{\color{blue}{\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{8} \cdot \frac{1}{x}\right)\right) \cdot \frac{x}{x}} + x}{x - 2} \]
        8. *-rgt-identityN/A

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

          \[\leadsto \frac{\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{8} \cdot \frac{1}{x}\right)\right) \cdot \color{blue}{\left(x \cdot \frac{1}{x}\right)} + x}{x - 2} \]
        10. rgt-mult-inverseN/A

          \[\leadsto \frac{\left(-1 \cdot \left(\frac{1}{2} + \frac{1}{8} \cdot \frac{1}{x}\right)\right) \cdot \color{blue}{1} + x}{x - 2} \]
        11. *-rgt-identityN/A

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

          \[\leadsto \frac{\color{blue}{\left(-1 \cdot \frac{1}{2} + -1 \cdot \left(\frac{1}{8} \cdot \frac{1}{x}\right)\right)} + x}{x - 2} \]
        13. metadata-evalN/A

          \[\leadsto \frac{\left(\color{blue}{\frac{-1}{2}} + -1 \cdot \left(\frac{1}{8} \cdot \frac{1}{x}\right)\right) + x}{x - 2} \]
        14. mul-1-negN/A

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

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

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

          \[\leadsto \frac{\left(\frac{-1}{2} - \color{blue}{\frac{\frac{1}{8} \cdot 1}{x}}\right) + x}{x - 2} \]
        18. metadata-evalN/A

          \[\leadsto \frac{\left(\frac{-1}{2} - \frac{\color{blue}{\frac{1}{8}}}{x}\right) + x}{x - 2} \]
        19. lower-/.f6486.2

          \[\leadsto \frac{\left(-0.5 - \color{blue}{\frac{0.125}{x}}\right) + x}{x - 2} \]
      5. Applied rewrites86.2%

        \[\leadsto \frac{\color{blue}{\left(-0.5 - \frac{0.125}{x}\right) + x}}{x - 2} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 5: 94.8% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{-x}}{x - 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 + x}{x - 2}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= x -1e-308) (/ (sqrt (- x)) (- x 2.0)) (/ (+ -0.5 x) (- x 2.0))))
    double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = sqrt(-x) / (x - 2.0);
    	} else {
    		tmp = (-0.5 + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= (-1d-308)) then
            tmp = sqrt(-x) / (x - 2.0d0)
        else
            tmp = ((-0.5d0) + x) / (x - 2.0d0)
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = Math.sqrt(-x) / (x - 2.0);
    	} else {
    		tmp = (-0.5 + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= -1e-308:
    		tmp = math.sqrt(-x) / (x - 2.0)
    	else:
    		tmp = (-0.5 + x) / (x - 2.0)
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= -1e-308)
    		tmp = Float64(sqrt(Float64(-x)) / Float64(x - 2.0));
    	else
    		tmp = Float64(Float64(-0.5 + x) / Float64(x - 2.0));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= -1e-308)
    		tmp = sqrt(-x) / (x - 2.0);
    	else
    		tmp = (-0.5 + x) / (x - 2.0);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, -1e-308], N[(N[Sqrt[(-x)], $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 + x), $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\
    \;\;\;\;\frac{\sqrt{-x}}{x - 2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{-0.5 + x}{x - 2}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -9.9999999999999991e-309

      1. Initial program 99.9%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \frac{\sqrt{\color{blue}{-1 \cdot x}}}{x - 2} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \frac{\sqrt{\color{blue}{\mathsf{neg}\left(x\right)}}}{x - 2} \]
        2. lower-neg.f6494.4

          \[\leadsto \frac{\sqrt{\color{blue}{-x}}}{x - 2} \]
      5. Applied rewrites94.4%

        \[\leadsto \frac{\sqrt{\color{blue}{-x}}}{x - 2} \]

      if -9.9999999999999991e-309 < x

      1. Initial program 99.2%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

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

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

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

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

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

          \[\leadsto \frac{\left(\color{blue}{\frac{-1}{2}} \cdot \frac{1}{x}\right) \cdot x + 1 \cdot x}{x - 2} \]
        6. associate-*l*N/A

          \[\leadsto \frac{\color{blue}{\frac{-1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x}{x - 2} \]
        7. lft-mult-inverseN/A

          \[\leadsto \frac{\frac{-1}{2} \cdot \color{blue}{1} + 1 \cdot x}{x - 2} \]
        8. metadata-evalN/A

          \[\leadsto \frac{\color{blue}{\frac{-1}{2}} + 1 \cdot x}{x - 2} \]
        9. *-lft-identityN/A

          \[\leadsto \frac{\frac{-1}{2} + \color{blue}{x}}{x - 2} \]
        10. lower-+.f6476.5

          \[\leadsto \frac{\color{blue}{-0.5 + x}}{x - 2} \]
      5. Applied rewrites76.5%

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

    Alternative 6: 99.9% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \frac{\sqrt{x \cdot x - x}}{x - 2} \end{array} \]
    (FPCore (x) :precision binary64 (/ (sqrt (- (* x x) x)) (- x 2.0)))
    double code(double x) {
    	return sqrt(((x * x) - x)) / (x - 2.0);
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        code = sqrt(((x * x) - x)) / (x - 2.0d0)
    end function
    
    public static double code(double x) {
    	return Math.sqrt(((x * x) - x)) / (x - 2.0);
    }
    
    def code(x):
    	return math.sqrt(((x * x) - x)) / (x - 2.0)
    
    function code(x)
    	return Float64(sqrt(Float64(Float64(x * x) - x)) / Float64(x - 2.0))
    end
    
    function tmp = code(x)
    	tmp = sqrt(((x * x) - x)) / (x - 2.0);
    end
    
    code[x_] := N[(N[Sqrt[N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\sqrt{x \cdot x - x}}{x - 2}
    \end{array}
    
    Derivation
    1. Initial program 99.9%

      \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \frac{\sqrt{x \cdot \color{blue}{\left(x - 1\right)}}}{x - 2} \]
      3. distribute-lft-out--N/A

        \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x - x \cdot 1}}}{x - 2} \]
      4. *-rgt-identityN/A

        \[\leadsto \frac{\sqrt{x \cdot x - \color{blue}{x}}}{x - 2} \]
      5. lower--.f64N/A

        \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x - x}}}{x - 2} \]
      6. lower-*.f6499.9

        \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x} - x}}{x - 2} \]
    4. Applied rewrites99.9%

      \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x - x}}}{x - 2} \]
    5. Add Preprocessing

    Alternative 7: 99.9% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \end{array} \]
    (FPCore (x) :precision binary64 (/ (sqrt (* x (- x 1.0))) (- x 2.0)))
    double code(double x) {
    	return sqrt((x * (x - 1.0))) / (x - 2.0);
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        code = sqrt((x * (x - 1.0d0))) / (x - 2.0d0)
    end function
    
    public static double code(double x) {
    	return Math.sqrt((x * (x - 1.0))) / (x - 2.0);
    }
    
    def code(x):
    	return math.sqrt((x * (x - 1.0))) / (x - 2.0)
    
    function code(x)
    	return Float64(sqrt(Float64(x * Float64(x - 1.0))) / Float64(x - 2.0))
    end
    
    function tmp = code(x)
    	tmp = sqrt((x * (x - 1.0))) / (x - 2.0);
    end
    
    code[x_] := N[(N[Sqrt[N[(x * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2}
    \end{array}
    
    Derivation
    1. Initial program 99.9%

      \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
    2. Add Preprocessing
    3. Add Preprocessing

    Alternative 8: 10.9% accurate, 1.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\ \;\;\;\;\frac{0.5 - x}{x - 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 + x}{x - 2}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= x -1e-308) (/ (- 0.5 x) (- x 2.0)) (/ (+ -0.5 x) (- x 2.0))))
    double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = (0.5 - x) / (x - 2.0);
    	} else {
    		tmp = (-0.5 + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= (-1d-308)) then
            tmp = (0.5d0 - x) / (x - 2.0d0)
        else
            tmp = ((-0.5d0) + x) / (x - 2.0d0)
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = (0.5 - x) / (x - 2.0);
    	} else {
    		tmp = (-0.5 + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= -1e-308:
    		tmp = (0.5 - x) / (x - 2.0)
    	else:
    		tmp = (-0.5 + x) / (x - 2.0)
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= -1e-308)
    		tmp = Float64(Float64(0.5 - x) / Float64(x - 2.0));
    	else
    		tmp = Float64(Float64(-0.5 + x) / Float64(x - 2.0));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= -1e-308)
    		tmp = (0.5 - x) / (x - 2.0);
    	else
    		tmp = (-0.5 + x) / (x - 2.0);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, -1e-308], N[(N[(0.5 - x), $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 + x), $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\
    \;\;\;\;\frac{0.5 - x}{x - 2}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{-0.5 + x}{x - 2}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -9.9999999999999991e-309

      1. Initial program 99.9%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around -inf

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

          \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(x \cdot \left(1 - \frac{1}{2} \cdot \frac{1}{x}\right)\right)}}{x - 2} \]
        2. neg-sub0N/A

          \[\leadsto \frac{\color{blue}{0 - x \cdot \left(1 - \frac{1}{2} \cdot \frac{1}{x}\right)}}{x - 2} \]
        3. sub-negN/A

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

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

          \[\leadsto \frac{0 - \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2} \cdot \frac{1}{x}\right)\right) \cdot x + 1 \cdot x\right)}}{x - 2} \]
        6. distribute-lft-neg-inN/A

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

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

          \[\leadsto \frac{0 - \left(\color{blue}{\frac{-1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x\right)}{x - 2} \]
        9. lft-mult-inverseN/A

          \[\leadsto \frac{0 - \left(\frac{-1}{2} \cdot \color{blue}{1} + 1 \cdot x\right)}{x - 2} \]
        10. metadata-evalN/A

          \[\leadsto \frac{0 - \left(\color{blue}{\frac{-1}{2}} + 1 \cdot x\right)}{x - 2} \]
        11. *-lft-identityN/A

          \[\leadsto \frac{0 - \left(\frac{-1}{2} + \color{blue}{x}\right)}{x - 2} \]
        12. associate--r+N/A

          \[\leadsto \frac{\color{blue}{\left(0 - \frac{-1}{2}\right) - x}}{x - 2} \]
        13. metadata-evalN/A

          \[\leadsto \frac{\color{blue}{\frac{1}{2}} - x}{x - 2} \]
        14. lower--.f648.8

          \[\leadsto \frac{\color{blue}{0.5 - x}}{x - 2} \]
      5. Applied rewrites8.8%

        \[\leadsto \frac{\color{blue}{0.5 - x}}{x - 2} \]

      if -9.9999999999999991e-309 < x

      1. Initial program 99.2%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

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

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

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

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

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

          \[\leadsto \frac{\left(\color{blue}{\frac{-1}{2}} \cdot \frac{1}{x}\right) \cdot x + 1 \cdot x}{x - 2} \]
        6. associate-*l*N/A

          \[\leadsto \frac{\color{blue}{\frac{-1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x}{x - 2} \]
        7. lft-mult-inverseN/A

          \[\leadsto \frac{\frac{-1}{2} \cdot \color{blue}{1} + 1 \cdot x}{x - 2} \]
        8. metadata-evalN/A

          \[\leadsto \frac{\color{blue}{\frac{-1}{2}} + 1 \cdot x}{x - 2} \]
        9. *-lft-identityN/A

          \[\leadsto \frac{\frac{-1}{2} + \color{blue}{x}}{x - 2} \]
        10. lower-+.f6476.5

          \[\leadsto \frac{\color{blue}{-0.5 + x}}{x - 2} \]
      5. Applied rewrites76.5%

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

    Alternative 9: 10.0% accurate, 1.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 + x}{x - 2}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= x -1e-308) -1.0 (/ (+ -0.5 x) (- x 2.0))))
    double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = -1.0;
    	} else {
    		tmp = (-0.5 + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (x <= (-1d-308)) then
            tmp = -1.0d0
        else
            tmp = ((-0.5d0) + x) / (x - 2.0d0)
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (x <= -1e-308) {
    		tmp = -1.0;
    	} else {
    		tmp = (-0.5 + x) / (x - 2.0);
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if x <= -1e-308:
    		tmp = -1.0
    	else:
    		tmp = (-0.5 + x) / (x - 2.0)
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (x <= -1e-308)
    		tmp = -1.0;
    	else
    		tmp = Float64(Float64(-0.5 + x) / Float64(x - 2.0));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (x <= -1e-308)
    		tmp = -1.0;
    	else
    		tmp = (-0.5 + x) / (x - 2.0);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[x, -1e-308], -1.0, N[(N[(-0.5 + x), $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\
    \;\;\;\;-1\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{-0.5 + x}{x - 2}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -9.9999999999999991e-309

      1. Initial program 99.9%

        \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around -inf

        \[\leadsto \color{blue}{-1 \cdot \frac{\frac{3}{2} + \frac{23}{8} \cdot \frac{1}{x}}{x} - 1} \]
      4. Step-by-step derivation
        1. sub-negN/A

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

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

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

          \[\leadsto -1 + \color{blue}{\left(\mathsf{neg}\left(\frac{\frac{3}{2} + \frac{23}{8} \cdot \frac{1}{x}}{x}\right)\right)} \]
        5. unsub-negN/A

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

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

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

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

          \[\leadsto -1 - \frac{\color{blue}{\frac{23}{8} \cdot \frac{1}{x} + \frac{3}{2}}}{x} \]
        10. associate-*r/N/A

          \[\leadsto -1 - \frac{\color{blue}{\frac{\frac{23}{8} \cdot 1}{x}} + \frac{3}{2}}{x} \]
        11. metadata-evalN/A

          \[\leadsto -1 - \frac{\frac{\color{blue}{\frac{23}{8}}}{x} + \frac{3}{2}}{x} \]
        12. lower-/.f645.7

          \[\leadsto -1 - \frac{\color{blue}{\frac{2.875}{x}} + 1.5}{x} \]
      5. Applied rewrites5.7%

        \[\leadsto \color{blue}{-1 - \frac{\frac{2.875}{x} + 1.5}{x}} \]
      6. Taylor expanded in x around inf

        \[\leadsto -1 \]
      7. Step-by-step derivation
        1. Applied rewrites8.0%

          \[\leadsto -1 \]

        if -9.9999999999999991e-309 < x

        1. Initial program 99.2%

          \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around inf

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

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

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

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

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

            \[\leadsto \frac{\left(\color{blue}{\frac{-1}{2}} \cdot \frac{1}{x}\right) \cdot x + 1 \cdot x}{x - 2} \]
          6. associate-*l*N/A

            \[\leadsto \frac{\color{blue}{\frac{-1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x}{x - 2} \]
          7. lft-mult-inverseN/A

            \[\leadsto \frac{\frac{-1}{2} \cdot \color{blue}{1} + 1 \cdot x}{x - 2} \]
          8. metadata-evalN/A

            \[\leadsto \frac{\color{blue}{\frac{-1}{2}} + 1 \cdot x}{x - 2} \]
          9. *-lft-identityN/A

            \[\leadsto \frac{\frac{-1}{2} + \color{blue}{x}}{x - 2} \]
          10. lower-+.f6476.5

            \[\leadsto \frac{\color{blue}{-0.5 + x}}{x - 2} \]
        5. Applied rewrites76.5%

          \[\leadsto \frac{\color{blue}{-0.5 + x}}{x - 2} \]
      8. Recombined 2 regimes into one program.
      9. Add Preprocessing

      Alternative 10: 9.8% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{1.5}{x} + 1\\ \end{array} \end{array} \]
      (FPCore (x) :precision binary64 (if (<= x 2.0) -1.0 (+ (/ 1.5 x) 1.0)))
      double code(double x) {
      	double tmp;
      	if (x <= 2.0) {
      		tmp = -1.0;
      	} else {
      		tmp = (1.5 / x) + 1.0;
      	}
      	return tmp;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          real(8) :: tmp
          if (x <= 2.0d0) then
              tmp = -1.0d0
          else
              tmp = (1.5d0 / x) + 1.0d0
          end if
          code = tmp
      end function
      
      public static double code(double x) {
      	double tmp;
      	if (x <= 2.0) {
      		tmp = -1.0;
      	} else {
      		tmp = (1.5 / x) + 1.0;
      	}
      	return tmp;
      }
      
      def code(x):
      	tmp = 0
      	if x <= 2.0:
      		tmp = -1.0
      	else:
      		tmp = (1.5 / x) + 1.0
      	return tmp
      
      function code(x)
      	tmp = 0.0
      	if (x <= 2.0)
      		tmp = -1.0;
      	else
      		tmp = Float64(Float64(1.5 / x) + 1.0);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x)
      	tmp = 0.0;
      	if (x <= 2.0)
      		tmp = -1.0;
      	else
      		tmp = (1.5 / x) + 1.0;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_] := If[LessEqual[x, 2.0], -1.0, N[(N[(1.5 / x), $MachinePrecision] + 1.0), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq 2:\\
      \;\;\;\;-1\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{1.5}{x} + 1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < 2

        1. Initial program 99.9%

          \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around -inf

          \[\leadsto \color{blue}{-1 \cdot \frac{\frac{3}{2} + \frac{23}{8} \cdot \frac{1}{x}}{x} - 1} \]
        4. Step-by-step derivation
          1. sub-negN/A

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

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

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

            \[\leadsto -1 + \color{blue}{\left(\mathsf{neg}\left(\frac{\frac{3}{2} + \frac{23}{8} \cdot \frac{1}{x}}{x}\right)\right)} \]
          5. unsub-negN/A

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

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

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

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

            \[\leadsto -1 - \frac{\color{blue}{\frac{23}{8} \cdot \frac{1}{x} + \frac{3}{2}}}{x} \]
          10. associate-*r/N/A

            \[\leadsto -1 - \frac{\color{blue}{\frac{\frac{23}{8} \cdot 1}{x}} + \frac{3}{2}}{x} \]
          11. metadata-evalN/A

            \[\leadsto -1 - \frac{\frac{\color{blue}{\frac{23}{8}}}{x} + \frac{3}{2}}{x} \]
          12. lower-/.f645.7

            \[\leadsto -1 - \frac{\color{blue}{\frac{2.875}{x}} + 1.5}{x} \]
        5. Applied rewrites5.7%

          \[\leadsto \color{blue}{-1 - \frac{\frac{2.875}{x} + 1.5}{x}} \]
        6. Taylor expanded in x around inf

          \[\leadsto -1 \]
        7. Step-by-step derivation
          1. Applied rewrites8.1%

            \[\leadsto -1 \]

          if 2 < x

          1. Initial program 99.3%

            \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
          2. Add Preprocessing
          3. Taylor expanded in x around inf

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

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

              \[\leadsto \color{blue}{\frac{3}{2} \cdot \frac{1}{x} + 1} \]
            3. associate-*r/N/A

              \[\leadsto \color{blue}{\frac{\frac{3}{2} \cdot 1}{x}} + 1 \]
            4. metadata-evalN/A

              \[\leadsto \frac{\color{blue}{\frac{3}{2}}}{x} + 1 \]
            5. lower-/.f6478.3

              \[\leadsto \color{blue}{\frac{1.5}{x}} + 1 \]
          5. Applied rewrites78.3%

            \[\leadsto \color{blue}{\frac{1.5}{x} + 1} \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 11: 7.8% accurate, 33.0× speedup?

        \[\begin{array}{l} \\ -1 \end{array} \]
        (FPCore (x) :precision binary64 -1.0)
        double code(double x) {
        	return -1.0;
        }
        
        real(8) function code(x)
            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 99.9%

          \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around -inf

          \[\leadsto \color{blue}{-1 \cdot \frac{\frac{3}{2} + \frac{23}{8} \cdot \frac{1}{x}}{x} - 1} \]
        4. Step-by-step derivation
          1. sub-negN/A

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

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

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

            \[\leadsto -1 + \color{blue}{\left(\mathsf{neg}\left(\frac{\frac{3}{2} + \frac{23}{8} \cdot \frac{1}{x}}{x}\right)\right)} \]
          5. unsub-negN/A

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

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

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

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

            \[\leadsto -1 - \frac{\color{blue}{\frac{23}{8} \cdot \frac{1}{x} + \frac{3}{2}}}{x} \]
          10. associate-*r/N/A

            \[\leadsto -1 - \frac{\color{blue}{\frac{\frac{23}{8} \cdot 1}{x}} + \frac{3}{2}}{x} \]
          11. metadata-evalN/A

            \[\leadsto -1 - \frac{\frac{\color{blue}{\frac{23}{8}}}{x} + \frac{3}{2}}{x} \]
          12. lower-/.f645.6

            \[\leadsto -1 - \frac{\color{blue}{\frac{2.875}{x}} + 1.5}{x} \]
        5. Applied rewrites5.6%

          \[\leadsto \color{blue}{-1 - \frac{\frac{2.875}{x} + 1.5}{x}} \]
        6. Taylor expanded in x around inf

          \[\leadsto -1 \]
        7. Step-by-step derivation
          1. Applied rewrites7.9%

            \[\leadsto -1 \]
          2. Add Preprocessing

          Alternative 12: 3.2% accurate, 33.0× speedup?

          \[\begin{array}{l} \\ 1 \end{array} \]
          (FPCore (x) :precision binary64 1.0)
          double code(double x) {
          	return 1.0;
          }
          
          real(8) function code(x)
              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 99.9%

            \[\frac{\sqrt{x \cdot \left(x - 1\right)}}{x - 2} \]
          2. Add Preprocessing
          3. Taylor expanded in x around inf

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

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

            Reproduce

            ?
            herbie shell --seed 1 
            (FPCore (x)
              :name "sqrt(x*(x-1))/(x-2)"
              :precision binary64
              :pre (and (<= -10000000000.0 x) (<= x 10000000000.0))
              (/ (sqrt (* x (- x 1.0))) (- x 2.0)))