Average Error: 12.3 → 2.5
Time: 5.6s
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.836872331576903 \cdot 10^{-47} \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \leq 2.828654708039762 \cdot 10^{+226}\right):\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x \cdot z}{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.836872331576903 \cdot 10^{-47} \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \leq 2.828654708039762 \cdot 10^{+226}\right):\\
\;\;\;\;x \cdot \frac{y - z}{y}\\

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

\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (if (or (<= (/ (* x (- y z)) y) 5.836872331576903e-47)
         (not (<= (/ (* x (- y z)) y) 2.828654708039762e+226)))
   (* x (/ (- y 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 tmp;
	if ((((x * (y - z)) / y) <= 5.836872331576903e-47) || !(((x * (y - z)) / y) <= 2.828654708039762e+226)) {
		tmp = x * ((y - z) / y);
	} else {
		tmp = x - ((x * 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.3
Target3.2
Herbie2.5
\[\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 2 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < 5.83687233157690328e-47 or 2.82865470803976192e226 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 15.5

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity_binary64_2190215.5

      \[\leadsto \frac{x \cdot \left(y - z\right)}{\color{blue}{1 \cdot y}}\]
    4. Applied times-frac_binary64_219083.0

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

      \[\leadsto \color{blue}{x} \cdot \frac{y - z}{y}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary64_219023.0

      \[\leadsto x \cdot \frac{y - z}{\color{blue}{1 \cdot y}}\]
    8. Applied *-un-lft-identity_binary64_219023.0

      \[\leadsto x \cdot \frac{\color{blue}{1 \cdot \left(y - z\right)}}{1 \cdot y}\]
    9. Applied times-frac_binary64_219083.0

      \[\leadsto x \cdot \color{blue}{\left(\frac{1}{1} \cdot \frac{y - z}{y}\right)}\]
    10. Applied associate-*r*_binary64_218423.0

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

    if 5.83687233157690328e-47 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2.82865470803976192e226

    1. Initial program 0.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 5.836872331576903 \cdot 10^{-47} \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \leq 2.828654708039762 \cdot 10^{+226}\right):\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \end{array}\]

Reproduce

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