?

Average Error: 0.2 → 0.1
Time: 1.9min
Precision: binary64
Cost: 20036

?

\[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(4, \sqrt{x}, x - -1\right)\\ \mathbf{if}\;x - 1 \ne 0:\\ \;\;\;\;\frac{-6}{\frac{t_0}{1 - x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(6, x, -6\right)}{t_0}\\ \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (fma 4.0 (sqrt x) (- x -1.0))))
   (if (!= (- x 1.0) 0.0)
     (/ -6.0 (/ t_0 (- 1.0 x)))
     (/ (fma 6.0 x -6.0) t_0))))
double code(double x) {
	return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
double code(double x) {
	double t_0 = fma(4.0, sqrt(x), (x - -1.0));
	double tmp;
	if ((x - 1.0) != 0.0) {
		tmp = -6.0 / (t_0 / (1.0 - x));
	} else {
		tmp = fma(6.0, x, -6.0) / t_0;
	}
	return tmp;
}
function code(x)
	return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x))))
end
function code(x)
	t_0 = fma(4.0, sqrt(x), Float64(x - -1.0))
	tmp = 0.0
	if (Float64(x - 1.0) != 0.0)
		tmp = Float64(-6.0 / Float64(t_0 / Float64(1.0 - x)));
	else
		tmp = Float64(fma(6.0, x, -6.0) / t_0);
	end
	return tmp
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]
code[x_] := Block[{t$95$0 = N[(4.0 * N[Sqrt[x], $MachinePrecision] + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, If[Unequal[N[(x - 1.0), $MachinePrecision], 0.0], N[(-6.0 / N[(t$95$0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(6.0 * x + -6.0), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\begin{array}{l}
t_0 := \mathsf{fma}\left(4, \sqrt{x}, x - -1\right)\\
\mathbf{if}\;x - 1 \ne 0:\\
\;\;\;\;\frac{-6}{\frac{t_0}{1 - x}}\\

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


\end{array}

Error?

Target

Original0.2
Target0.1
Herbie0.1
\[\frac{6}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}} \]

Derivation?

  1. Initial program 0.2

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Applied egg-rr0.1

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;-1 + x \ne 0:\\ \;\;\;\;\frac{-6}{\frac{-1 - \mathsf{fma}\left(\sqrt{x}, 4, x\right)}{-1 + x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(6, x, -6\right)}{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right)}\\ } \end{array}} \]
  3. Simplified0.1

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;x - 1 \ne 0:\\ \;\;\;\;\frac{-6}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x - -1\right)}{1 - x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(6, x, -6\right)}{\mathsf{fma}\left(4, \sqrt{x}, x - -1\right)}\\ } \end{array}} \]
    Proof

Alternatives

Alternative 1
Error0.1
Cost7232
\[\frac{-6}{-1 - \left(4 \cdot \sqrt{x} + x\right)} \cdot \left(-1 + x\right) \]
Alternative 2
Error0.0
Cost7232
\[\frac{1 - x}{-1 - \left(4 \cdot \sqrt{x} + x\right)} \cdot 6 \]
Alternative 3
Error3.0
Cost576
\[\frac{-6}{-1 - x} \cdot \left(-1 + x\right) \]
Alternative 4
Error2.9
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6\\ \mathbf{else}:\\ \;\;\;\;6 + \frac{-12}{x}\\ \end{array} \]
Alternative 5
Error2.9
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;12 \cdot x - 6\\ \mathbf{else}:\\ \;\;\;\;6 + \frac{-12}{x}\\ \end{array} \]
Alternative 6
Error2.9
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6\\ \mathbf{else}:\\ \;\;\;\;6\\ \end{array} \]
Alternative 7
Error32.7
Cost64
\[-6 \]

Error

Reproduce?

herbie shell --seed 2023033 
(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)))))