?

Average Error: 8.3 → 0.0
Time: 2.5s
Precision: binary64
Cost: 713

?

\[\frac{x \cdot y}{y + 1} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -400000000 \lor \neg \left(y \leq 240000000\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{y + 1}\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* x y) (+ y 1.0)))
(FPCore (x y)
 :precision binary64
 (if (or (<= y -400000000.0) (not (<= y 240000000.0)))
   (- x (/ x y))
   (* y (/ x (+ y 1.0)))))
double code(double x, double y) {
	return (x * y) / (y + 1.0);
}
double code(double x, double y) {
	double tmp;
	if ((y <= -400000000.0) || !(y <= 240000000.0)) {
		tmp = x - (x / y);
	} else {
		tmp = y * (x / (y + 1.0));
	}
	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 <= (-400000000.0d0)) .or. (.not. (y <= 240000000.0d0))) then
        tmp = x - (x / y)
    else
        tmp = y * (x / (y + 1.0d0))
    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 <= -400000000.0) || !(y <= 240000000.0)) {
		tmp = x - (x / y);
	} else {
		tmp = y * (x / (y + 1.0));
	}
	return tmp;
}
def code(x, y):
	return (x * y) / (y + 1.0)
def code(x, y):
	tmp = 0
	if (y <= -400000000.0) or not (y <= 240000000.0):
		tmp = x - (x / y)
	else:
		tmp = y * (x / (y + 1.0))
	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 <= -400000000.0) || !(y <= 240000000.0))
		tmp = Float64(x - Float64(x / y));
	else
		tmp = Float64(y * Float64(x / Float64(y + 1.0)));
	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 <= -400000000.0) || ~((y <= 240000000.0)))
		tmp = x - (x / y);
	else
		tmp = y * (x / (y + 1.0));
	end
	tmp_2 = tmp;
end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[Or[LessEqual[y, -400000000.0], N[Not[LessEqual[y, 240000000.0]], $MachinePrecision]], N[(x - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -400000000 \lor \neg \left(y \leq 240000000\right):\\
\;\;\;\;x - \frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y + 1}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.3
Target0.0
Herbie0.0
\[\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 2 regimes
  2. if y < -4e8 or 2.4e8 < y

    1. Initial program 17.0

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

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

      [Start]17.0

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

      associate-/l* [=>]0.0

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

    if -4e8 < y < 2.4e8

    1. Initial program 0.0

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

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

      [Start]0.0

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

      associate-/l* [=>]0.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -400000000 \lor \neg \left(y \leq 240000000\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{y + 1}\\ \end{array} \]

Alternatives

Alternative 1
Error1.0
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.35\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Error1.3
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.1
Cost448
\[\frac{x}{\frac{y + 1}{y}} \]
Alternative 4
Error31.0
Cost64
\[x \]

Error

Reproduce?

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