Average Error: 10.5 → 0.9
Time: 2.3s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ t_1 := \frac{t_0}{y}\\ t_2 := x \cdot \frac{y - z}{y}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -2.082978945168603 \cdot 10^{+190}:\\ \;\;\;\;t_0 \cdot \frac{1}{y}\\ \mathbf{elif}\;t_1 \leq 947192973.4213506:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 1.1655371408352642 \cdot 10^{+279}:\\ \;\;\;\;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 := x \cdot \left(y - z\right)\\
t_1 := \frac{t_0}{y}\\
t_2 := x \cdot \frac{y - z}{y}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq -2.082978945168603 \cdot 10^{+190}:\\
\;\;\;\;t_0 \cdot \frac{1}{y}\\

\mathbf{elif}\;t_1 \leq 947192973.4213506:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 1.1655371408352642 \cdot 10^{+279}:\\
\;\;\;\;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))) (t_1 (/ t_0 y)) (t_2 (* x (/ (- y z) y))))
   (if (<= t_1 (- INFINITY))
     t_2
     (if (<= t_1 -2.082978945168603e+190)
       (* t_0 (/ 1.0 y))
       (if (<= t_1 947192973.4213506)
         t_2
         (if (<= t_1 1.1655371408352642e+279)
           (- 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);
	double t_1 = t_0 / y;
	double t_2 = x * ((y - z) / y);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_2;
	} else if (t_1 <= -2.082978945168603e+190) {
		tmp = t_0 * (1.0 / y);
	} else if (t_1 <= 947192973.4213506) {
		tmp = t_2;
	} else if (t_1 <= 1.1655371408352642e+279) {
		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

Original10.5
Target2.4
Herbie0.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 4 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0 or -2.0829789451686031e190 < (/.f64 (*.f64 x (-.f64 y z)) y) < 947192973.421350598

    1. Initial program 10.5

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

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

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

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

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

    1. Initial program 0.2

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

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

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

      \[\leadsto \color{blue}{x} \cdot \frac{y - z}{y} \]
    5. Applied div-inv_binary6413.3

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

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

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

    if 947192973.421350598 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.16553714083526419e279

    1. Initial program 0.2

      \[\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 1.16553714083526419e279 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 24.1

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -\infty:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -2.082978945168603 \cdot 10^{+190}:\\ \;\;\;\;\left(x \cdot \left(y - z\right)\right) \cdot \frac{1}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 947192973.4213506:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 1.1655371408352642 \cdot 10^{+279}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \end{array} \]

Reproduce

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