?

Average Accuracy: 97.6% → 99.9%
Time: 9.0s
Precision: binary64
Cost: 13513

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+15} \lor \neg \left(x \leq 5.6 \cdot 10^{+16}\right):\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{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 (or (<= x -2e+15) (not (<= x 5.6e+16)))
   (fabs (- (/ (+ x 4.0) y) (* (/ x y) z)))
   (fabs (/ (- x (fma x z -4.0)) 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+15) || !(x <= 5.6e+16)) {
		tmp = fabs((((x + 4.0) / y) - ((x / y) * z)));
	} else {
		tmp = fabs(((x - fma(x, z, -4.0)) / 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+15) || !(x <= 5.6e+16))
		tmp = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)));
	else
		tmp = abs(Float64(Float64(x - fma(x, z, -4.0)) / 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[Or[LessEqual[x, -2e+15], N[Not[LessEqual[x, 5.6e+16]], $MachinePrecision]], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x - N[(x * z + -4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+15} \lor \neg \left(x \leq 5.6 \cdot 10^{+16}\right):\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\

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


\end{array}

Error?

Derivation?

  1. Split input into 2 regimes
  2. if x < -2e15 or 5.6e16 < x

    1. Initial program 99.8%

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

    if -2e15 < x < 5.6e16

    1. Initial program 96.3%

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

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

      [Start]96.3

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

      *-lft-identity [<=]96.3

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

      metadata-eval [<=]96.3

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

      fabs-sub [=>]96.3

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

      fabs-mul [<=]96.3

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

      neg-mul-1 [<=]96.3

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

      sub0-neg [<=]96.3

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

      associate-+l- [<=]96.3

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

      neg-sub0 [<=]96.3

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

      +-commutative [<=]96.3

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

      sub-neg [<=]96.3

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

      associate-*l/ [=>]99.9

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

      div-sub [<=]99.9

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

      /-rgt-identity [<=]99.9

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

      metadata-eval [<=]99.9

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

      associate-/l* [<=]99.9

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

      *-commutative [=>]99.9

      \[ \left|\frac{\color{blue}{\left(--1\right) \cdot \left(\left(x + 4\right) - x \cdot z\right)}}{y}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy68.4%
Cost7512
\[\begin{array}{l} t_0 := \frac{4}{\left|y\right|}\\ t_1 := \left|\frac{x}{y}\right|\\ t_2 := \left|x \cdot \frac{z}{y}\right|\\ \mathbf{if}\;x \leq -1.02 \cdot 10^{+59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-71}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.7 \cdot 10^{-93}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{+70}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy68.4%
Cost7512
\[\begin{array}{l} t_0 := \frac{4}{\left|y\right|}\\ t_1 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -7 \cdot 10^{+56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-35}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-72}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.7 \cdot 10^{-93}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+70}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy67.6%
Cost7512
\[\begin{array}{l} t_0 := \frac{4}{\left|y\right|}\\ t_1 := \left|\frac{x}{y}\right|\\ t_2 := \left|\frac{x \cdot z}{y}\right|\\ \mathbf{if}\;x \leq -5.8 \cdot 10^{+56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-34}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-72}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-114}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{+70}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy84.3%
Cost7376
\[\begin{array}{l} t_0 := \left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{if}\;x \leq -1.12 \cdot 10^{-34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-71}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-114}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;x \leq 9000000:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy84.4%
Cost7376
\[\begin{array}{l} t_0 := \left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{if}\;x \leq -1.3 \cdot 10^{-34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{-72}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-114}:\\ \;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y}\right|\\ \mathbf{elif}\;x \leq 1500000000:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy99.9%
Cost7369
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{+17} \lor \neg \left(x \leq 5 \cdot 10^{+16}\right):\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 7
Accuracy69.1%
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -5.7 \cdot 10^{+56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-22}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{+70}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Accuracy99.3%
Cost7241
\[\begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{+55} \lor \neg \left(x \leq 1.46 \cdot 10^{+112}\right):\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 9
Accuracy80.8%
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8 \cdot 10^{+128}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{+115}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 10
Accuracy70.2%
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \end{array} \]
Alternative 11
Accuracy48.5%
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce?

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