Average Error: 12.1 → 1.8
Time: 4.4s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\frac{-z}{y}, x, x\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{+92}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8.829242912010182 \cdot 10^{-304}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{-x}{y}, x\right)\\ \mathbf{elif}\;x \leq 4.142754075651002 \cdot 10^{-166}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{elif}\;x \leq 1.9913091815903685 \cdot 10^{-11}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fma (/ (- z) y) x x)))
   (if (<= x -1e+92)
     t_0
     (if (<= x 8.829242912010182e-304)
       (fma z (/ (- x) y) x)
       (if (<= x 4.142754075651002e-166)
         (- x (/ (* x z) y))
         (if (<= x 1.9913091815903685e-11) (- x (/ z (/ y x))) t_0))))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double t_0 = fma((-z / y), x, x);
	double tmp;
	if (x <= -1e+92) {
		tmp = t_0;
	} else if (x <= 8.829242912010182e-304) {
		tmp = fma(z, (-x / y), x);
	} else if (x <= 4.142754075651002e-166) {
		tmp = x - ((x * z) / y);
	} else if (x <= 1.9913091815903685e-11) {
		tmp = x - (z / (y / x));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	t_0 = fma(Float64(Float64(-z) / y), x, x)
	tmp = 0.0
	if (x <= -1e+92)
		tmp = t_0;
	elseif (x <= 8.829242912010182e-304)
		tmp = fma(z, Float64(Float64(-x) / y), x);
	elseif (x <= 4.142754075651002e-166)
		tmp = Float64(x - Float64(Float64(x * z) / y));
	elseif (x <= 1.9913091815903685e-11)
		tmp = Float64(x - Float64(z / Float64(y / x)));
	else
		tmp = t_0;
	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[((-z) / y), $MachinePrecision] * x + x), $MachinePrecision]}, If[LessEqual[x, -1e+92], t$95$0, If[LessEqual[x, 8.829242912010182e-304], N[(z * N[((-x) / y), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 4.142754075651002e-166], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.9913091815903685e-11], N[(x - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{-z}{y}, x, x\right)\\
\mathbf{if}\;x \leq -1 \cdot 10^{+92}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 8.829242912010182 \cdot 10^{-304}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{-x}{y}, x\right)\\

\mathbf{elif}\;x \leq 4.142754075651002 \cdot 10^{-166}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\

\mathbf{elif}\;x \leq 1.9913091815903685 \cdot 10^{-11}:\\
\;\;\;\;x - \frac{z}{\frac{y}{x}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Target

Original12.1
Target3.1
Herbie1.8
\[\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 x < -1e92 or 1.9913091815903685e-11 < x

    1. Initial program 24.2

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

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

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

    if -1e92 < x < 8.8292429120101816e-304

    1. Initial program 5.4

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

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

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

    if 8.8292429120101816e-304 < x < 4.1427540756510021e-166

    1. Initial program 8.2

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

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Taylor expanded in z around 0 4.0

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

    if 4.1427540756510021e-166 < x < 1.9913091815903685e-11

    1. Initial program 1.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+92}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-z}{y}, x, x\right)\\ \mathbf{elif}\;x \leq 8.829242912010182 \cdot 10^{-304}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{-x}{y}, x\right)\\ \mathbf{elif}\;x \leq 4.142754075651002 \cdot 10^{-166}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{elif}\;x \leq 1.9913091815903685 \cdot 10^{-11}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-z}{y}, x, x\right)\\ \end{array} \]

Reproduce

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