Average Error: 12.8 → 2.1
Time: 2.3s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y}\]
\[\begin{array}{l} \mathbf{if}\;z \leq -3.0737797897570942 \cdot 10^{-40} \lor \neg \left(z \leq 2.5641904822085338 \cdot 10^{-80}\right) \land z \leq 5.35542472829832 \cdot 10^{+248}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \end{array}\]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\mathbf{if}\;z \leq -3.0737797897570942 \cdot 10^{-40} \lor \neg \left(z \leq 2.5641904822085338 \cdot 10^{-80}\right) \land z \leq 5.35542472829832 \cdot 10^{+248}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\

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

\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -3.0737797897570942e-40)
         (and (not (<= z 2.5641904822085338e-80))
              (<= z 5.35542472829832e+248)))
   (- x (* z (/ x y)))
   (* x (/ (- y 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 ((z <= -3.0737797897570942e-40) || (!(z <= 2.5641904822085338e-80) && (z <= 5.35542472829832e+248))) {
		tmp = x - (z * (x / y));
	} else {
		tmp = x * ((y - 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.8
Target3.1
Herbie2.1
\[\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 z < -3.0737797897570942e-40 or 2.56419048220853379e-80 < z < 5.3554247282983202e248

    1. Initial program 11.4

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

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

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

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

    if -3.0737797897570942e-40 < z < 2.56419048220853379e-80 or 5.3554247282983202e248 < z

    1. Initial program 14.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.0737797897570942 \cdot 10^{-40} \lor \neg \left(z \leq 2.5641904822085338 \cdot 10^{-80}\right) \land z \leq 5.35542472829832 \cdot 10^{+248}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \end{array}\]

Reproduce

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