Average Error: 1.6 → 0.2
Time: 10.4s
Precision: binary64
Cost: 14792
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ t_1 := t_0 - \frac{x}{y} \cdot z\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-146}:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;t_1 \leq 0.0005:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_1\right|\\ \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)) (t_1 (- t_0 (* (/ x y) z))))
   (if (<= t_1 -2e-146)
     (fabs (- t_0 (/ z (/ y x))))
     (if (<= t_1 0.0005) (fabs (/ (- x (fma x z -4.0)) y)) (fabs 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;
	double t_1 = t_0 - ((x / y) * z);
	double tmp;
	if (t_1 <= -2e-146) {
		tmp = fabs((t_0 - (z / (y / x))));
	} else if (t_1 <= 0.0005) {
		tmp = fabs(((x - fma(x, z, -4.0)) / y));
	} else {
		tmp = fabs(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(x + 4.0) / y)
	t_1 = Float64(t_0 - Float64(Float64(x / y) * z))
	tmp = 0.0
	if (t_1 <= -2e-146)
		tmp = abs(Float64(t_0 - Float64(z / Float64(y / x))));
	elseif (t_1 <= 0.0005)
		tmp = abs(Float64(Float64(x - fma(x, z, -4.0)) / y));
	else
		tmp = abs(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[(x + 4.0), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-146], N[Abs[N[(t$95$0 - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$1, 0.0005], N[Abs[N[(N[(x - N[(x * z + -4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[t$95$1], $MachinePrecision]]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x + 4}{y}\\
t_1 := t_0 - \frac{x}{y} \cdot z\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{-146}:\\
\;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\

\mathbf{elif}\;t_1 \leq 0.0005:\\
\;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|t_1\right|\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -2.00000000000000005e-146

    1. Initial program 0.3

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

      \[\leadsto \color{blue}{\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|} \]
      Proof
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (/.f64 z (/.f64 y x)))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 z x) y)))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 x z)) y))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x y) z)))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> sub-neg_binary64 (+.f64 (/.f64 (+.f64 x 4) y) (neg.f64 (*.f64 (/.f64 x y) z))))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 (*.f64 (/.f64 x y) z)) (/.f64 (+.f64 x 4) y)))): 12 points increase in error, 0 points decrease in error
      (fabs.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (*.f64 (/.f64 x y) z))) (/.f64 (+.f64 x 4) y))): 0 points increase in error, 12 points decrease in error
      (fabs.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 2 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> sub0-neg_binary64 (neg.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 0 points increase in error, 2 points decrease in error
      (fabs.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> fabs-mul_binary64 (*.f64 (fabs.f64 -1) (fabs.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite=> metadata-eval 1) (fabs.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y)))): 2 points increase in error, 0 points decrease in error
      (*.f64 1 (Rewrite<= fabs-sub_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))))): 0 points increase in error, 2 points decrease in error
      (Rewrite=> *-lft-identity_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)))): 0 points increase in error, 0 points decrease in error

    if -2.00000000000000005e-146 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 5.0000000000000001e-4

    1. Initial program 5.3

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

      \[\leadsto \color{blue}{\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|} \]
      Proof
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (/.f64 z (/.f64 y x)))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 z x) y)))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 x z)) y))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x y) z)))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> sub-neg_binary64 (+.f64 (/.f64 (+.f64 x 4) y) (neg.f64 (*.f64 (/.f64 x y) z))))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 (*.f64 (/.f64 x y) z)) (/.f64 (+.f64 x 4) y)))): 12 points increase in error, 0 points decrease in error
      (fabs.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (*.f64 (/.f64 x y) z))) (/.f64 (+.f64 x 4) y))): 0 points increase in error, 12 points decrease in error
      (fabs.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 2 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> sub0-neg_binary64 (neg.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 0 points increase in error, 2 points decrease in error
      (fabs.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> fabs-mul_binary64 (*.f64 (fabs.f64 -1) (fabs.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite=> metadata-eval 1) (fabs.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y)))): 2 points increase in error, 0 points decrease in error
      (*.f64 1 (Rewrite<= fabs-sub_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))))): 0 points increase in error, 2 points decrease in error
      (Rewrite=> *-lft-identity_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)))): 0 points increase in error, 0 points decrease in error

    if 5.0000000000000001e-4 < (-.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| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

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

Alternatives

Alternative 1
Error0.2
Cost8649
\[\begin{array}{l} t_0 := \frac{x + 4}{y} - \frac{x}{y} \cdot z\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-171} \lor \neg \left(t_0 \leq 0.0005\right):\\ \;\;\;\;\left|t_0\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 2
Error0.2
Cost8648
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ t_1 := t_0 - \frac{x}{y} \cdot z\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-146}:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;t_1 \leq 0.0005:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_1\right|\\ \end{array} \]
Alternative 3
Error13.0
Cost7512
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot z\right|\\ t_1 := \left|\frac{x}{\frac{y}{z}}\right|\\ t_2 := \left|\frac{x + 4}{y}\right|\\ \mathbf{if}\;z \leq -1.45 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.45 \cdot 10^{+120}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;z \leq -1.36 \cdot 10^{+40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{+35}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{+202}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error20.6
Cost7249
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -10.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.000105:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+188} \lor \neg \left(x \leq 1.5 \cdot 10^{+290}\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error9.5
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-42}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 0.001:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \left(\frac{z}{y} + \frac{-1}{y}\right)\right|\\ \end{array} \]
Alternative 6
Error0.8
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -7.4 \cdot 10^{+167}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+55}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \left(\frac{z}{y} + \frac{-1}{y}\right)\right|\\ \end{array} \]
Alternative 7
Error9.4
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -8 \cdot 10^{-41} \lor \neg \left(x \leq 0.00043\right):\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \end{array} \]
Alternative 8
Error19.1
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \end{array} \]
Alternative 9
Error32.8
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce

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