Average Error: 1.7 → 0.4
Time: 10.2s
Precision: binary64
Cost: 14920
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{x + 4}{y} - \frac{x}{y} \cdot z\\ t_1 := \left|t_0\right|\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{+171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+70}:\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (/ (+ x 4.0) y) (* (/ x y) z))) (t_1 (fabs t_0)))
   (if (<= t_0 -4e+171)
     t_1
     (if (<= t_0 2e+70) (fabs (fma x (/ z y) (/ (- -4.0 x) y))) t_1))))
double code(double x, double y, double z) {
	return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
double code(double x, double y, double z) {
	double t_0 = ((x + 4.0) / y) - ((x / y) * z);
	double t_1 = fabs(t_0);
	double tmp;
	if (t_0 <= -4e+171) {
		tmp = t_1;
	} else if (t_0 <= 2e+70) {
		tmp = fabs(fma(x, (z / y), ((-4.0 - x) / y)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z)
	return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)))
end
function code(x, y, z)
	t_0 = Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))
	t_1 = abs(t_0)
	tmp = 0.0
	if (t_0 <= -4e+171)
		tmp = t_1;
	elseif (t_0 <= 2e+70)
		tmp = abs(fma(x, Float64(z / y), Float64(Float64(-4.0 - x) / y)));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Abs[t$95$0], $MachinePrecision]}, If[LessEqual[t$95$0, -4e+171], t$95$1, If[LessEqual[t$95$0, 2e+70], N[Abs[N[(x * N[(z / y), $MachinePrecision] + N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x + 4}{y} - \frac{x}{y} \cdot z\\
t_1 := \left|t_0\right|\\
\mathbf{if}\;t_0 \leq -4 \cdot 10^{+171}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+70}:\\
\;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\

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


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -3.99999999999999982e171 or 2.00000000000000015e70 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 0.1

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]

    if -3.99999999999999982e171 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 2.00000000000000015e70

    1. Initial program 2.6

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified0.6

      \[\leadsto \color{blue}{\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|} \]
      Proof
      (fabs.f64 (fma.f64 x (/.f64 z y) (/.f64 (-.f64 -4 x) y))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (fma.f64 x (/.f64 z y) (/.f64 (-.f64 (Rewrite<= metadata-eval (neg.f64 4)) x) y))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (fma.f64 x (/.f64 z y) (/.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 4) (neg.f64 x))) y))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (fma.f64 x (/.f64 z y) (/.f64 (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 4 x))) y))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (fma.f64 x (/.f64 z y) (/.f64 (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 x 4))) y))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (fma.f64 x (/.f64 z y) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (+.f64 x 4) y))))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x (/.f64 z y)) (/.f64 (+.f64 x 4) y)))): 2 points increase in error, 1 points decrease in error
      (fabs.f64 (-.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x z) y)) (/.f64 (+.f64 x 4) y))): 25 points increase in error, 28 points decrease in error
      (fabs.f64 (-.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x y) z)) (/.f64 (+.f64 x 4) y))): 17 points increase in error, 21 points decrease in error
      (Rewrite<= fabs-sub_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Alternatives

Alternative 1
Error0.3
Cost8648
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ t_1 := t_0 - \frac{x}{y} \cdot z\\ t_2 := \left|t_1\right|\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{+171}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+70}:\\ \;\;\;\;\left|t_0 - \frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error12.4
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y}\right|\\ \mathbf{if}\;z \leq -4.8 \cdot 10^{+43}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+99}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+133}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+213}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 3
Error10.4
Cost7240
\[\begin{array}{l} t_0 := \left|x \cdot \frac{z}{y} - \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -0.0165:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-80}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.5
Cost7240
\[\begin{array}{l} t_0 := \left|x \cdot \frac{z}{y} - \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.5 \cdot 10^{+60}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+109}:\\ \;\;\;\;\left|\frac{\left(-4 - x\right) + x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.4
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -0.85:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+109}:\\ \;\;\;\;\left|\frac{\left(-4 - x\right) + x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y} - \frac{x}{y}\right|\\ \end{array} \]
Alternative 6
Error20.0
Cost7116
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-82}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+21}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error10.4
Cost7112
\[\begin{array}{l} t_0 := \left|\frac{x}{\frac{y}{z + -1}}\right|\\ \mathbf{if}\;x \leq -0.015:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-80}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error10.4
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -3.15 \cdot 10^{-6}:\\ \;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-80}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z + -1}}\right|\\ \end{array} \]
Alternative 9
Error18.7
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error32.2
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce

herbie shell --seed 2022318 
(FPCore (x y z)
  :name "fabs fraction 1"
  :precision binary64
  (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))