?

Average Error: 13.16% → 0.13%
Time: 2.3s
Precision: binary64
Cost: 712

?

\[\frac{x \cdot y}{y + 1} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+50}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 145000000:\\ \;\;\;\;y \cdot \frac{x}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{y}\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* x y) (+ y 1.0)))
(FPCore (x y)
 :precision binary64
 (if (<= y -6.5e+50)
   x
   (if (<= y 145000000.0) (* y (/ x (+ y 1.0))) (- x (/ x y)))))
double code(double x, double y) {
	return (x * y) / (y + 1.0);
}
double code(double x, double y) {
	double tmp;
	if (y <= -6.5e+50) {
		tmp = x;
	} else if (y <= 145000000.0) {
		tmp = y * (x / (y + 1.0));
	} else {
		tmp = x - (x / y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (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) :: tmp
    if (y <= (-6.5d+50)) then
        tmp = x
    else if (y <= 145000000.0d0) then
        tmp = y * (x / (y + 1.0d0))
    else
        tmp = x - (x / y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return (x * y) / (y + 1.0);
}
public static double code(double x, double y) {
	double tmp;
	if (y <= -6.5e+50) {
		tmp = x;
	} else if (y <= 145000000.0) {
		tmp = y * (x / (y + 1.0));
	} else {
		tmp = x - (x / y);
	}
	return tmp;
}
def code(x, y):
	return (x * y) / (y + 1.0)
def code(x, y):
	tmp = 0
	if y <= -6.5e+50:
		tmp = x
	elif y <= 145000000.0:
		tmp = y * (x / (y + 1.0))
	else:
		tmp = x - (x / y)
	return tmp
function code(x, y)
	return Float64(Float64(x * y) / Float64(y + 1.0))
end
function code(x, y)
	tmp = 0.0
	if (y <= -6.5e+50)
		tmp = x;
	elseif (y <= 145000000.0)
		tmp = Float64(y * Float64(x / Float64(y + 1.0)));
	else
		tmp = Float64(x - Float64(x / y));
	end
	return tmp
end
function tmp = code(x, y)
	tmp = (x * y) / (y + 1.0);
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -6.5e+50)
		tmp = x;
	elseif (y <= 145000000.0)
		tmp = y * (x / (y + 1.0));
	else
		tmp = x - (x / y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[y, -6.5e+50], x, If[LessEqual[y, 145000000.0], N[(y * N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+50}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 145000000:\\
\;\;\;\;y \cdot \frac{x}{y + 1}\\

\mathbf{else}:\\
\;\;\;\;x - \frac{x}{y}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original13.16%
Target0.06%
Herbie0.13%
\[\begin{array}{l} \mathbf{if}\;y < -3693.8482788297247:\\ \;\;\;\;\frac{x}{y \cdot y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y < 6799310503.41891:\\ \;\;\;\;\frac{x \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot y} - \left(\frac{x}{y} - x\right)\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if y < -6.5000000000000003e50

    1. Initial program 30.56

      \[\frac{x \cdot y}{y + 1} \]
    2. Simplified0

      \[\leadsto \color{blue}{\frac{x}{\frac{y + 1}{y}}} \]
      Proof

      [Start]30.56

      \[ \frac{x \cdot y}{y + 1} \]

      associate-/l* [=>]0

      \[ \color{blue}{\frac{x}{\frac{y + 1}{y}}} \]
    3. Taylor expanded in y around inf 0

      \[\leadsto \color{blue}{x} \]

    if -6.5000000000000003e50 < y < 1.45e8

    1. Initial program 0.29

      \[\frac{x \cdot y}{y + 1} \]
    2. Simplified0.37

      \[\leadsto \color{blue}{\frac{x}{\frac{y + 1}{y}}} \]
      Proof

      [Start]0.29

      \[ \frac{x \cdot y}{y + 1} \]

      associate-/l* [=>]0.37

      \[ \color{blue}{\frac{x}{\frac{y + 1}{y}}} \]
    3. Applied egg-rr0.25

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

    if 1.45e8 < y

    1. Initial program 26.83

      \[\frac{x \cdot y}{y + 1} \]
    2. Simplified0.02

      \[\leadsto \color{blue}{\frac{x}{\frac{y + 1}{y}}} \]
      Proof

      [Start]26.83

      \[ \frac{x \cdot y}{y + 1} \]

      associate-/l* [=>]0.02

      \[ \color{blue}{\frac{x}{\frac{y + 1}{y}}} \]
    3. Taylor expanded in y around inf 0

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

      \[\leadsto \color{blue}{x - \frac{x}{y}} \]
      Proof

      [Start]0

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

      +-commutative [=>]0

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

      mul-1-neg [=>]0

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

      unsub-neg [=>]0

      \[ \color{blue}{x - \frac{x}{y}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.13

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+50}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 145000000:\\ \;\;\;\;y \cdot \frac{x}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{y}\\ \end{array} \]

Alternatives

Alternative 1
Error1.47%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.3\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Error2.04%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error0.21%
Cost448
\[\frac{x}{\frac{y + 1}{y}} \]
Alternative 4
Error48.73%
Cost64
\[x \]

Error

Reproduce?

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

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

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