Average Error: 12.1 → 2.7
Time: 4.8s
Precision: binary64
Cost: 712
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-166}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq 10^{-265}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (if (<= y -1e-166)
   (* x (- 1.0 (/ z y)))
   (if (<= y 1e-265) (- x (/ (* x z) y)) (/ x (/ y (- y z))))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1e-166) {
		tmp = x * (1.0 - (z / y));
	} else if (y <= 1e-265) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x / (y / (y - z));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * (y - z)) / y
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1d-166)) then
        tmp = x * (1.0d0 - (z / y))
    else if (y <= 1d-265) then
        tmp = x - ((x * z) / y)
    else
        tmp = x / (y / (y - z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1e-166) {
		tmp = x * (1.0 - (z / y));
	} else if (y <= 1e-265) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x / (y / (y - z));
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	tmp = 0
	if y <= -1e-166:
		tmp = x * (1.0 - (z / y))
	elif y <= 1e-265:
		tmp = x - ((x * z) / y)
	else:
		tmp = x / (y / (y - z))
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	tmp = 0.0
	if (y <= -1e-166)
		tmp = Float64(x * Float64(1.0 - Float64(z / y)));
	elseif (y <= 1e-265)
		tmp = Float64(x - Float64(Float64(x * z) / y));
	else
		tmp = Float64(x / Float64(y / Float64(y - z)));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (y - z)) / y;
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1e-166)
		tmp = x * (1.0 - (z / y));
	elseif (y <= 1e-265)
		tmp = x - ((x * z) / y);
	else
		tmp = x / (y / (y - z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, -1e-166], N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1e-265], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-166}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\

\mathbf{elif}\;y \leq 10^{-265}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.1
Target3.1
Herbie2.7
\[\begin{array}{l} \mathbf{if}\;z < -2.060202331921739 \cdot 10^{+104}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{elif}\;z < 1.6939766013828526 \cdot 10^{+213}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if y < -1.00000000000000004e-166

    1. Initial program 12.5

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

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Applied egg-rr1.6

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

    if -1.00000000000000004e-166 < y < 9.99999999999999985e-266

    1. Initial program 9.5

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified13.0

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Taylor expanded in z around 0 7.3

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

    if 9.99999999999999985e-266 < y

    1. Initial program 12.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied egg-rr12.5

      \[\leadsto \color{blue}{\left(x \cdot \left(y - z\right)\right) \cdot \frac{1}{y}} \]
    3. Applied egg-rr2.7

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.7

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

Alternatives

Alternative 1
Error20.8
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{-178}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-61}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error19.4
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{-169}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-61}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error3.2
Cost448
\[\frac{x}{\frac{y}{y - z}} \]
Alternative 4
Error25.4
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022217 
(FPCore (x y z)
  :name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))

  (/ (* x (- y z)) y))