Average Error: 15.2 → 0.2
Time: 1.6s
Precision: binary64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
\[{\left(\frac{0.5}{y} + \frac{-0.5}{x}\right)}^{-1} \]
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y) :precision binary64 (pow (+ (/ 0.5 y) (/ -0.5 x)) -1.0))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
	return pow(((0.5 / y) + (-0.5 / x)), -1.0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * 2.0d0) * y) / (x - y)
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((0.5d0 / y) + ((-0.5d0) / x)) ** (-1.0d0)
end function
public static double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
public static double code(double x, double y) {
	return Math.pow(((0.5 / y) + (-0.5 / x)), -1.0);
}
def code(x, y):
	return ((x * 2.0) * y) / (x - y)
def code(x, y):
	return math.pow(((0.5 / y) + (-0.5 / x)), -1.0)
function code(x, y)
	return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
end
function code(x, y)
	return Float64(Float64(0.5 / y) + Float64(-0.5 / x)) ^ -1.0
end
function tmp = code(x, y)
	tmp = ((x * 2.0) * y) / (x - y);
end
function tmp = code(x, y)
	tmp = ((0.5 / y) + (-0.5 / x)) ^ -1.0;
end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[Power[N[(N[(0.5 / y), $MachinePrecision] + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
{\left(\frac{0.5}{y} + \frac{-0.5}{x}\right)}^{-1}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.2
Target0.3
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x < 83645045635564430:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array} \]

Derivation

  1. Initial program 15.2

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

    \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}} \]
  3. Applied egg-rr7.6

    \[\leadsto \color{blue}{{\left(\frac{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}{x}\right)}^{-1}} \]
  4. Taylor expanded in x around 0 0.2

    \[\leadsto {\color{blue}{\left(0.5 \cdot \frac{1}{y} - 0.5 \cdot \frac{1}{x}\right)}}^{-1} \]
  5. Simplified0.2

    \[\leadsto {\color{blue}{\left(\frac{0.5}{y} + \frac{-0.5}{x}\right)}}^{-1} \]
  6. Final simplification0.2

    \[\leadsto {\left(\frac{0.5}{y} + \frac{-0.5}{x}\right)}^{-1} \]

Reproduce

herbie shell --seed 2022153 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))