Average Error: 22.5 → 0.4
Time: 2.9s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\ t_1 := \frac{y}{-1 - y}\\ \mathbf{if}\;t_0 \leq 0.1:\\ \;\;\;\;\mathsf{fma}\left(1 - x, \mathsf{expm1}\left(\mathsf{log1p}\left(t_1\right)\right), 1\right)\\ \mathbf{elif}\;t_0 \leq 1.01:\\ \;\;\;\;x + \left(\left(\frac{1}{{y}^{3}} + \frac{x + -1}{y \cdot y}\right) + \left(\frac{1 - x}{y} - \frac{x}{{y}^{3}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1 - x, t_1, 1\right)\\ \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- 1.0 x) y) (+ 1.0 y))) (t_1 (/ y (- -1.0 y))))
   (if (<= t_0 0.1)
     (fma (- 1.0 x) (expm1 (log1p t_1)) 1.0)
     (if (<= t_0 1.01)
       (+
        x
        (+
         (+ (/ 1.0 (pow y 3.0)) (/ (+ x -1.0) (* y y)))
         (- (/ (- 1.0 x) y) (/ x (pow y 3.0)))))
       (fma (- 1.0 x) t_1 1.0)))))
double code(double x, double y) {
	return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
	double t_0 = ((1.0 - x) * y) / (1.0 + y);
	double t_1 = y / (-1.0 - y);
	double tmp;
	if (t_0 <= 0.1) {
		tmp = fma((1.0 - x), expm1(log1p(t_1)), 1.0);
	} else if (t_0 <= 1.01) {
		tmp = x + (((1.0 / pow(y, 3.0)) + ((x + -1.0) / (y * y))) + (((1.0 - x) / y) - (x / pow(y, 3.0))));
	} else {
		tmp = fma((1.0 - x), t_1, 1.0);
	}
	return tmp;
}
function code(x, y)
	return Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0)))
end
function code(x, y)
	t_0 = Float64(Float64(Float64(1.0 - x) * y) / Float64(1.0 + y))
	t_1 = Float64(y / Float64(-1.0 - y))
	tmp = 0.0
	if (t_0 <= 0.1)
		tmp = fma(Float64(1.0 - x), expm1(log1p(t_1)), 1.0);
	elseif (t_0 <= 1.01)
		tmp = Float64(x + Float64(Float64(Float64(1.0 / (y ^ 3.0)) + Float64(Float64(x + -1.0) / Float64(y * y))) + Float64(Float64(Float64(1.0 - x) / y) - Float64(x / (y ^ 3.0)))));
	else
		tmp = fma(Float64(1.0 - x), t_1, 1.0);
	end
	return tmp
end
code[x_, y_] := N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(-1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.1], N[(N[(1.0 - x), $MachinePrecision] * N[(Exp[N[Log[1 + t$95$1], $MachinePrecision]] - 1), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$0, 1.01], N[(x + N[(N[(N[(1.0 / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x + -1.0), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision] - N[(x / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * t$95$1 + 1.0), $MachinePrecision]]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_1 := \frac{y}{-1 - y}\\
\mathbf{if}\;t_0 \leq 0.1:\\
\;\;\;\;\mathsf{fma}\left(1 - x, \mathsf{expm1}\left(\mathsf{log1p}\left(t_1\right)\right), 1\right)\\

\mathbf{elif}\;t_0 \leq 1.01:\\
\;\;\;\;x + \left(\left(\frac{1}{{y}^{3}} + \frac{x + -1}{y \cdot y}\right) + \left(\frac{1 - x}{y} - \frac{x}{{y}^{3}}\right)\right)\\

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


\end{array}

Error

Target

Original22.5
Target0.2
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;y < -3693.8482788297247:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y < 6799310503.41891:\\ \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 0.10000000000000001

    1. Initial program 7.1

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, \frac{y}{-1 - y}, 1\right)} \]
    3. Applied egg-rr0.4

      \[\leadsto \mathsf{fma}\left(1 - x, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y}{-1 - y}\right)\right)}, 1\right) \]

    if 0.10000000000000001 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 1.01000000000000001

    1. Initial program 57.8

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Simplified57.8

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

      \[\leadsto \color{blue}{\left(\frac{1}{y} + \left(1 + \left(-1 \cdot \left(1 - x\right) + \left(\frac{1}{{y}^{3}} + -1 \cdot \frac{1 - x}{{y}^{2}}\right)\right)\right)\right) - \left(\frac{x}{{y}^{3}} + \frac{x}{y}\right)} \]
    4. Simplified0.4

      \[\leadsto \color{blue}{x + \left(\left(\frac{1}{{y}^{3}} - \frac{1 - x}{y \cdot y}\right) + \left(\frac{1 - x}{y} - \frac{x}{{y}^{3}}\right)\right)} \]

    if 1.01000000000000001 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))

    1. Initial program 22.0

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Simplified0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 0.1:\\ \;\;\;\;\mathsf{fma}\left(1 - x, \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y}{-1 - y}\right)\right), 1\right)\\ \mathbf{elif}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 1.01:\\ \;\;\;\;x + \left(\left(\frac{1}{{y}^{3}} + \frac{x + -1}{y \cdot y}\right) + \left(\frac{1 - x}{y} - \frac{x}{{y}^{3}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1 - x, \frac{y}{-1 - y}, 1\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022212 
(FPCore (x y)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, D"
  :precision binary64

  :herbie-target
  (if (< y -3693.8482788297247) (- (/ 1.0 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) (- (/ 1.0 y) (- (/ x y) x))))

  (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))