Average Error: 12.5 → 0.4
Time: 7.0s
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(-x, \frac{z}{y}, x\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+292}:\\ \;\;\;\;x + \frac{z}{\frac{1}{x}} \cdot \frac{-1}{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 (- x) (/ z y) x)))
   (if (<= t_0 (- INFINITY))
     (- x (/ x (/ y z)))
     (if (<= t_0 -5e+44)
       t_0
       (if (<= t_0 1e-36)
         t_1
         (if (<= t_0 1e+292) (+ x (* (/ z (/ 1.0 x)) (/ -1.0 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(-x, (z / y), x);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = x - (x / (y / z));
	} else if (t_0 <= -5e+44) {
		tmp = t_0;
	} else if (t_0 <= 1e-36) {
		tmp = t_1;
	} else if (t_0 <= 1e+292) {
		tmp = x + ((z / (1.0 / x)) * (-1.0 / 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(Float64(-x), Float64(z / y), x)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(x - Float64(x / Float64(y / z)));
	elseif (t_0 <= -5e+44)
		tmp = t_0;
	elseif (t_0 <= 1e-36)
		tmp = t_1;
	elseif (t_0 <= 1e+292)
		tmp = Float64(x + Float64(Float64(z / Float64(1.0 / x)) * Float64(-1.0 / 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[((-x) * N[(z / y), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -5e+44], t$95$0, If[LessEqual[t$95$0, 1e-36], t$95$1, If[LessEqual[t$95$0, 1e+292], N[(x + N[(N[(z / N[(1.0 / x), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / y), $MachinePrecision]), $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(-x, \frac{z}{y}, x\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\

\mathbf{elif}\;t_0 \leq -5 \cdot 10^{+44}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 10^{-36}:\\
\;\;\;\;t_1\\

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

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


\end{array}

Error

Target

Original12.5
Target3.3
Herbie0.4
\[\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.1

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

      \[\leadsto x - \color{blue}{{\left(\frac{y}{z \cdot x}\right)}^{-1}} \]
    4. Applied egg-rr0.1

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -4.9999999999999996e44

    1. Initial program 0.2

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

    if -4.9999999999999996e44 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.9999999999999994e-37 or 1e292 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 14.4

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

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

      \[\leadsto x - \color{blue}{{\left(\frac{y}{z \cdot x}\right)}^{-1}} \]
    4. Applied egg-rr0.5

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

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

    if 9.9999999999999994e-37 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1e292

    1. Initial program 0.2

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

      \[\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}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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