Average Error: 12.9 → 0.3
Time: 3.2s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := \mathsf{fma}\left(z, \frac{-x}{y}, x\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(1, x, \frac{-z}{\frac{y}{x}}\right)\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-272}:\\ \;\;\;\;x - \frac{1}{y} \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+306}:\\ \;\;\;\;x + \frac{x \cdot z}{-y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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)) (t_1 (fma z (/ (- x) y) x)))
   (if (<= t_0 (- INFINITY))
     (fma 1.0 x (/ (- z) (/ y x)))
     (if (<= t_0 -2e-272)
       (- x (* (/ 1.0 y) (* x z)))
       (if (<= t_0 0.0)
         t_1
         (if (<= t_0 1e+306) (+ x (/ (* x z) (- y))) t_1))))))
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 t_1 = fma(z, (-x / y), x);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = fma(1.0, x, (-z / (y / x)));
	} else if (t_0 <= -2e-272) {
		tmp = x - ((1.0 / y) * (x * z));
	} else if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 1e+306) {
		tmp = x + ((x * z) / -y);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	t_0 = Float64(Float64(x * Float64(y - z)) / y)
	t_1 = fma(z, Float64(Float64(-x) / y), x)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = fma(1.0, x, Float64(Float64(-z) / Float64(y / x)));
	elseif (t_0 <= -2e-272)
		tmp = Float64(x - Float64(Float64(1.0 / y) * Float64(x * z)));
	elseif (t_0 <= 0.0)
		tmp = t_1;
	elseif (t_0 <= 1e+306)
		tmp = Float64(x + Float64(Float64(x * z) / Float64(-y)));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[((-x) / y), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(1.0 * x + N[((-z) / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -2e-272], N[(x - N[(N[(1.0 / y), $MachinePrecision] * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 1e+306], N[(x + N[(N[(x * z), $MachinePrecision] / (-y)), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
t_1 := \mathsf{fma}\left(z, \frac{-x}{y}, x\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(1, x, \frac{-z}{\frac{y}{x}}\right)\\

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

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.9
Target3.3
Herbie0.3
\[\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

    1. Initial program 64.0

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified0.0

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Applied egg-rr21.5

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

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -1.99999999999999986e-272

    1. Initial program 0.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified6.1

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Applied egg-rr0.3

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

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

    if -1.99999999999999986e-272 < (/.f64 (*.f64 x (-.f64 y z)) y) < 0.0 or 1.00000000000000002e306 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 55.1

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified0.7

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Applied egg-rr0.8

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

    if 0.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.00000000000000002e306

    1. Initial program 0.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified5.5

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Applied egg-rr0.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(1, x, \frac{-z}{\frac{y}{x}}\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -2 \cdot 10^{-272}:\\ \;\;\;\;x - \frac{1}{y} \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 0:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{-x}{y}, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 10^{+306}:\\ \;\;\;\;x + \frac{x \cdot z}{-y}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{-x}{y}, x\right)\\ \end{array} \]

Reproduce

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