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

\mathbf{elif}\;t_3 \leq 10^{-97}:\\
\;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, t_1\right)\right|\\

\mathbf{else}:\\
\;\;\;\;\left|t_2 + 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)) < -1e4

    1. Initial program 0.1

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

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

      [Start]0.1

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

      *-lft-identity [<=]0.1

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

      metadata-eval [<=]0.1

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

      fabs-sub [=>]0.1

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

      fabs-mul [<=]0.1

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

      neg-mul-1 [<=]0.1

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

      sub0-neg [<=]0.1

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

      associate-+l- [<=]0.1

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

      neg-sub0 [<=]0.1

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

      +-commutative [<=]0.1

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

      sub-neg [<=]0.1

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

      associate-*l/ [=>]5.8

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

      *-commutative [=>]5.8

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

      associate-/l* [=>]0.1

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

    if -1e4 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 1.00000000000000004e-97

    1. Initial program 3.9

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

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

      [Start]3.9

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

      fabs-sub [=>]3.9

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

      associate-*l/ [=>]0.1

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

      associate-*r/ [<=]0.1

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

      *-commutative [<=]0.1

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

      *-commutative [=>]0.1

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

      fma-neg [=>]0.1

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

      distribute-neg-frac [=>]0.1

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

      neg-sub0 [=>]0.1

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

      +-commutative [=>]0.1

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

      associate--r+ [=>]0.1

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

      metadata-eval [=>]0.1

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

    if 1.00000000000000004e-97 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 0.2

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

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

Alternatives

Alternative 1
Error19.3
Cost7512
\[\begin{array}{l} t_0 := \frac{4}{\left|y\right|}\\ t_1 := \left|\frac{x}{y}\right|\\ t_2 := \left|\frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -5.8 \cdot 10^{+51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-29}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.35 \cdot 10^{-75}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+269}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error19.2
Cost7512
\[\begin{array}{l} t_0 := \frac{4}{\left|y\right|}\\ t_1 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -6.2 \cdot 10^{+51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-29}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-77}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8 \cdot 10^{+267}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 3
Error19.3
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^{+51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-29}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-77}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{+268}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 4
Error8.8
Cost7376
\[\begin{array}{l} t_0 := \left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{if}\;x \leq -1.4 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-91}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1.52 \cdot 10^{-77}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 3.8:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.5
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-13}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z + \frac{-4 - x}{y}\right|\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+152}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 6
Error18.8
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -7 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 8 \cdot 10^{+269}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error11.5
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y}\right|\\ \mathbf{if}\;z \leq -2.35 \cdot 10^{+17}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;z \leq 970:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+33}:\\ \;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y}\right|\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+106}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \end{array} \]
Alternative 8
Error0.7
Cost7241
\[\begin{array}{l} \mathbf{if}\;x \leq -8.2 \cdot 10^{+52} \lor \neg \left(x \leq 1.9 \cdot 10^{+158}\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 9
Error0.6
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -6.8 \cdot 10^{-13}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z + \frac{-4 - x}{y}\right|\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+158}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 10
Error11.3
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{+17}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+105}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \end{array} \]
Alternative 11
Error18.2
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 12
Error32.1
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce

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