Average Error: 12.6 → 1.6
Time: 2.2s
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 -\infty:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_0 \leq -19425980806.412174:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \end{array} \]
\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 -\infty:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

\mathbf{elif}\;t_0 \leq -19425980806.412174:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\


\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 (- INFINITY))
     (/ x (/ y (- y z)))
     (if (<= t_0 -19425980806.412174)
       (- x (/ (* x z) y))
       (* x (- 1.0 (/ 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 <= -((double) INFINITY)) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= -19425980806.412174) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x * (1.0 - (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.6
Target2.6
Herbie1.6
\[\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) < -inf.0

    1. Initial program 64.0

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

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -19425980806.4121742

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
    3. Applied associate-/r/_binary647.8

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

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

      \[\leadsto \color{blue}{y \cdot \frac{x}{y} + \left(-z\right) \cdot \frac{x}{y}} \]
    6. Simplified7.7

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

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

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

    1. Initial program 10.6

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

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

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

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

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

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

Reproduce

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