?

Average Error: 12.5 → 0.5
Time: 5.6s
Precision: binary64
Cost: 8850

?

\[\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 \lor \neg \left(t_0 \leq -1 \cdot 10^{+116} \lor \neg \left(t_0 \leq 5 \cdot 10^{-104}\right) \land t_0 \leq 2 \cdot 10^{+291}\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 (- INFINITY))
           (not
            (or (<= t_0 -1e+116) (and (not (<= t_0 5e-104)) (<= t_0 2e+291)))))
     (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 <= -((double) INFINITY)) || !((t_0 <= -1e+116) || (!(t_0 <= 5e-104) && (t_0 <= 2e+291)))) {
		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 <= Float64(-Inf)) || !((t_0 <= -1e+116) || (!(t_0 <= 5e-104) && (t_0 <= 2e+291))))
		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, (-Infinity)], N[Not[Or[LessEqual[t$95$0, -1e+116], And[N[Not[LessEqual[t$95$0, 5e-104]], $MachinePrecision], LessEqual[t$95$0, 2e+291]]]], $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 -\infty \lor \neg \left(t_0 \leq -1 \cdot 10^{+116} \lor \neg \left(t_0 \leq 5 \cdot 10^{-104}\right) \land t_0 \leq 2 \cdot 10^{+291}\right):\\
\;\;\;\;\mathsf{fma}\left(x, -\frac{z}{y}, x\right)\\

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


\end{array}

Error?

Target

Original12.5
Target2.9
Herbie0.5
\[\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) < -inf.0 or -1.00000000000000002e116 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.99999999999999979e-104 or 1.9999999999999999e291 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 20.4

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

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

      [Start]20.4

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

      *-commutative [=>]20.4

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

      associate-*l/ [<=]0.7

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

      div-sub [=>]0.7

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

      sub-neg [=>]0.7

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

      +-commutative [=>]0.7

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

      *-inverses [=>]0.7

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

      distribute-lft1-in [<=]0.7

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

      *-commutative [=>]0.7

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

      fma-def [=>]0.7

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

      distribute-neg-frac [=>]0.7

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -1.00000000000000002e116 or 4.99999999999999979e-104 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.9999999999999999e291

    1. Initial program 0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -\infty \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \leq -1 \cdot 10^{+116} \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \leq 5 \cdot 10^{-104}\right) \land \frac{x \cdot \left(y - z\right)}{y} \leq 2 \cdot 10^{+291}\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
Error0.5
Cost2514
\[\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 -1 \cdot 10^{+116} \lor \neg \left(t_0 \leq 0.05\right) \land t_0 \leq 2 \cdot 10^{+291}\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error20.0
Cost912
\[\begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+60}:\\ \;\;\;\;\frac{x}{-\frac{y}{z}}\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+49}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+178}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{+217}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \end{array} \]
Alternative 3
Error7.8
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{+187}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{+199}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error18.7
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{+61} \lor \neg \left(z \leq 4.1 \cdot 10^{+49}\right):\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error19.4
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{+62}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+48}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \end{array} \]
Alternative 6
Error19.4
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+61}:\\ \;\;\;\;\frac{x}{-\frac{y}{z}}\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+49}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \end{array} \]
Alternative 7
Error3.1
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq 1.55 \cdot 10^{+80}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 8
Error24.4
Cost64
\[x \]

Error

Reproduce?

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