Average Error: 1.6 → 0.1
Time: 8.8s
Precision: binary64
Cost: 13641
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-41} \lor \neg \left(x \leq 1.02 \cdot 10^{+21}\right):\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\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 -5e-41) (not (<= x 1.02e+21)))
   (fabs (fma x (/ z y) (/ (- -4.0 x) y)))
   (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 <= -5e-41) || !(x <= 1.02e+21)) {
		tmp = fabs(fma(x, (z / y), ((-4.0 - x) / y)));
	} 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 <= -5e-41) || !(x <= 1.02e+21))
		tmp = abs(fma(x, Float64(z / y), Float64(Float64(-4.0 - x) / y)));
	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, -5e-41], N[Not[LessEqual[x, 1.02e+21]], $MachinePrecision]], N[Abs[N[(x * N[(z / y), $MachinePrecision] + N[(N[(-4.0 - x), $MachinePrecision] / y), $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 -5 \cdot 10^{-41} \lor \neg \left(x \leq 1.02 \cdot 10^{+21}\right):\\
\;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\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 < -4.9999999999999996e-41 or 1.02e21 < x

    1. Initial program 0.2

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

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

      [Start]0.2

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

      fabs-sub [=>]0.2

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

      associate-*l/ [=>]8.5

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

      associate-*r/ [<=]0.2

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

      *-commutative [<=]0.2

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

      *-commutative [=>]0.2

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

      fma-neg [=>]0.2

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

      distribute-neg-frac [=>]0.2

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

      neg-sub0 [=>]0.2

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

      +-commutative [=>]0.2

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

      associate--r+ [=>]0.2

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

      metadata-eval [=>]0.2

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

    if -4.9999999999999996e-41 < x < 1.02e21

    1. Initial program 2.6

      \[\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

      [Start]2.6

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

      *-lft-identity [<=]2.6

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

      metadata-eval [<=]2.6

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

      fabs-sub [=>]2.6

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

      fabs-mul [<=]2.6

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

      neg-mul-1 [<=]2.6

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

      sub0-neg [<=]2.6

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

      associate-+l- [<=]2.6

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

      neg-sub0 [<=]2.6

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

      +-commutative [<=]2.6

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

      sub-neg [<=]2.6

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

      associate-*l/ [=>]0.1

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

      div-sub [<=]0.1

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

      /-rgt-identity [<=]0.1

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

      metadata-eval [<=]0.1

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

      associate-/l* [<=]0.1

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

      *-commutative [=>]0.1

      \[ \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 simplification0.1

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

Alternatives

Alternative 1
Error0.4
Cost8649
\[\begin{array}{l} t_0 := \frac{x + 4}{y} - z \cdot \frac{x}{y}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+87} \lor \neg \left(t_0 \leq 10^{+44}\right):\\ \;\;\;\;\left|t_0\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 2
Error19.5
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.5 \cdot 10^{+109}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.32 \cdot 10^{-18}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error19.5
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|x \cdot \frac{z}{y}\right|\\ \mathbf{if}\;x \leq -3.35 \cdot 10^{+108}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.56 \cdot 10^{-18}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.5
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -2.5 \cdot 10^{+108}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7.6 \cdot 10^{-41}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 3.05 \cdot 10^{-19}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{+36}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.2
Cost7241
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+43} \lor \neg \left(x \leq 6 \cdot 10^{+17}\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 6
Error9.5
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-41} \lor \neg \left(x \leq 2.8 \cdot 10^{-33}\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \end{array} \]
Alternative 7
Error0.9
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -0.8 \lor \neg \left(x \leq 56000\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4 - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 8
Error9.5
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-45}:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-33}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{1 - z}}\right|\\ \end{array} \]
Alternative 9
Error11.6
Cost6985
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{+91} \lor \neg \left(z \leq 16500\right):\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \end{array} \]
Alternative 10
Error18.8
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
Error32.7
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce

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