Data.Approximate.Numerics:blog from approximate-0.2.2.1

Percentage Accurate: 99.7% → 99.9%
Time: 12.3s
Alternatives: 10
Speedup: 1.0×

Specification

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

\\
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 99.7% accurate, 1.0× speedup?

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

\\
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

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

\\
\frac{x + -1}{-1 - \left(x + 4 \cdot \sqrt{x}\right)} \cdot -6
\end{array}
Derivation
  1. Initial program 99.5%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. *-commutative99.5%

      \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot 6}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. +-commutative99.5%

      \[\leadsto \frac{\left(x - 1\right) \cdot 6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
    3. fma-udef99.5%

      \[\leadsto \frac{\left(x - 1\right) \cdot 6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \]
    4. associate-/l*99.9%

      \[\leadsto \color{blue}{\frac{x - 1}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{6}}} \]
    5. frac-2neg99.9%

      \[\leadsto \frac{x - 1}{\color{blue}{\frac{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{-6}}} \]
    6. metadata-eval99.9%

      \[\leadsto \frac{x - 1}{\frac{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{\color{blue}{-6}}} \]
    7. associate-/r/99.9%

      \[\leadsto \color{blue}{\frac{x - 1}{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot -6} \]
    8. sub-neg99.9%

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

      \[\leadsto \frac{x + \color{blue}{-1}}{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot -6 \]
    10. neg-sub099.9%

      \[\leadsto \frac{x + -1}{\color{blue}{0 - \mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot -6 \]
    11. fma-udef99.9%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(4 \cdot \sqrt{x} + \left(x + 1\right)\right)}} \cdot -6 \]
    12. +-commutative99.9%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right)}} \cdot -6 \]
    13. +-commutative99.9%

      \[\leadsto \frac{x + -1}{0 - \left(\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}\right)} \cdot -6 \]
    14. associate-+l+100.0%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(1 + \left(x + 4 \cdot \sqrt{x}\right)\right)}} \cdot -6 \]
    15. associate--r+100.0%

      \[\leadsto \frac{x + -1}{\color{blue}{\left(0 - 1\right) - \left(x + 4 \cdot \sqrt{x}\right)}} \cdot -6 \]
    16. metadata-eval100.0%

      \[\leadsto \frac{x + -1}{\color{blue}{-1} - \left(x + 4 \cdot \sqrt{x}\right)} \cdot -6 \]
    17. +-commutative100.0%

      \[\leadsto \frac{x + -1}{-1 - \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \cdot -6 \]
    18. fma-def100.0%

      \[\leadsto \frac{x + -1}{-1 - \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \cdot -6 \]
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{x + -1}{-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)} \cdot -6} \]
  4. Step-by-step derivation
    1. fma-udef100.0%

      \[\leadsto \frac{x + -1}{-1 - \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \cdot -6 \]
  5. Applied egg-rr100.0%

    \[\leadsto \frac{x + -1}{-1 - \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \cdot -6 \]
  6. Final simplification100.0%

    \[\leadsto \frac{x + -1}{-1 - \left(x + 4 \cdot \sqrt{x}\right)} \cdot -6 \]

Alternative 2: 99.9% accurate, 1.0× speedup?

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

\\
\left(x + -1\right) \cdot \frac{6}{1 + \left(x - \sqrt{x} \cdot -4\right)}
\end{array}
Derivation
  1. Initial program 99.5%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. associate-*l/99.8%

      \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
    2. sub-neg99.8%

      \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
    3. +-commutative99.8%

      \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
    4. +-commutative99.8%

      \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
    5. fma-def99.8%

      \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
    6. +-commutative99.8%

      \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
    7. metadata-eval99.8%

      \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)} \]
  4. Step-by-step derivation
    1. fma-udef99.8%

      \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x + -1\right) \]
    2. +-commutative99.8%

      \[\leadsto \frac{6}{\color{blue}{\left(x + 1\right) + 4 \cdot \sqrt{x}}} \cdot \left(x + -1\right) \]
    3. metadata-eval99.8%

      \[\leadsto \frac{6}{\left(x + \color{blue}{\left(--1\right)}\right) + 4 \cdot \sqrt{x}} \cdot \left(x + -1\right) \]
    4. sub-neg99.8%

      \[\leadsto \frac{6}{\color{blue}{\left(x - -1\right)} + 4 \cdot \sqrt{x}} \cdot \left(x + -1\right) \]
    5. associate-+l-99.8%

      \[\leadsto \frac{6}{\color{blue}{x - \left(-1 - 4 \cdot \sqrt{x}\right)}} \cdot \left(x + -1\right) \]
  5. Applied egg-rr99.8%

    \[\leadsto \frac{6}{\color{blue}{x - \left(-1 - 4 \cdot \sqrt{x}\right)}} \cdot \left(x + -1\right) \]
  6. Step-by-step derivation
    1. associate--r-99.8%

      \[\leadsto \frac{6}{\color{blue}{\left(x - -1\right) + 4 \cdot \sqrt{x}}} \cdot \left(x + -1\right) \]
    2. sub-neg99.8%

      \[\leadsto \frac{6}{\color{blue}{\left(x + \left(--1\right)\right)} + 4 \cdot \sqrt{x}} \cdot \left(x + -1\right) \]
    3. metadata-eval99.8%

      \[\leadsto \frac{6}{\left(x + \color{blue}{1}\right) + 4 \cdot \sqrt{x}} \cdot \left(x + -1\right) \]
    4. *-lft-identity99.8%

      \[\leadsto \frac{6}{\left(x + 1\right) + \color{blue}{1 \cdot \left(4 \cdot \sqrt{x}\right)}} \cdot \left(x + -1\right) \]
    5. metadata-eval99.8%

      \[\leadsto \frac{6}{\left(x + 1\right) + \color{blue}{\left(--1\right)} \cdot \left(4 \cdot \sqrt{x}\right)} \cdot \left(x + -1\right) \]
    6. cancel-sign-sub-inv99.8%

      \[\leadsto \frac{6}{\color{blue}{\left(x + 1\right) - -1 \cdot \left(4 \cdot \sqrt{x}\right)}} \cdot \left(x + -1\right) \]
    7. +-commutative99.8%

      \[\leadsto \frac{6}{\color{blue}{\left(1 + x\right)} - -1 \cdot \left(4 \cdot \sqrt{x}\right)} \cdot \left(x + -1\right) \]
    8. associate--l+99.9%

      \[\leadsto \frac{6}{\color{blue}{1 + \left(x - -1 \cdot \left(4 \cdot \sqrt{x}\right)\right)}} \cdot \left(x + -1\right) \]
    9. mul-1-neg99.9%

      \[\leadsto \frac{6}{1 + \left(x - \color{blue}{\left(-4 \cdot \sqrt{x}\right)}\right)} \cdot \left(x + -1\right) \]
    10. distribute-lft-neg-in99.9%

      \[\leadsto \frac{6}{1 + \left(x - \color{blue}{\left(-4\right) \cdot \sqrt{x}}\right)} \cdot \left(x + -1\right) \]
    11. *-commutative99.9%

      \[\leadsto \frac{6}{1 + \left(x - \color{blue}{\sqrt{x} \cdot \left(-4\right)}\right)} \cdot \left(x + -1\right) \]
    12. metadata-eval99.9%

      \[\leadsto \frac{6}{1 + \left(x - \sqrt{x} \cdot \color{blue}{-4}\right)} \cdot \left(x + -1\right) \]
  7. Applied egg-rr99.9%

    \[\leadsto \frac{6}{\color{blue}{1 + \left(x - \sqrt{x} \cdot -4\right)}} \cdot \left(x + -1\right) \]
  8. Final simplification99.9%

    \[\leadsto \left(x + -1\right) \cdot \frac{6}{1 + \left(x - \sqrt{x} \cdot -4\right)} \]

Alternative 3: 95.5% accurate, 12.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;\frac{6}{\frac{-1}{1 - x}}\\

\mathbf{else}:\\
\;\;\;\;6 - \frac{12}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. sub-neg99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. +-commutative99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
      4. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      5. fma-def99.9%

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

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      7. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

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

      \[\leadsto \frac{6}{\color{blue}{1}} \cdot \left(x + -1\right) \]
    5. Step-by-step derivation
      1. +-commutative93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-1 + x\right)} \]
      2. metadata-eval93.3%

        \[\leadsto \frac{6}{1} \cdot \left(\color{blue}{\left(0 - 1\right)} + x\right) \]
      3. associate--r-93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(0 - \left(1 - x\right)\right)} \]
      4. neg-sub093.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-\left(1 - x\right)\right)} \]
      5. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{6}{\frac{1}{-\left(1 - x\right)}}} \]
      6. metadata-eval93.3%

        \[\leadsto \frac{6}{\frac{\color{blue}{--1}}{-\left(1 - x\right)}} \]
      7. frac-2neg93.3%

        \[\leadsto \frac{6}{\color{blue}{\frac{-1}{1 - x}}} \]
    6. Applied egg-rr93.3%

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

    if 2 < x

    1. Initial program 99.0%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.0%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.0%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
      7. fma-def99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \]
    3. Simplified99.0%

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

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{x}} \]
    5. Step-by-step derivation
      1. fma-udef93.8%

        \[\leadsto \frac{\color{blue}{6 \cdot x + -6}}{x} \]
      2. metadata-eval93.8%

        \[\leadsto \frac{6 \cdot x + \color{blue}{6 \cdot -1}}{x} \]
      3. distribute-lft-in93.8%

        \[\leadsto \frac{\color{blue}{6 \cdot \left(x + -1\right)}}{x} \]
      4. *-commutative93.8%

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

        \[\leadsto \color{blue}{\frac{x + -1}{\frac{x}{6}}} \]
      6. metadata-eval94.7%

        \[\leadsto \frac{x + \color{blue}{\left(-1\right)}}{\frac{x}{6}} \]
      7. sub-neg94.7%

        \[\leadsto \frac{\color{blue}{x - 1}}{\frac{x}{6}} \]
      8. flip--39.8%

        \[\leadsto \frac{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}{\frac{x}{6}} \]
      9. metadata-eval39.8%

        \[\leadsto \frac{\frac{x \cdot x - \color{blue}{1}}{x + 1}}{\frac{x}{6}} \]
      10. sub-div39.8%

        \[\leadsto \frac{\color{blue}{\frac{x \cdot x}{x + 1} - \frac{1}{x + 1}}}{\frac{x}{6}} \]
      11. div-sub39.8%

        \[\leadsto \color{blue}{\frac{\frac{x \cdot x}{x + 1}}{\frac{x}{6}} - \frac{\frac{1}{x + 1}}{\frac{x}{6}}} \]
      12. div-inv39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{\color{blue}{x \cdot \frac{1}{6}}} - \frac{\frac{1}{x + 1}}{\frac{x}{6}} \]
      13. metadata-eval39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{x \cdot \color{blue}{0.16666666666666666}} - \frac{\frac{1}{x + 1}}{\frac{x}{6}} \]
      14. div-inv39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{x \cdot 0.16666666666666666} - \frac{\frac{1}{x + 1}}{\color{blue}{x \cdot \frac{1}{6}}} \]
      15. metadata-eval39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{x \cdot 0.16666666666666666} - \frac{\frac{1}{x + 1}}{x \cdot \color{blue}{0.16666666666666666}} \]
    6. Applied egg-rr39.7%

      \[\leadsto \color{blue}{\frac{\frac{x \cdot x}{x + 1}}{x \cdot 0.16666666666666666} - \frac{\frac{1}{x + 1}}{x \cdot 0.16666666666666666}} \]
    7. Step-by-step derivation
      1. associate-/l/37.9%

        \[\leadsto \color{blue}{\frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(x + 1\right)}} - \frac{\frac{1}{x + 1}}{x \cdot 0.16666666666666666} \]
      2. +-commutative37.9%

        \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \color{blue}{\left(1 + x\right)}} - \frac{\frac{1}{x + 1}}{x \cdot 0.16666666666666666} \]
      3. associate-/l/37.9%

        \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \color{blue}{\frac{1}{\left(x \cdot 0.16666666666666666\right) \cdot \left(x + 1\right)}} \]
      4. +-commutative37.9%

        \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \frac{1}{\left(x \cdot 0.16666666666666666\right) \cdot \color{blue}{\left(1 + x\right)}} \]
    8. Simplified37.9%

      \[\leadsto \color{blue}{\frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \frac{1}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)}} \]
    9. Taylor expanded in x around 0 37.9%

      \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \color{blue}{\frac{6}{x}} \]
    10. Taylor expanded in x around inf 94.7%

      \[\leadsto \color{blue}{6 - 12 \cdot \frac{1}{x}} \]
    11. Step-by-step derivation
      1. associate-*r/94.7%

        \[\leadsto 6 - \color{blue}{\frac{12 \cdot 1}{x}} \]
      2. metadata-eval94.7%

        \[\leadsto 6 - \frac{\color{blue}{12}}{x} \]
    12. Simplified94.7%

      \[\leadsto \color{blue}{6 - \frac{12}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;\frac{6}{\frac{-1}{1 - x}}\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \]

Alternative 4: 95.5% accurate, 12.6× speedup?

\[\begin{array}{l} \\ -6 \cdot \frac{x + -1}{-1 - x} \end{array} \]
(FPCore (x) :precision binary64 (* -6.0 (/ (+ x -1.0) (- -1.0 x))))
double code(double x) {
	return -6.0 * ((x + -1.0) / (-1.0 - x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (-6.0d0) * ((x + (-1.0d0)) / ((-1.0d0) - x))
end function
public static double code(double x) {
	return -6.0 * ((x + -1.0) / (-1.0 - x));
}
def code(x):
	return -6.0 * ((x + -1.0) / (-1.0 - x))
function code(x)
	return Float64(-6.0 * Float64(Float64(x + -1.0) / Float64(-1.0 - x)))
end
function tmp = code(x)
	tmp = -6.0 * ((x + -1.0) / (-1.0 - x));
end
code[x_] := N[(-6.0 * N[(N[(x + -1.0), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-6 \cdot \frac{x + -1}{-1 - x}
\end{array}
Derivation
  1. Initial program 99.5%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. *-commutative99.5%

      \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot 6}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. +-commutative99.5%

      \[\leadsto \frac{\left(x - 1\right) \cdot 6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
    3. fma-udef99.5%

      \[\leadsto \frac{\left(x - 1\right) \cdot 6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \]
    4. associate-/l*99.9%

      \[\leadsto \color{blue}{\frac{x - 1}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{6}}} \]
    5. frac-2neg99.9%

      \[\leadsto \frac{x - 1}{\color{blue}{\frac{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{-6}}} \]
    6. metadata-eval99.9%

      \[\leadsto \frac{x - 1}{\frac{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{\color{blue}{-6}}} \]
    7. associate-/r/99.9%

      \[\leadsto \color{blue}{\frac{x - 1}{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot -6} \]
    8. sub-neg99.9%

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

      \[\leadsto \frac{x + \color{blue}{-1}}{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot -6 \]
    10. neg-sub099.9%

      \[\leadsto \frac{x + -1}{\color{blue}{0 - \mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot -6 \]
    11. fma-udef99.9%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(4 \cdot \sqrt{x} + \left(x + 1\right)\right)}} \cdot -6 \]
    12. +-commutative99.9%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right)}} \cdot -6 \]
    13. +-commutative99.9%

      \[\leadsto \frac{x + -1}{0 - \left(\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}\right)} \cdot -6 \]
    14. associate-+l+100.0%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(1 + \left(x + 4 \cdot \sqrt{x}\right)\right)}} \cdot -6 \]
    15. associate--r+100.0%

      \[\leadsto \frac{x + -1}{\color{blue}{\left(0 - 1\right) - \left(x + 4 \cdot \sqrt{x}\right)}} \cdot -6 \]
    16. metadata-eval100.0%

      \[\leadsto \frac{x + -1}{\color{blue}{-1} - \left(x + 4 \cdot \sqrt{x}\right)} \cdot -6 \]
    17. +-commutative100.0%

      \[\leadsto \frac{x + -1}{-1 - \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \cdot -6 \]
    18. fma-def100.0%

      \[\leadsto \frac{x + -1}{-1 - \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \cdot -6 \]
  3. Applied egg-rr100.0%

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

    \[\leadsto \frac{x + -1}{-1 - \color{blue}{x}} \cdot -6 \]
  5. Final simplification94.0%

    \[\leadsto -6 \cdot \frac{x + -1}{-1 - x} \]

Alternative 5: 95.5% accurate, 12.6× speedup?

\[\begin{array}{l} \\ \frac{6}{\frac{-1 - x}{1 - x}} \end{array} \]
(FPCore (x) :precision binary64 (/ 6.0 (/ (- -1.0 x) (- 1.0 x))))
double code(double x) {
	return 6.0 / ((-1.0 - x) / (1.0 - x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 6.0d0 / (((-1.0d0) - x) / (1.0d0 - x))
end function
public static double code(double x) {
	return 6.0 / ((-1.0 - x) / (1.0 - x));
}
def code(x):
	return 6.0 / ((-1.0 - x) / (1.0 - x))
function code(x)
	return Float64(6.0 / Float64(Float64(-1.0 - x) / Float64(1.0 - x)))
end
function tmp = code(x)
	tmp = 6.0 / ((-1.0 - x) / (1.0 - x));
end
code[x_] := N[(6.0 / N[(N[(-1.0 - x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{6}{\frac{-1 - x}{1 - x}}
\end{array}
Derivation
  1. Initial program 99.5%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. *-commutative99.5%

      \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot 6}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. +-commutative99.5%

      \[\leadsto \frac{\left(x - 1\right) \cdot 6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
    3. fma-udef99.5%

      \[\leadsto \frac{\left(x - 1\right) \cdot 6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \]
    4. associate-/l*99.9%

      \[\leadsto \color{blue}{\frac{x - 1}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{6}}} \]
    5. frac-2neg99.9%

      \[\leadsto \frac{x - 1}{\color{blue}{\frac{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{-6}}} \]
    6. metadata-eval99.9%

      \[\leadsto \frac{x - 1}{\frac{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{\color{blue}{-6}}} \]
    7. associate-/r/99.9%

      \[\leadsto \color{blue}{\frac{x - 1}{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot -6} \]
    8. sub-neg99.9%

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

      \[\leadsto \frac{x + \color{blue}{-1}}{-\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot -6 \]
    10. neg-sub099.9%

      \[\leadsto \frac{x + -1}{\color{blue}{0 - \mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot -6 \]
    11. fma-udef99.9%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(4 \cdot \sqrt{x} + \left(x + 1\right)\right)}} \cdot -6 \]
    12. +-commutative99.9%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right)}} \cdot -6 \]
    13. +-commutative99.9%

      \[\leadsto \frac{x + -1}{0 - \left(\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}\right)} \cdot -6 \]
    14. associate-+l+100.0%

      \[\leadsto \frac{x + -1}{0 - \color{blue}{\left(1 + \left(x + 4 \cdot \sqrt{x}\right)\right)}} \cdot -6 \]
    15. associate--r+100.0%

      \[\leadsto \frac{x + -1}{\color{blue}{\left(0 - 1\right) - \left(x + 4 \cdot \sqrt{x}\right)}} \cdot -6 \]
    16. metadata-eval100.0%

      \[\leadsto \frac{x + -1}{\color{blue}{-1} - \left(x + 4 \cdot \sqrt{x}\right)} \cdot -6 \]
    17. +-commutative100.0%

      \[\leadsto \frac{x + -1}{-1 - \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \cdot -6 \]
    18. fma-def100.0%

      \[\leadsto \frac{x + -1}{-1 - \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \cdot -6 \]
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{x + -1}{-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)} \cdot -6} \]
  4. Step-by-step derivation
    1. frac-2neg100.0%

      \[\leadsto \color{blue}{\frac{-\left(x + -1\right)}{-\left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)}} \cdot -6 \]
    2. associate-*l/99.5%

      \[\leadsto \color{blue}{\frac{\left(-\left(x + -1\right)\right) \cdot -6}{-\left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)}} \]
    3. distribute-neg-in99.5%

      \[\leadsto \frac{\color{blue}{\left(\left(-x\right) + \left(--1\right)\right)} \cdot -6}{-\left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)} \]
    4. metadata-eval99.5%

      \[\leadsto \frac{\left(\left(-x\right) + \color{blue}{1}\right) \cdot -6}{-\left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)} \]
    5. +-commutative99.5%

      \[\leadsto \frac{\color{blue}{\left(1 + \left(-x\right)\right)} \cdot -6}{-\left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)} \]
    6. sub-neg99.5%

      \[\leadsto \frac{\color{blue}{\left(1 - x\right)} \cdot -6}{-\left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)} \]
    7. *-commutative99.5%

      \[\leadsto \frac{\color{blue}{-6 \cdot \left(1 - x\right)}}{-\left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)} \]
    8. neg-sub099.5%

      \[\leadsto \frac{-6 \cdot \left(1 - x\right)}{\color{blue}{0 - \left(-1 - \mathsf{fma}\left(4, \sqrt{x}, x\right)\right)}} \]
    9. associate--r-99.5%

      \[\leadsto \frac{-6 \cdot \left(1 - x\right)}{\color{blue}{\left(0 - -1\right) + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    10. metadata-eval99.5%

      \[\leadsto \frac{-6 \cdot \left(1 - x\right)}{\color{blue}{1} + \mathsf{fma}\left(4, \sqrt{x}, x\right)} \]
    11. fma-udef99.5%

      \[\leadsto \frac{-6 \cdot \left(1 - x\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
    12. associate-+r+99.5%

      \[\leadsto \frac{-6 \cdot \left(1 - x\right)}{\color{blue}{\left(1 + 4 \cdot \sqrt{x}\right) + x}} \]
    13. +-commutative99.5%

      \[\leadsto \frac{-6 \cdot \left(1 - x\right)}{\color{blue}{x + \left(1 + 4 \cdot \sqrt{x}\right)}} \]
    14. associate-+l+99.5%

      \[\leadsto \frac{-6 \cdot \left(1 - x\right)}{\color{blue}{\left(x + 1\right) + 4 \cdot \sqrt{x}}} \]
    15. metadata-eval99.5%

      \[\leadsto \frac{\color{blue}{\frac{6}{-1}} \cdot \left(1 - x\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    16. associate-/r/99.4%

      \[\leadsto \frac{\color{blue}{\frac{6}{\frac{-1}{1 - x}}}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    17. associate-/l/99.8%

      \[\leadsto \color{blue}{\frac{6}{\left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right) \cdot \frac{-1}{1 - x}}} \]
    18. associate-*r/99.9%

      \[\leadsto \frac{6}{\color{blue}{\frac{\left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right) \cdot -1}{1 - x}}} \]
  5. Applied egg-rr99.9%

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

    \[\leadsto \frac{6}{\frac{-1 - \color{blue}{x}}{1 - x}} \]
  7. Final simplification94.0%

    \[\leadsto \frac{6}{\frac{-1 - x}{1 - x}} \]

Alternative 6: 95.5% accurate, 16.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;-6 \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;6\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 2.0) (* -6.0 (- 1.0 x)) 6.0))
double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = -6.0 * (1.0 - x);
	} else {
		tmp = 6.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 2.0d0) then
        tmp = (-6.0d0) * (1.0d0 - x)
    else
        tmp = 6.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = -6.0 * (1.0 - x);
	} else {
		tmp = 6.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 2.0:
		tmp = -6.0 * (1.0 - x)
	else:
		tmp = 6.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 2.0)
		tmp = Float64(-6.0 * Float64(1.0 - x));
	else
		tmp = 6.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 2.0)
		tmp = -6.0 * (1.0 - x);
	else
		tmp = 6.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 2.0], N[(-6.0 * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], 6.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;-6 \cdot \left(1 - x\right)\\

\mathbf{else}:\\
\;\;\;\;6\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. sub-neg99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. +-commutative99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
      4. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      5. fma-def99.9%

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

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      7. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

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

      \[\leadsto \frac{6}{\color{blue}{1}} \cdot \left(x + -1\right) \]
    5. Step-by-step derivation
      1. +-commutative93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-1 + x\right)} \]
      2. metadata-eval93.3%

        \[\leadsto \frac{6}{1} \cdot \left(\color{blue}{\left(0 - 1\right)} + x\right) \]
      3. associate--r-93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(0 - \left(1 - x\right)\right)} \]
      4. neg-sub093.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-\left(1 - x\right)\right)} \]
      5. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{6}{\frac{1}{-\left(1 - x\right)}}} \]
      6. metadata-eval93.3%

        \[\leadsto \frac{6}{\frac{\color{blue}{--1}}{-\left(1 - x\right)}} \]
      7. frac-2neg93.3%

        \[\leadsto \frac{6}{\color{blue}{\frac{-1}{1 - x}}} \]
    6. Applied egg-rr93.3%

      \[\leadsto \color{blue}{\frac{6}{\frac{-1}{1 - x}}} \]
    7. Step-by-step derivation
      1. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{6}{-1} \cdot \left(1 - x\right)} \]
      2. metadata-eval93.3%

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

      \[\leadsto \color{blue}{-6 \cdot \left(1 - x\right)} \]

    if 2 < x

    1. Initial program 99.0%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.8%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. sub-neg99.8%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. +-commutative99.8%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
      4. +-commutative99.8%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      5. fma-def99.8%

        \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      6. +-commutative99.8%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      7. metadata-eval99.8%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.8%

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

      \[\leadsto \color{blue}{6} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;-6 \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;6\\ \end{array} \]

Alternative 7: 95.5% accurate, 16.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6 \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{6}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 1.0) (* -6.0 (- 1.0 x)) (- 6.0 (/ 6.0 x))))
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0 * (1.0 - x);
	} else {
		tmp = 6.0 - (6.0 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = (-6.0d0) * (1.0d0 - x)
    else
        tmp = 6.0d0 - (6.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0 * (1.0 - x);
	} else {
		tmp = 6.0 - (6.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = -6.0 * (1.0 - x)
	else:
		tmp = 6.0 - (6.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = Float64(-6.0 * Float64(1.0 - x));
	else
		tmp = Float64(6.0 - Float64(6.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = -6.0 * (1.0 - x);
	else
		tmp = 6.0 - (6.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 1.0], N[(-6.0 * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(6.0 - N[(6.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;-6 \cdot \left(1 - x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. sub-neg99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. +-commutative99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
      4. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      5. fma-def99.9%

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

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      7. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

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

      \[\leadsto \frac{6}{\color{blue}{1}} \cdot \left(x + -1\right) \]
    5. Step-by-step derivation
      1. +-commutative93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-1 + x\right)} \]
      2. metadata-eval93.3%

        \[\leadsto \frac{6}{1} \cdot \left(\color{blue}{\left(0 - 1\right)} + x\right) \]
      3. associate--r-93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(0 - \left(1 - x\right)\right)} \]
      4. neg-sub093.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-\left(1 - x\right)\right)} \]
      5. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{6}{\frac{1}{-\left(1 - x\right)}}} \]
      6. metadata-eval93.3%

        \[\leadsto \frac{6}{\frac{\color{blue}{--1}}{-\left(1 - x\right)}} \]
      7. frac-2neg93.3%

        \[\leadsto \frac{6}{\color{blue}{\frac{-1}{1 - x}}} \]
    6. Applied egg-rr93.3%

      \[\leadsto \color{blue}{\frac{6}{\frac{-1}{1 - x}}} \]
    7. Step-by-step derivation
      1. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{6}{-1} \cdot \left(1 - x\right)} \]
      2. metadata-eval93.3%

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

      \[\leadsto \color{blue}{-6 \cdot \left(1 - x\right)} \]

    if 1 < x

    1. Initial program 99.0%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.0%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.0%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
      7. fma-def99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \]
    3. Simplified99.0%

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

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

      \[\leadsto \color{blue}{6 - 6 \cdot \frac{1}{x}} \]
    6. Step-by-step derivation
      1. associate-*r/94.7%

        \[\leadsto 6 - \color{blue}{\frac{6 \cdot 1}{x}} \]
      2. metadata-eval94.7%

        \[\leadsto 6 - \frac{\color{blue}{6}}{x} \]
    7. Simplified94.7%

      \[\leadsto \color{blue}{6 - \frac{6}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6 \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{6}{x}\\ \end{array} \]

Alternative 8: 95.5% accurate, 16.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;-6 \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 2.0) (* -6.0 (- 1.0 x)) (- 6.0 (/ 12.0 x))))
double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = -6.0 * (1.0 - x);
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 2.0d0) then
        tmp = (-6.0d0) * (1.0d0 - x)
    else
        tmp = 6.0d0 - (12.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = -6.0 * (1.0 - x);
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 2.0:
		tmp = -6.0 * (1.0 - x)
	else:
		tmp = 6.0 - (12.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 2.0)
		tmp = Float64(-6.0 * Float64(1.0 - x));
	else
		tmp = Float64(6.0 - Float64(12.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 2.0)
		tmp = -6.0 * (1.0 - x);
	else
		tmp = 6.0 - (12.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 2.0], N[(-6.0 * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(6.0 - N[(12.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;-6 \cdot \left(1 - x\right)\\

\mathbf{else}:\\
\;\;\;\;6 - \frac{12}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. sub-neg99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. +-commutative99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
      4. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      5. fma-def99.9%

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

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      7. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

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

      \[\leadsto \frac{6}{\color{blue}{1}} \cdot \left(x + -1\right) \]
    5. Step-by-step derivation
      1. +-commutative93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-1 + x\right)} \]
      2. metadata-eval93.3%

        \[\leadsto \frac{6}{1} \cdot \left(\color{blue}{\left(0 - 1\right)} + x\right) \]
      3. associate--r-93.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(0 - \left(1 - x\right)\right)} \]
      4. neg-sub093.3%

        \[\leadsto \frac{6}{1} \cdot \color{blue}{\left(-\left(1 - x\right)\right)} \]
      5. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{6}{\frac{1}{-\left(1 - x\right)}}} \]
      6. metadata-eval93.3%

        \[\leadsto \frac{6}{\frac{\color{blue}{--1}}{-\left(1 - x\right)}} \]
      7. frac-2neg93.3%

        \[\leadsto \frac{6}{\color{blue}{\frac{-1}{1 - x}}} \]
    6. Applied egg-rr93.3%

      \[\leadsto \color{blue}{\frac{6}{\frac{-1}{1 - x}}} \]
    7. Step-by-step derivation
      1. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{6}{-1} \cdot \left(1 - x\right)} \]
      2. metadata-eval93.3%

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

      \[\leadsto \color{blue}{-6 \cdot \left(1 - x\right)} \]

    if 2 < x

    1. Initial program 99.0%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.0%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.0%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
      7. fma-def99.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \]
    3. Simplified99.0%

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

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{x}} \]
    5. Step-by-step derivation
      1. fma-udef93.8%

        \[\leadsto \frac{\color{blue}{6 \cdot x + -6}}{x} \]
      2. metadata-eval93.8%

        \[\leadsto \frac{6 \cdot x + \color{blue}{6 \cdot -1}}{x} \]
      3. distribute-lft-in93.8%

        \[\leadsto \frac{\color{blue}{6 \cdot \left(x + -1\right)}}{x} \]
      4. *-commutative93.8%

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

        \[\leadsto \color{blue}{\frac{x + -1}{\frac{x}{6}}} \]
      6. metadata-eval94.7%

        \[\leadsto \frac{x + \color{blue}{\left(-1\right)}}{\frac{x}{6}} \]
      7. sub-neg94.7%

        \[\leadsto \frac{\color{blue}{x - 1}}{\frac{x}{6}} \]
      8. flip--39.8%

        \[\leadsto \frac{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}{\frac{x}{6}} \]
      9. metadata-eval39.8%

        \[\leadsto \frac{\frac{x \cdot x - \color{blue}{1}}{x + 1}}{\frac{x}{6}} \]
      10. sub-div39.8%

        \[\leadsto \frac{\color{blue}{\frac{x \cdot x}{x + 1} - \frac{1}{x + 1}}}{\frac{x}{6}} \]
      11. div-sub39.8%

        \[\leadsto \color{blue}{\frac{\frac{x \cdot x}{x + 1}}{\frac{x}{6}} - \frac{\frac{1}{x + 1}}{\frac{x}{6}}} \]
      12. div-inv39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{\color{blue}{x \cdot \frac{1}{6}}} - \frac{\frac{1}{x + 1}}{\frac{x}{6}} \]
      13. metadata-eval39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{x \cdot \color{blue}{0.16666666666666666}} - \frac{\frac{1}{x + 1}}{\frac{x}{6}} \]
      14. div-inv39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{x \cdot 0.16666666666666666} - \frac{\frac{1}{x + 1}}{\color{blue}{x \cdot \frac{1}{6}}} \]
      15. metadata-eval39.7%

        \[\leadsto \frac{\frac{x \cdot x}{x + 1}}{x \cdot 0.16666666666666666} - \frac{\frac{1}{x + 1}}{x \cdot \color{blue}{0.16666666666666666}} \]
    6. Applied egg-rr39.7%

      \[\leadsto \color{blue}{\frac{\frac{x \cdot x}{x + 1}}{x \cdot 0.16666666666666666} - \frac{\frac{1}{x + 1}}{x \cdot 0.16666666666666666}} \]
    7. Step-by-step derivation
      1. associate-/l/37.9%

        \[\leadsto \color{blue}{\frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(x + 1\right)}} - \frac{\frac{1}{x + 1}}{x \cdot 0.16666666666666666} \]
      2. +-commutative37.9%

        \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \color{blue}{\left(1 + x\right)}} - \frac{\frac{1}{x + 1}}{x \cdot 0.16666666666666666} \]
      3. associate-/l/37.9%

        \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \color{blue}{\frac{1}{\left(x \cdot 0.16666666666666666\right) \cdot \left(x + 1\right)}} \]
      4. +-commutative37.9%

        \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \frac{1}{\left(x \cdot 0.16666666666666666\right) \cdot \color{blue}{\left(1 + x\right)}} \]
    8. Simplified37.9%

      \[\leadsto \color{blue}{\frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \frac{1}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)}} \]
    9. Taylor expanded in x around 0 37.9%

      \[\leadsto \frac{x \cdot x}{\left(x \cdot 0.16666666666666666\right) \cdot \left(1 + x\right)} - \color{blue}{\frac{6}{x}} \]
    10. Taylor expanded in x around inf 94.7%

      \[\leadsto \color{blue}{6 - 12 \cdot \frac{1}{x}} \]
    11. Step-by-step derivation
      1. associate-*r/94.7%

        \[\leadsto 6 - \color{blue}{\frac{12 \cdot 1}{x}} \]
      2. metadata-eval94.7%

        \[\leadsto 6 - \frac{\color{blue}{12}}{x} \]
    12. Simplified94.7%

      \[\leadsto \color{blue}{6 - \frac{12}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;-6 \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \]

Alternative 9: 95.5% accurate, 36.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6\\ \mathbf{else}:\\ \;\;\;\;6\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 1.0) -6.0 6.0))
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0;
	} else {
		tmp = 6.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = -6.0d0
    else
        tmp = 6.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0;
	} else {
		tmp = 6.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = -6.0
	else:
		tmp = 6.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = -6.0;
	else
		tmp = 6.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = -6.0;
	else
		tmp = 6.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 1.0], -6.0, 6.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;-6\\

\mathbf{else}:\\
\;\;\;\;6\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. sub-neg99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. +-commutative99.9%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
      4. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      5. fma-def99.9%

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

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      7. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

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

      \[\leadsto \color{blue}{-6} \]

    if 1 < x

    1. Initial program 99.0%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.8%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. sub-neg99.8%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. +-commutative99.8%

        \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
      4. +-commutative99.8%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      5. fma-def99.8%

        \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
      6. +-commutative99.8%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      7. metadata-eval99.8%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.8%

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

      \[\leadsto \color{blue}{6} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6\\ \mathbf{else}:\\ \;\;\;\;6\\ \end{array} \]

Alternative 10: 49.3% accurate, 113.0× speedup?

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

\\
-6
\end{array}
Derivation
  1. Initial program 99.5%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. associate-*l/99.8%

      \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
    2. sub-neg99.8%

      \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
    3. +-commutative99.8%

      \[\leadsto \frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \color{blue}{\left(\left(-1\right) + x\right)} \]
    4. +-commutative99.8%

      \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
    5. fma-def99.8%

      \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(\left(-1\right) + x\right) \]
    6. +-commutative99.8%

      \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
    7. metadata-eval99.8%

      \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
  3. Simplified99.8%

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

    \[\leadsto \color{blue}{-6} \]
  5. Final simplification47.8%

    \[\leadsto -6 \]

Developer target: 99.9% accurate, 1.0× speedup?

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

\\
\frac{6}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}
\end{array}

Reproduce

?
herbie shell --seed 2023297 
(FPCore (x)
  :name "Data.Approximate.Numerics:blog from approximate-0.2.2.1"
  :precision binary64

  :herbie-target
  (/ 6.0 (/ (+ (+ x 1.0) (* 4.0 (sqrt x))) (- x 1.0)))

  (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))