Average Error: 12.7 → 1.9
Time: 6.7s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 5.178726587552157 \cdot 10^{-14}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 7.305374277848311 \cdot 10^{+296}:\\ \;\;\;\;\frac{x \cdot y - x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \end{array}\]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 5.178726587552157 \cdot 10^{-14}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

\mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 7.305374277848311 \cdot 10^{+296}:\\
\;\;\;\;\frac{x \cdot y - x \cdot z}{y}\\

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

\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (if (<= (/ (* x (- y z)) y) 5.178726587552157e-14)
   (/ x (/ y (- y z)))
   (if (<= (/ (* x (- y z)) y) 7.305374277848311e+296)
     (/ (- (* x y) (* x z)) y)
     (- x (* z (/ x y))))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double tmp;
	if (((x * (y - z)) / y) <= 5.178726587552157e-14) {
		tmp = x / (y / (y - z));
	} else if (((x * (y - z)) / y) <= 7.305374277848311e+296) {
		tmp = ((x * y) - (x * z)) / y;
	} else {
		tmp = x - (z * (x / 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.7
Target3.4
Herbie1.9
\[\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) < 5.1787265875521573e-14

    1. Initial program 11.4

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Using strategy rm
    3. Applied associate-/l*_binary64_177552.4

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

    if 5.1787265875521573e-14 < (/.f64 (*.f64 x (-.f64 y z)) y) < 7.30537427784831114e296

    1. Initial program 0.2

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Using strategy rm
    3. Applied sub-neg_binary64_178030.2

      \[\leadsto \frac{x \cdot \color{blue}{\left(y + \left(-z\right)\right)}}{y}\]
    4. Applied distribute-rgt-in_binary64_177600.2

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

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

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

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

    1. Initial program 59.9

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Using strategy rm
    3. Applied associate-/l*_binary64_177550.9

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}}\]
    4. Taylor expanded around 0 21.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 5.178726587552157 \cdot 10^{-14}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 7.305374277848311 \cdot 10^{+296}:\\ \;\;\;\;\frac{x \cdot y - x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \end{array}\]

Reproduce

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