?

Average Error: 1.8 → 0.1
Time: 10.1s
Precision: binary64
Cost: 13512

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{-4 - x}{y}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-5}:\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, t_0\right)\right|\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-60}:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}} + t_0\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 (/ (- -4.0 x) y)))
   (if (<= x -1e-5)
     (fabs (fma x (/ z y) t_0))
     (if (<= x 5e-60)
       (fabs (/ (- x (fma x z -4.0)) y))
       (fabs (+ (/ z (/ y x)) t_0))))))
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 = (-4.0 - x) / y;
	double tmp;
	if (x <= -1e-5) {
		tmp = fabs(fma(x, (z / y), t_0));
	} else if (x <= 5e-60) {
		tmp = fabs(((x - fma(x, z, -4.0)) / y));
	} else {
		tmp = fabs(((z / (y / x)) + t_0));
	}
	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(-4.0 - x) / y)
	tmp = 0.0
	if (x <= -1e-5)
		tmp = abs(fma(x, Float64(z / y), t_0));
	elseif (x <= 5e-60)
		tmp = abs(Float64(Float64(x - fma(x, z, -4.0)) / y));
	else
		tmp = abs(Float64(Float64(z / Float64(y / x)) + t_0));
	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[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[x, -1e-5], N[Abs[N[(x * N[(z / y), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 5e-60], N[Abs[N[(N[(x - N[(x * z + -4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{-4 - x}{y}\\
\mathbf{if}\;x \leq -1 \cdot 10^{-5}:\\
\;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, t_0\right)\right|\\

\mathbf{elif}\;x \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{z}{\frac{y}{x}} + t_0\right|\\


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if x < -1.00000000000000008e-5

    1. Initial program 0.1

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

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

      fabs-sub [=>]0.1

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

      associate-*l/ [=>]8.3

      \[ \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.00000000000000008e-5 < x < 5.0000000000000001e-60

    1. Initial program 3.1

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

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

      *-lft-identity [<=]3.1

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

      metadata-eval [<=]3.1

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

      fabs-sub [=>]3.1

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

      fabs-mul [<=]3.1

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

      neg-mul-1 [<=]3.1

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

      sub0-neg [<=]3.1

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

      associate-+l- [<=]3.1

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

      neg-sub0 [<=]3.1

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

      +-commutative [<=]3.1

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

      sub-neg [<=]3.1

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

    if 5.0000000000000001e-60 < x

    1. Initial program 0.3

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

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

      [Start]0.3

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

      *-lft-identity [<=]0.3

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

      metadata-eval [<=]0.3

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

      fabs-sub [=>]0.3

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

      fabs-mul [<=]0.3

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

      neg-mul-1 [<=]0.3

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

      sub0-neg [<=]0.3

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

      associate-+l- [<=]0.3

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

      neg-sub0 [<=]0.3

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

      +-commutative [<=]0.3

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

      sub-neg [<=]0.3

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

      associate-*l/ [=>]6.7

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

      *-commutative [=>]6.7

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

      associate-/l* [=>]0.4

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

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

Alternatives

Alternative 1
Error0.1
Cost13513
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \lor \neg \left(x \leq 5.8 \cdot 10^{-60}\right):\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}} + \frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \end{array} \]
Alternative 2
Error0.1
Cost8649
\[\begin{array}{l} t_0 := z \cdot \frac{x}{y}\\ t_1 := \frac{x + 4}{y} - t_0\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+20} \lor \neg \left(t_1 \leq 2 \cdot 10^{+29}\right):\\ \;\;\;\;\left|t_0 + \frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 3
Error0.2
Cost7369
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+25} \lor \neg \left(x \leq 5.5 \cdot 10^{-60}\right):\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}} + \frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 4
Error0.2
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+49}:\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+41}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 5
Error19.2
Cost7116
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-43}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{+27}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error11.6
Cost6985
\[\begin{array}{l} \mathbf{if}\;z \leq -20000000000 \lor \neg \left(z \leq 2.3 \cdot 10^{+104}\right):\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \end{array} \]
Alternative 7
Error11.7
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -20000000000:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+103}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 8
Error18.9
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 9
Error33.0
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce?

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