Average Error: 22.1 → 0.0
Time: 3.5s
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}\\ t_2 := x \cdot t_1 + \left(1 - t_1\right)\\ \mathbf{if}\;t_0 \leq 0.9917361766273673:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_0 \leq 1.000018514059526:\\ \;\;\;\;\left(\left(x + \frac{x}{y \cdot y}\right) + \frac{1}{{y}^{3}}\right) - \left(\frac{x}{{y}^{3}} + \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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)))
        (t_2 (+ (* x t_1) (- 1.0 t_1))))
   (if (<= t_0 0.9917361766273673)
     t_2
     (if (<= t_0 1.000018514059526)
       (-
        (+ (+ x (/ x (* y y))) (/ 1.0 (pow y 3.0)))
        (+ (/ x (pow y 3.0)) (+ (/ 1.0 (* y y)) (/ (+ x -1.0) y))))
       t_2))))
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 t_2 = (x * t_1) + (1.0 - t_1);
	double tmp;
	if (t_0 <= 0.9917361766273673) {
		tmp = t_2;
	} else if (t_0 <= 1.000018514059526) {
		tmp = ((x + (x / (y * y))) + (1.0 / pow(y, 3.0))) - ((x / pow(y, 3.0)) + ((1.0 / (y * y)) + ((x + -1.0) / y)));
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 1.0d0 - (((1.0d0 - x) * y) / (y + 1.0d0))
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = ((1.0d0 - x) * y) / (1.0d0 + y)
    t_1 = y / (1.0d0 + y)
    t_2 = (x * t_1) + (1.0d0 - t_1)
    if (t_0 <= 0.9917361766273673d0) then
        tmp = t_2
    else if (t_0 <= 1.000018514059526d0) then
        tmp = ((x + (x / (y * y))) + (1.0d0 / (y ** 3.0d0))) - ((x / (y ** 3.0d0)) + ((1.0d0 / (y * y)) + ((x + (-1.0d0)) / y)))
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
public static double code(double x, double y) {
	double t_0 = ((1.0 - x) * y) / (1.0 + y);
	double t_1 = y / (1.0 + y);
	double t_2 = (x * t_1) + (1.0 - t_1);
	double tmp;
	if (t_0 <= 0.9917361766273673) {
		tmp = t_2;
	} else if (t_0 <= 1.000018514059526) {
		tmp = ((x + (x / (y * y))) + (1.0 / Math.pow(y, 3.0))) - ((x / Math.pow(y, 3.0)) + ((1.0 / (y * y)) + ((x + -1.0) / y)));
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y):
	return 1.0 - (((1.0 - x) * y) / (y + 1.0))
def code(x, y):
	t_0 = ((1.0 - x) * y) / (1.0 + y)
	t_1 = y / (1.0 + y)
	t_2 = (x * t_1) + (1.0 - t_1)
	tmp = 0
	if t_0 <= 0.9917361766273673:
		tmp = t_2
	elif t_0 <= 1.000018514059526:
		tmp = ((x + (x / (y * y))) + (1.0 / math.pow(y, 3.0))) - ((x / math.pow(y, 3.0)) + ((1.0 / (y * y)) + ((x + -1.0) / y)))
	else:
		tmp = t_2
	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))
	t_2 = Float64(Float64(x * t_1) + Float64(1.0 - t_1))
	tmp = 0.0
	if (t_0 <= 0.9917361766273673)
		tmp = t_2;
	elseif (t_0 <= 1.000018514059526)
		tmp = Float64(Float64(Float64(x + Float64(x / Float64(y * y))) + Float64(1.0 / (y ^ 3.0))) - Float64(Float64(x / (y ^ 3.0)) + Float64(Float64(1.0 / Float64(y * y)) + Float64(Float64(x + -1.0) / y))));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp = code(x, y)
	tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0));
end
function tmp_2 = code(x, y)
	t_0 = ((1.0 - x) * y) / (1.0 + y);
	t_1 = y / (1.0 + y);
	t_2 = (x * t_1) + (1.0 - t_1);
	tmp = 0.0;
	if (t_0 <= 0.9917361766273673)
		tmp = t_2;
	elseif (t_0 <= 1.000018514059526)
		tmp = ((x + (x / (y * y))) + (1.0 / (y ^ 3.0))) - ((x / (y ^ 3.0)) + ((1.0 / (y * y)) + ((x + -1.0) / y)));
	else
		tmp = t_2;
	end
	tmp_2 = 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]}, Block[{t$95$2 = N[(N[(x * t$95$1), $MachinePrecision] + N[(1.0 - t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.9917361766273673], t$95$2, If[LessEqual[t$95$0, 1.000018514059526], N[(N[(N[(x + N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(x / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
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}\\
t_2 := x \cdot t_1 + \left(1 - t_1\right)\\
\mathbf{if}\;t_0 \leq 0.9917361766273673:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original22.1
Target0.2
Herbie0.0
\[\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 2 regimes
  2. if (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 0.99173617662736735 or 1.0000185140595259 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))

    1. Initial program 10.8

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

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

      \[\leadsto \color{blue}{y \cdot \frac{x + -1}{1 + y} + 1} \]
    4. Simplified0.1

      \[\leadsto \color{blue}{\frac{y}{1 + y} \cdot \left(x + -1\right)} + 1 \]
    5. Applied distribute-lft-in_binary640.1

      \[\leadsto \color{blue}{\left(\frac{y}{1 + y} \cdot x + \frac{y}{1 + y} \cdot -1\right)} + 1 \]
    6. Applied associate-+l+_binary640.0

      \[\leadsto \color{blue}{\frac{y}{1 + y} \cdot x + \left(\frac{y}{1 + y} \cdot -1 + 1\right)} \]
    7. Simplified0.0

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

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

    1. Initial program 58.7

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

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

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

      \[\leadsto \color{blue}{\left(\left(x + \frac{x}{y \cdot y}\right) + \frac{1}{{y}^{3}}\right) - \left(\frac{x}{{y}^{3}} + \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 0.9917361766273673:\\ \;\;\;\;x \cdot \frac{y}{1 + y} + \left(1 - \frac{y}{1 + y}\right)\\ \mathbf{elif}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 1.000018514059526:\\ \;\;\;\;\left(\left(x + \frac{x}{y \cdot y}\right) + \frac{1}{{y}^{3}}\right) - \left(\frac{x}{{y}^{3}} + \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{1 + y} + \left(1 - \frac{y}{1 + y}\right)\\ \end{array} \]

Reproduce

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