Average Error: 22.1 → 0.2
Time: 11.5s
Precision: binary64
Cost: 21000
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;x + t_0\\ \mathbf{elif}\;y \leq 1221.762001520424:\\ \;\;\;\;1 + \frac{y \cdot \left(x + -1\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{x}{{y}^{2}} + \left(t_0 + \left(x + \frac{1 - x}{{y}^{3}}\right)\right)\right) + \frac{-1}{{y}^{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)))
   (if (<= y -201599714860451170.0)
     (+ x t_0)
     (if (<= y 1221.762001520424)
       (+ 1.0 (/ (* y (+ x -1.0)) (+ y 1.0)))
       (+
        (+ (/ x (pow y 2.0)) (+ t_0 (+ x (/ (- 1.0 x) (pow y 3.0)))))
        (/ -1.0 (pow y 2.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;
	double tmp;
	if (y <= -201599714860451170.0) {
		tmp = x + t_0;
	} else if (y <= 1221.762001520424) {
		tmp = 1.0 + ((y * (x + -1.0)) / (y + 1.0));
	} else {
		tmp = ((x / pow(y, 2.0)) + (t_0 + (x + ((1.0 - x) / pow(y, 3.0))))) + (-1.0 / pow(y, 2.0));
	}
	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) :: tmp
    t_0 = (1.0d0 - x) / y
    if (y <= (-201599714860451170.0d0)) then
        tmp = x + t_0
    else if (y <= 1221.762001520424d0) then
        tmp = 1.0d0 + ((y * (x + (-1.0d0))) / (y + 1.0d0))
    else
        tmp = ((x / (y ** 2.0d0)) + (t_0 + (x + ((1.0d0 - x) / (y ** 3.0d0))))) + ((-1.0d0) / (y ** 2.0d0))
    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;
	double tmp;
	if (y <= -201599714860451170.0) {
		tmp = x + t_0;
	} else if (y <= 1221.762001520424) {
		tmp = 1.0 + ((y * (x + -1.0)) / (y + 1.0));
	} else {
		tmp = ((x / Math.pow(y, 2.0)) + (t_0 + (x + ((1.0 - x) / Math.pow(y, 3.0))))) + (-1.0 / Math.pow(y, 2.0));
	}
	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
	tmp = 0
	if y <= -201599714860451170.0:
		tmp = x + t_0
	elif y <= 1221.762001520424:
		tmp = 1.0 + ((y * (x + -1.0)) / (y + 1.0))
	else:
		tmp = ((x / math.pow(y, 2.0)) + (t_0 + (x + ((1.0 - x) / math.pow(y, 3.0))))) + (-1.0 / math.pow(y, 2.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(1.0 - x) / y)
	tmp = 0.0
	if (y <= -201599714860451170.0)
		tmp = Float64(x + t_0);
	elseif (y <= 1221.762001520424)
		tmp = Float64(1.0 + Float64(Float64(y * Float64(x + -1.0)) / Float64(y + 1.0)));
	else
		tmp = Float64(Float64(Float64(x / (y ^ 2.0)) + Float64(t_0 + Float64(x + Float64(Float64(1.0 - x) / (y ^ 3.0))))) + Float64(-1.0 / (y ^ 2.0)));
	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;
	tmp = 0.0;
	if (y <= -201599714860451170.0)
		tmp = x + t_0;
	elseif (y <= 1221.762001520424)
		tmp = 1.0 + ((y * (x + -1.0)) / (y + 1.0));
	else
		tmp = ((x / (y ^ 2.0)) + (t_0 + (x + ((1.0 - x) / (y ^ 3.0))))) + (-1.0 / (y ^ 2.0));
	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[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[y, -201599714860451170.0], N[(x + t$95$0), $MachinePrecision], If[LessEqual[y, 1221.762001520424], N[(1.0 + N[(N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 + N[(x + N[(N[(1.0 - x), $MachinePrecision] / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{1 - x}{y}\\
\mathbf{if}\;y \leq -201599714860451170:\\
\;\;\;\;x + t_0\\

\mathbf{elif}\;y \leq 1221.762001520424:\\
\;\;\;\;1 + \frac{y \cdot \left(x + -1\right)}{y + 1}\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{x}{{y}^{2}} + \left(t_0 + \left(x + \frac{1 - x}{{y}^{3}}\right)\right)\right) + \frac{-1}{{y}^{2}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original22.1
Target0.2
Herbie0.2
\[\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 y < -201599714860451168

    1. Initial program 45.8

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Taylor expanded in y around inf 0.0

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

      \[\leadsto \color{blue}{x + \frac{1 - x}{y}} \]
      Proof
      (+.f64 x (/.f64 (-.f64 1 x) y)): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite=> div-sub_binary64 (-.f64 (/.f64 1 y) (/.f64 x y)))): 1 points increase in error, 1 points decrease in error
      (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 x (/.f64 1 y)) (/.f64 x y))): 1 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 1 y) x)) (/.f64 x y)): 0 points increase in error, 0 points decrease in error

    if -201599714860451168 < y < 1221.76200152042406

    1. Initial program 0.4

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

    if 1221.76200152042406 < y

    1. Initial program 44.8

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Taylor expanded in y around -inf 0.1

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

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

Alternatives

Alternative 1
Error0.2
Cost1608
\[\begin{array}{l} t_0 := x + \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1221.762001520424:\\ \;\;\;\;1 + \frac{y \cdot \left(x + -1\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{x + -1}{y \cdot y} \cdot \left(1 - \frac{1}{y}\right)\\ \end{array} \]
Alternative 2
Error0.2
Cost1096
\[\begin{array}{l} t_0 := \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;x + t_0\\ \mathbf{elif}\;y \leq 97966.40980302799:\\ \;\;\;\;1 + \frac{y \cdot \left(x + -1\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + t_0 \cdot \left(1 - \frac{1}{y}\right)\\ \end{array} \]
Alternative 3
Error0.3
Cost968
\[\begin{array}{l} t_0 := x + \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 38357552.01592997:\\ \;\;\;\;1 + \frac{y \cdot \left(x + -1\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.1
Cost840
\[\begin{array}{l} t_0 := x + \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 97966.40980302799:\\ \;\;\;\;1 + \frac{y \cdot x}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.8
Cost712
\[\begin{array}{l} t_0 := x + \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.5102899063254773:\\ \;\;\;\;1 + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error1.7
Cost712
\[\begin{array}{l} t_0 := x + \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.5102899063254773:\\ \;\;\;\;1 + \left(y \cdot x - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error9.5
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1221.762001520424:\\ \;\;\;\;1 + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error9.5
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1221.762001520424:\\ \;\;\;\;1 + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{y}\\ \end{array} \]
Alternative 9
Error16.9
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.12033959919243467:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error17.1
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -201599714860451170:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.12033959919243467:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error39.0
Cost64
\[1 \]

Error

Reproduce

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