Average Error: 12.5 → 1.7
Time: 5.7s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq 6.240358642528451 \cdot 10^{-273}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_0 \leq 4.160283441989339 \cdot 10^{+303}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{z}{y}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (- y z)) y)))
   (if (<= t_0 6.240358642528451e-273)
     (/ x (/ y (- y z)))
     (if (<= t_0 4.160283441989339e+303)
       (- x (/ (* x z) y))
       (- x (* x (/ z y)))))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double t_0 = (x * (y - z)) / y;
	double tmp;
	if (t_0 <= 6.240358642528451e-273) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 4.160283441989339e+303) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x - (x * (z / y));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (x * (y - z)) / y
    if (t_0 <= 6.240358642528451d-273) then
        tmp = x / (y / (y - z))
    else if (t_0 <= 4.160283441989339d+303) then
        tmp = x - ((x * z) / y)
    else
        tmp = x - (x * (z / y))
    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 t_0 = (x * (y - z)) / y;
	double tmp;
	if (t_0 <= 6.240358642528451e-273) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 4.160283441989339e+303) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x - (x * (z / y));
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	t_0 = (x * (y - z)) / y
	tmp = 0
	if t_0 <= 6.240358642528451e-273:
		tmp = x / (y / (y - z))
	elif t_0 <= 4.160283441989339e+303:
		tmp = x - ((x * z) / y)
	else:
		tmp = x - (x * (z / y))
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	t_0 = Float64(Float64(x * Float64(y - z)) / y)
	tmp = 0.0
	if (t_0 <= 6.240358642528451e-273)
		tmp = Float64(x / Float64(y / Float64(y - z)));
	elseif (t_0 <= 4.160283441989339e+303)
		tmp = Float64(x - Float64(Float64(x * z) / y));
	else
		tmp = Float64(x - Float64(x * Float64(z / y)));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (y - z)) / y;
end
function tmp_2 = code(x, y, z)
	t_0 = (x * (y - z)) / y;
	tmp = 0.0;
	if (t_0 <= 6.240358642528451e-273)
		tmp = x / (y / (y - z));
	elseif (t_0 <= 4.160283441989339e+303)
		tmp = x - ((x * z) / y);
	else
		tmp = x - (x * (z / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, 6.240358642528451e-273], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4.160283441989339e+303], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{if}\;t_0 \leq 6.240358642528451 \cdot 10^{-273}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

\mathbf{elif}\;t_0 \leq 4.160283441989339 \cdot 10^{+303}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.5
Target2.8
Herbie1.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 (/.f64 (*.f64 x (-.f64 y z)) y) < 6.24035864252845103e-273

    1. Initial program 14.1

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied associate-/l*_binary642.9

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

    if 6.24035864252845103e-273 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.160283441989339e303

    1. Initial program 0.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around 0 0.2

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

    if 4.160283441989339e303 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 60.9

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied *-un-lft-identity_binary6460.9

      \[\leadsto \frac{x \cdot \left(y - z\right)}{\color{blue}{1 \cdot y}} \]
    3. Applied times-frac_binary640.8

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

      \[\leadsto \color{blue}{x} \cdot \frac{y - z}{y} \]
    5. Taylor expanded in y around 0 0.8

      \[\leadsto x \cdot \color{blue}{\left(1 - \frac{z}{y}\right)} \]
    6. Applied sub-neg_binary640.8

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-\frac{z}{y}\right)\right)} \]
    7. Applied distribute-rgt-in_binary640.8

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

      \[\leadsto \color{blue}{x} + \left(-\frac{z}{y}\right) \cdot x \]
    9. Simplified0.8

      \[\leadsto x + \color{blue}{\left(-\frac{z}{y} \cdot x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 6.240358642528451 \cdot 10^{-273}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 4.160283441989339 \cdot 10^{+303}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{z}{y}\\ \end{array} \]

Reproduce

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