Average Error: 12.4 → 2.2
Time: 2.7s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := x - \frac{x \cdot z}{y}\\ \mathbf{if}\;t_0 \leq -2.1152773731587005 \cdot 10^{+119}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 6.209461191697141 \cdot 10^{-263}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_0 \leq 4.38171916267836 \cdot 10^{+273}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \end{array} \]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
t_1 := x - \frac{x \cdot z}{y}\\
\mathbf{if}\;t_0 \leq -2.1152773731587005 \cdot 10^{+119}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;t_0 \leq 4.38171916267836 \cdot 10^{+273}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y - 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)) (t_1 (- x (/ (* x z) y))))
   (if (<= t_0 -2.1152773731587005e+119)
     t_1
     (if (<= t_0 6.209461191697141e-263)
       (/ x (/ y (- y z)))
       (if (<= t_0 4.38171916267836e+273) t_1 (* x (/ (- y 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 t_1 = x - ((x * z) / y);
	double tmp;
	if (t_0 <= -2.1152773731587005e+119) {
		tmp = t_1;
	} else if (t_0 <= 6.209461191697141e-263) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 4.38171916267836e+273) {
		tmp = t_1;
	} else {
		tmp = x * ((y - z) / y);
	}
	return tmp;
}

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.4
Target3.1
Herbie2.2
\[\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) < -2.11527737315870047e119 or 6.2094611916971407e-263 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.38171916267835984e273

    1. Initial program 9.5

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

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

    if -2.11527737315870047e119 < (/.f64 (*.f64 x (-.f64 y z)) y) < 6.2094611916971407e-263

    1. Initial program 6.8

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

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

    if 4.38171916267835984e273 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 52.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -2.1152773731587005 \cdot 10^{+119}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 6.209461191697141 \cdot 10^{-263}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 4.38171916267836 \cdot 10^{+273}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \end{array} \]

Reproduce

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