Average Error: 1.6 → 0.6
Time: 5.8s
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 -4 \cdot 10^{+137}:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;t_1 \leq 10^{+28}:\\ \;\;\;\;\left|\frac{\mathsf{fma}\left(x, z, -4 - x\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 -4e+137)
     (fabs (- t_0 (/ z (/ y x))))
     (if (<= t_1 1e+28) (fabs (/ (fma x z (- -4.0 x)) 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 <= -4e+137) {
		tmp = fabs((t_0 - (z / (y / x))));
	} else if (t_1 <= 1e+28) {
		tmp = fabs((fma(x, z, (-4.0 - x)) / 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 <= -4e+137)
		tmp = abs(Float64(t_0 - Float64(z / Float64(y / x))));
	elseif (t_1 <= 1e+28)
		tmp = abs(Float64(fma(x, z, Float64(-4.0 - x)) / 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, -4e+137], N[Abs[N[(t$95$0 - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$1, 1e+28], N[Abs[N[(N[(x * z + N[(-4.0 - x), $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 -4 \cdot 10^{+137}:\\
\;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\

\mathbf{elif}\;t_1 \leq 10^{+28}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(x, z, -4 - x\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)) < -4.0000000000000001e137

    1. Initial program 0.1

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

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]

    if -4.0000000000000001e137 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 9.99999999999999958e27

    1. Initial program 2.9

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

      \[\leadsto \color{blue}{\left|\frac{\mathsf{fma}\left(x, z, -4 - x\right)}{y}\right|} \]
      Proof
      (fabs.f64 (/.f64 (fma.f64 x z (-.f64 -4 x)) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (-.f64 (Rewrite<= metadata-eval (neg.f64 4)) x)) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 4) (neg.f64 x)))) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 4 x)))) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 x 4)))) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x z) (+.f64 x 4))) y)): 1 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (*.f64 x z) y) (/.f64 (+.f64 x 4) y)))): 3 points increase in error, 6 points decrease in error
      (fabs.f64 (-.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x y) z)) (/.f64 (+.f64 x 4) y))): 23 points increase in error, 20 points decrease in error
      (fabs.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y)) 1))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (*.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y)) (Rewrite<= metadata-eval (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> fabs-mul_binary64 (*.f64 (fabs.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))) (fabs.f64 (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= fabs-sub_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)))) (fabs.f64 (neg.f64 -1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))) (fabs.f64 (Rewrite=> metadata-eval 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))) (Rewrite=> metadata-eval 1)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> *-rgt-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 9.99999999999999958e27 < (-.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.6

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

Alternatives

Alternative 1
Error1.1
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1924074597898065 \cdot 10^{-9}:\\ \;\;\;\;\left|x \cdot \frac{z + -1}{y}\right|\\ \mathbf{elif}\;x \leq 0.0035918931347239122:\\ \;\;\;\;\left|\frac{4 - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 2
Error1.8
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 10^{+20}:\\ \;\;\;\;\left|\frac{4 + x \cdot \left(1 - z\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\ \end{array} \]
Alternative 3
Error11.4
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -4.750997175531537 \cdot 10^{+82}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;z \leq 1.4394440538083371 \cdot 10^{+76}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 4
Error18.7
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -975.5834168698973:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0035918931347239122:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]

Error

Reproduce

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