Average Error: 12.6 → 1.8
Time: 6.4s
Precision: binary64
Cost: 7817
\[\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 5 \cdot 10^{+61} \lor \neg \left(t_0 \leq 2 \cdot 10^{+262}\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\ \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 (/ (* x (- y z)) y)))
   (if (or (<= t_0 5e+61) (not (<= t_0 2e+262))) (fma 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 = (x * (y - z)) / y;
	double tmp;
	if ((t_0 <= 5e+61) || !(t_0 <= 2e+262)) {
		tmp = fma(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 = Float64(Float64(x * Float64(y - z)) / y)
	tmp = 0.0
	if ((t_0 <= 5e+61) || !(t_0 <= 2e+262))
		tmp = fma(x, Float64(Float64(-z) / 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[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[Or[LessEqual[t$95$0, 5e+61], N[Not[LessEqual[t$95$0, 2e+262]], $MachinePrecision]], N[(x * N[((-z) / y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]
\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 5 \cdot 10^{+61} \lor \neg \left(t_0 \leq 2 \cdot 10^{+262}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\

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


\end{array}

Error

Target

Original12.6
Target3.0
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 2 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < 5.00000000000000018e61 or 2e262 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 14.6

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

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

      [Start]14.6

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

      *-commutative [=>]14.6

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

      associate-*l/ [<=]2.1

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

      div-sub [=>]2.1

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

      sub-neg [=>]2.1

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

      +-commutative [=>]2.1

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

      *-inverses [=>]2.1

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

      distribute-lft1-in [<=]2.1

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

      *-commutative [=>]2.1

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

      fma-def [=>]2.1

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

      distribute-neg-frac [=>]2.1

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

    if 5.00000000000000018e61 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2e262

    1. Initial program 0.2

      \[\frac{x \cdot \left(y - z\right)}{y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.8

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

Alternatives

Alternative 1
Error1.8
Cost1481
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq 10^{-155} \lor \neg \left(t_0 \leq 5 \cdot 10^{+236}\right):\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error7.9
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{+173}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+218}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error19.0
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+39} \lor \neg \left(z \leq 1.6 \cdot 10^{+40}\right):\\ \;\;\;\;\left(-z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error20.3
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{+39} \lor \neg \left(z \leq 1.15 \cdot 10^{+40}\right):\\ \;\;\;\;x \cdot \frac{-z}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error2.7
Cost448
\[\frac{x}{\frac{y}{y - z}} \]
Alternative 6
Error25.4
Cost64
\[x \]

Error

Reproduce

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