Average Error: 12.4 → 2.0
Time: 3.1s
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 -1.153456526587012 \cdot 10^{-34}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{elif}\;t_0 \leq 8.221940391576001 \cdot 10^{+83}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;t_0 \leq 8.047330820983547 \cdot 10^{+306}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \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 -1.153456526587012 \cdot 10^{-34}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\

\mathbf{elif}\;t_0 \leq 8.221940391576001 \cdot 10^{+83}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\

\mathbf{elif}\;t_0 \leq 8.047330820983547 \cdot 10^{+306}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\

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


\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 -1.153456526587012e-34)
     (* (- y z) (/ x y))
     (if (<= t_0 8.221940391576001e+83)
       (* x (- 1.0 (/ z y)))
       (if (<= t_0 8.047330820983547e+306)
         (- x (/ (* x z) y))
         (/ x (/ y (- y z))))))))
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 <= -1.153456526587012e-34) {
		tmp = (y - z) * (x / y);
	} else if (t_0 <= 8.221940391576001e+83) {
		tmp = x * (1.0 - (z / y));
	} else if (t_0 <= 8.047330820983547e+306) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x / (y / (y - z));
	}
	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.0
Herbie2.0
\[\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) < -1.15345652658701191e-34

    1. Initial program 15.2

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

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

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

    if -1.15345652658701191e-34 < (/.f64 (*.f64 x (-.f64 y z)) y) < 8.2219403915760008e83

    1. Initial program 6.1

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

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
    3. Applied log1p-expm1-u_binary640.3

      \[\leadsto \frac{x}{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{y}{y - z}\right)\right)}} \]
    4. Applied div-inv_binary640.4

      \[\leadsto \color{blue}{x \cdot \frac{1}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{y}{y - z}\right)\right)}} \]
    5. Simplified0.4

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

    if 8.2219403915760008e83 < (/.f64 (*.f64 x (-.f64 y z)) y) < 8.0473308209835466e306

    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 8.0473308209835466e306 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 63.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -1.153456526587012 \cdot 10^{-34}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 8.221940391576001 \cdot 10^{+83}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 8.047330820983547 \cdot 10^{+306}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \end{array} \]

Reproduce

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