?

Average Error: 22.1 → 0.3
Time: 16.1s
Precision: binary64
Cost: 22152

?

\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{\left(1 - x\right) \cdot y}{y + 1}\\ t_1 := 1 - \left(1 - x\right) \cdot \frac{y}{1 + y}\\ \mathbf{if}\;t_0 \leq 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2:\\ \;\;\;\;\frac{x}{{y}^{2}} + \left(\left(x + \left(-\frac{x + -1}{y}\right)\right) + \left(\left(-\frac{x + -1}{{y}^{3}}\right) - \frac{1}{{y}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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) (+ y 1.0)))
        (t_1 (- 1.0 (* (- 1.0 x) (/ y (+ 1.0 y))))))
   (if (<= t_0 1e-5)
     t_1
     (if (<= t_0 2.0)
       (+
        (/ x (pow y 2.0))
        (+
         (+ x (- (/ (+ x -1.0) y)))
         (- (- (/ (+ x -1.0) (pow y 3.0))) (/ 1.0 (pow y 2.0)))))
       t_1))))
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) / (y + 1.0);
	double t_1 = 1.0 - ((1.0 - x) * (y / (1.0 + y)));
	double tmp;
	if (t_0 <= 1e-5) {
		tmp = t_1;
	} else if (t_0 <= 2.0) {
		tmp = (x / pow(y, 2.0)) + ((x + -((x + -1.0) / y)) + (-((x + -1.0) / pow(y, 3.0)) - (1.0 / pow(y, 2.0))));
	} else {
		tmp = t_1;
	}
	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) :: tmp
    t_0 = ((1.0d0 - x) * y) / (y + 1.0d0)
    t_1 = 1.0d0 - ((1.0d0 - x) * (y / (1.0d0 + y)))
    if (t_0 <= 1d-5) then
        tmp = t_1
    else if (t_0 <= 2.0d0) then
        tmp = (x / (y ** 2.0d0)) + ((x + -((x + (-1.0d0)) / y)) + (-((x + (-1.0d0)) / (y ** 3.0d0)) - (1.0d0 / (y ** 2.0d0))))
    else
        tmp = t_1
    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) / (y + 1.0);
	double t_1 = 1.0 - ((1.0 - x) * (y / (1.0 + y)));
	double tmp;
	if (t_0 <= 1e-5) {
		tmp = t_1;
	} else if (t_0 <= 2.0) {
		tmp = (x / Math.pow(y, 2.0)) + ((x + -((x + -1.0) / y)) + (-((x + -1.0) / Math.pow(y, 3.0)) - (1.0 / Math.pow(y, 2.0))));
	} else {
		tmp = t_1;
	}
	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) / (y + 1.0)
	t_1 = 1.0 - ((1.0 - x) * (y / (1.0 + y)))
	tmp = 0
	if t_0 <= 1e-5:
		tmp = t_1
	elif t_0 <= 2.0:
		tmp = (x / math.pow(y, 2.0)) + ((x + -((x + -1.0) / y)) + (-((x + -1.0) / math.pow(y, 3.0)) - (1.0 / math.pow(y, 2.0))))
	else:
		tmp = t_1
	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(y + 1.0))
	t_1 = Float64(1.0 - Float64(Float64(1.0 - x) * Float64(y / Float64(1.0 + y))))
	tmp = 0.0
	if (t_0 <= 1e-5)
		tmp = t_1;
	elseif (t_0 <= 2.0)
		tmp = Float64(Float64(x / (y ^ 2.0)) + Float64(Float64(x + Float64(-Float64(Float64(x + -1.0) / y))) + Float64(Float64(-Float64(Float64(x + -1.0) / (y ^ 3.0))) - Float64(1.0 / (y ^ 2.0)))));
	else
		tmp = t_1;
	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) / (y + 1.0);
	t_1 = 1.0 - ((1.0 - x) * (y / (1.0 + y)));
	tmp = 0.0;
	if (t_0 <= 1e-5)
		tmp = t_1;
	elseif (t_0 <= 2.0)
		tmp = (x / (y ^ 2.0)) + ((x + -((x + -1.0) / y)) + (-((x + -1.0) / (y ^ 3.0)) - (1.0 / (y ^ 2.0))));
	else
		tmp = t_1;
	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[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] * N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], t$95$1, If[LessEqual[t$95$0, 2.0], N[(N[(x / N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x + (-N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision])), $MachinePrecision] + N[((-N[(N[(x + -1.0), $MachinePrecision] / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision]) - N[(1.0 / N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{\left(1 - x\right) \cdot y}{y + 1}\\
t_1 := 1 - \left(1 - x\right) \cdot \frac{y}{1 + y}\\
\mathbf{if}\;t_0 \leq 10^{-5}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original22.1
Target0.2
Herbie0.3
\[\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)) < 1.00000000000000008e-5 or 2 < (/.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.0

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

      [Start]10.8

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

      rational.json-simplify-49 [=>]0.1

      \[ 1 - \color{blue}{y \cdot \frac{1 - x}{y + 1}} \]

      rational.json-simplify-1 [=>]0.1

      \[ 1 - y \cdot \frac{1 - x}{\color{blue}{1 + y}} \]

      rational.json-simplify-17 [=>]0.1

      \[ 1 - y \cdot \frac{1 - x}{\color{blue}{y - -1}} \]

      rational.json-simplify-50 [=>]0.1

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

      rational.json-simplify-8 [=>]0.1

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

      rational.json-simplify-2 [=>]0.1

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

      rational.json-simplify-49 [=>]0.1

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

      rational.json-simplify-43 [=>]0.1

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

      rational.json-simplify-2 [<=]0.1

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

      rational.json-simplify-49 [<=]0.0

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

      rational.json-simplify-2 [<=]0.0

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

      rational.json-simplify-8 [<=]0.0

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

      rational.json-simplify-50 [<=]0.0

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

      rational.json-simplify-17 [<=]0.0

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

    if 1.00000000000000008e-5 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 2

    1. Initial program 56.4

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

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

      [Start]56.4

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

      rational.json-simplify-49 [=>]56.4

      \[ 1 - \color{blue}{y \cdot \frac{1 - x}{y + 1}} \]

      rational.json-simplify-1 [=>]56.4

      \[ 1 - y \cdot \frac{1 - x}{\color{blue}{1 + y}} \]

      rational.json-simplify-17 [=>]56.4

      \[ 1 - y \cdot \frac{1 - x}{\color{blue}{y - -1}} \]

      rational.json-simplify-50 [=>]56.4

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

      rational.json-simplify-8 [=>]56.4

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

      rational.json-simplify-2 [=>]56.4

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

      rational.json-simplify-49 [=>]56.5

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

      rational.json-simplify-43 [=>]56.5

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

      rational.json-simplify-2 [<=]56.5

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

      rational.json-simplify-49 [<=]56.4

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

      rational.json-simplify-2 [<=]56.4

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

      rational.json-simplify-8 [<=]56.4

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

      rational.json-simplify-50 [<=]56.4

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

      rational.json-simplify-17 [<=]56.4

      \[ 1 - \left(1 - x\right) \cdot \frac{y}{\color{blue}{1 + y}} \]
    3. Taylor expanded in y around -inf 1.4

      \[\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}}} \]
    4. Simplified1.3

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

      [Start]1.4

      \[ \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}} \]

      rational.json-simplify-1 [=>]1.4

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

      rational.json-simplify-48 [=>]1.4

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

      rational.json-simplify-41 [=>]1.4

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

      rational.json-simplify-1 [<=]1.4

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

      rational.json-simplify-48 [=>]1.3

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

      rational.json-simplify-1 [=>]1.3

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

      rational.json-simplify-2 [=>]1.3

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

      rational.json-simplify-9 [=>]1.3

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

      rational.json-simplify-15 [<=]1.3

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

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

Alternatives

Alternative 1
Error0.4
Cost8840
\[\begin{array}{l} t_0 := \frac{\left(1 - x\right) \cdot y}{y + 1}\\ t_1 := 1 - \left(1 - x\right) \cdot \frac{y}{1 + y}\\ \mathbf{if}\;t_0 \leq 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2:\\ \;\;\;\;\left(x + \frac{1}{y}\right) + \left(\left(-\frac{1 + \left(-x\right)}{{y}^{2}}\right) - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.2
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -30000000000:\\ \;\;\;\;\frac{1}{y} + x\\ \mathbf{elif}\;y \leq 160000000:\\ \;\;\;\;1 - y \cdot \frac{1 - x}{1 + y}\\ \mathbf{else}:\\ \;\;\;\;x + \left(-\frac{x + -1}{y}\right)\\ \end{array} \]
Alternative 3
Error0.2
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -3700000000:\\ \;\;\;\;\frac{1}{y} + x\\ \mathbf{elif}\;y \leq 160000000:\\ \;\;\;\;1 - \left(1 - x\right) \cdot \frac{y}{1 + y}\\ \mathbf{else}:\\ \;\;\;\;x + \left(-\frac{x + -1}{y}\right)\\ \end{array} \]
Alternative 4
Error0.2
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -125000000000:\\ \;\;\;\;\frac{1}{y} + x\\ \mathbf{elif}\;y \leq 240000000:\\ \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + \left(-\frac{x + -1}{y}\right)\\ \end{array} \]
Alternative 5
Error1.1
Cost776
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;\frac{1}{y} + x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \left(1 - x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + \left(-\frac{x + -1}{y}\right)\\ \end{array} \]
Alternative 6
Error1.2
Cost712
\[\begin{array}{l} t_0 := \frac{1}{y} + x\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.82:\\ \;\;\;\;1 - \left(1 - x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error1.4
Cost648
\[\begin{array}{l} t_0 := \frac{1}{y} + x\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error9.0
Cost584
\[\begin{array}{l} t_0 := \frac{1}{y} + x\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.1:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error9.0
Cost584
\[\begin{array}{l} t_0 := \frac{1}{y} + x\\ \mathbf{if}\;y \leq -6 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 40000000:\\ \;\;\;\;\frac{1}{1 + y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error16.5
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.215:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error16.8
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 16000000:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error39.2
Cost64
\[1 \]

Error

Reproduce?

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