Average Error: 12.4 → 1.9
Time: 6.0s
Precision: binary64
Cost: 7816
\[\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 -\infty:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\ \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 (- INFINITY))
     (/ x (/ y (- y z)))
     (if (<= t_0 -2e+76) t_0 (fma x (/ (- z) y) x)))))
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 <= -((double) INFINITY)) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= -2e+76) {
		tmp = t_0;
	} else {
		tmp = fma(x, (-z / y), x);
	}
	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)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(x / Float64(y / Float64(y - z)));
	elseif (t_0 <= -2e+76)
		tmp = t_0;
	else
		tmp = fma(x, Float64(Float64(-z) / y), x);
	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]}, If[LessEqual[t$95$0, (-Infinity)], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -2e+76], t$95$0, N[(x * N[((-z) / y), $MachinePrecision] + x), $MachinePrecision]]]]
\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 -\infty:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{+76}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\


\end{array}

Error

Target

Original12.4
Target3.3
Herbie1.9
\[\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 3 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}{\frac{x}{\frac{y}{y - z}}} \]
      Proof

      [Start]64.0

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

      associate-/l* [=>]0.1

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -2.0000000000000001e76

    1. Initial program 0.2

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

    if -2.0000000000000001e76 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 10.2

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

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

      [Start]10.2

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

      *-commutative [=>]10.2

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

      associate-*l/ [<=]2.4

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

      div-sub [=>]2.4

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

      sub-neg [=>]2.4

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

      +-commutative [=>]2.4

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

      *-inverses [=>]2.4

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

      distribute-lft1-in [<=]2.4

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

      *-commutative [=>]2.4

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

      fma-def [=>]2.4

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

      distribute-neg-frac [=>]2.4

      \[ \mathsf{fma}\left(x, \color{blue}{\frac{-z}{y}}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.9

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

Alternatives

Alternative 1
Error1.7
Cost1609
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ t_1 := \frac{t_0}{y}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+289} \lor \neg \left(t_1 \leq -2 \cdot 10^{+45}\right):\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} \cdot t_0\\ \end{array} \]
Alternative 2
Error1.7
Cost1481
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq -2 \cdot 10^{+76}\right):\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error21.4
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;y \leq -5.4 \cdot 10^{-138}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-51}:\\ \;\;\;\;\frac{z}{y} \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+68}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error20.9
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;y \leq -5.4 \cdot 10^{-138}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-298}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-148}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+68}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error3.5
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{-205} \lor \neg \left(y \leq -3 \cdot 10^{-295}\right):\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \end{array} \]
Alternative 6
Error7.9
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+131}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+150}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error20.4
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -5.2 \cdot 10^{-138}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+68}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error20.3
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-138}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{+68}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error25.8
Cost64
\[x \]

Error

Reproduce

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