?

Average Accuracy: 97.5% → 99.8%
Time: 10.2s
Precision: binary64
Cost: 13508

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+23}:\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-11}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= x -2e+23)
   (fabs (fma x (/ z y) (/ (- -4.0 x) y)))
   (if (<= x 2e-11)
     (fabs (/ (- (+ x 4.0) (* x z)) y))
     (fabs (- (/ (+ x 4.0) y) (* z (/ x y)))))))
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 tmp;
	if (x <= -2e+23) {
		tmp = fabs(fma(x, (z / y), ((-4.0 - x) / y)));
	} else if (x <= 2e-11) {
		tmp = fabs((((x + 4.0) - (x * z)) / y));
	} else {
		tmp = fabs((((x + 4.0) / y) - (z * (x / y))));
	}
	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)
	tmp = 0.0
	if (x <= -2e+23)
		tmp = abs(fma(x, Float64(z / y), Float64(Float64(-4.0 - x) / y)));
	elseif (x <= 2e-11)
		tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y));
	else
		tmp = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(z * Float64(x / y))));
	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_] := If[LessEqual[x, -2e+23], N[Abs[N[(x * N[(z / y), $MachinePrecision] + N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 2e-11], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+23}:\\
\;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if x < -1.9999999999999998e23

    1. Initial program 99.8%

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

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

      [Start]99.8

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

      fabs-sub [=>]99.8

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

      associate-*l/ [=>]85.5

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

      associate-*r/ [<=]99.8

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

      *-commutative [<=]99.8

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

      *-commutative [=>]99.8

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

      fma-neg [=>]99.8

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

      distribute-neg-frac [=>]99.8

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

      neg-sub0 [=>]99.8

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

      +-commutative [=>]99.8

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

      associate--r+ [=>]99.8

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

      metadata-eval [=>]99.8

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

    if -1.9999999999999998e23 < x < 1.99999999999999988e-11

    1. Initial program 96.0%

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

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

      [Start]96.0

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

      associate-*l/ [=>]99.8

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

      sub-div [=>]99.8

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

    if 1.99999999999999988e-11 < x

    1. Initial program 99.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.8%

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

Alternatives

Alternative 1
Accuracy67.4%
Cost7778
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -2.55 \cdot 10^{+125}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-19}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 4000000000000 \lor \neg \left(x \leq 4.5 \cdot 10^{+93}\right) \land \left(x \leq 6.8 \cdot 10^{+103} \lor \neg \left(x \leq 2.2 \cdot 10^{+211}\right) \land x \leq 3.8 \cdot 10^{+237}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy67.6%
Cost7777
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{+128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-19}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+104}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{+212} \lor \neg \left(x \leq 1.9 \cdot 10^{+234}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy67.3%
Cost7777
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -3.4 \cdot 10^{+125}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-37}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-19}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 22500000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+107}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{+212} \lor \neg \left(x \leq 5.3 \cdot 10^{+241}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy99.8%
Cost7369
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+28} \lor \neg \left(x \leq 0.5\right):\\ \;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 5
Accuracy99.8%
Cost7368
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{+33}:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-11}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_0 - z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 6
Accuracy99.7%
Cost7241
\[\begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+33} \lor \neg \left(x \leq 1.25 \cdot 10^{+24}\right):\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 7
Accuracy85.3%
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{-37} \lor \neg \left(x \leq 3.8 \cdot 10^{-19}\right):\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \end{array} \]
Alternative 8
Accuracy80.7%
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{+187}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+90}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 9
Accuracy69.9%
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \end{array} \]
Alternative 10
Accuracy48.0%
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce?

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