?

Average Error: 97.4% → 99.6%
Time: 11.3s
Precision: binary64
Cost: 14920.00

?

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

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

\mathbf{else}:\\
\;\;\;\;\left|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)) < -1.00000000000000006e-9

    1. Initial program 99.8

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

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

      [Start]99.8

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

      *-lft-identity [<=]99.8

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

      metadata-eval [<=]99.8

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

      fabs-sub [=>]99.8

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

      fabs-mul [<=]99.8

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

      neg-mul-1 [<=]99.8

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

      sub0-neg [<=]99.8

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

      associate-+l- [<=]99.8

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

      neg-sub0 [<=]99.8

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

      +-commutative [<=]99.8

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

      sub-neg [<=]99.8

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

      associate-*l/ [=>]91.6

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

      *-commutative [=>]91.6

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

      associate-/l* [=>]99.8

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

    if -1.00000000000000006e-9 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 2e-176

    1. Initial program 91.1

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

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

      [Start]91.1

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

      fabs-sub [=>]91.1

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

      associate-*l/ [=>]99.9

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

      associate-*r/ [<=]99.9

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

      *-commutative [<=]99.9

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

      *-commutative [=>]99.9

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

      fma-neg [=>]99.9

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

      distribute-neg-frac [=>]99.9

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

      neg-sub0 [=>]99.9

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

      +-commutative [=>]99.9

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

      associate--r+ [=>]99.9

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

      metadata-eval [=>]99.9

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

    if 2e-176 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 99.4

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

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

Alternatives

Alternative 1
Error99.8%
Cost8648.00
\[\begin{array}{l} t_0 := \frac{x + 4}{y} - \frac{x}{y} \cdot z\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{-33}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}} + \frac{-4 - x}{y}\right|\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-31}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_0\right|\\ \end{array} \]
Alternative 2
Error67.2%
Cost7645.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -8.2 \cdot 10^{+83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -10.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-25}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 8.4 \cdot 10^{+97} \lor \neg \left(x \leq 2.35 \cdot 10^{+172}\right) \land x \leq 8.5 \cdot 10^{+247}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error67.1%
Cost7645.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -4.2 \cdot 10^{+83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{+24}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq -10.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-27}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 10^{+103} \lor \neg \left(x \leq 8.2 \cdot 10^{+172}\right) \land x \leq 2.7 \cdot 10^{+247}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error67.0%
Cost7645.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -8.6 \cdot 10^{+83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.6 \cdot 10^{+20}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq -10.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-25}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 8.1 \cdot 10^{+101} \lor \neg \left(x \leq 3 \cdot 10^{+172}\right) \land x \leq 5.3 \cdot 10^{+247}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error67.1%
Cost7645.00
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.75 \cdot 10^{+84}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{+23}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq -10.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-25}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+97}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+172} \lor \neg \left(x \leq 7.2 \cdot 10^{+246}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 6
Error99.6%
Cost7240.00
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1 \cdot 10^{+69}:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+16}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 7
Error99.8%
Cost7240.00
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-46}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+20}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 8
Error85.4%
Cost7113.00
\[\begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{+14} \lor \neg \left(x \leq 3.8 \cdot 10^{-25}\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \end{array} \]
Alternative 9
Error85.3%
Cost7112.00
\[\begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{+14}:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(z + -1\right)\right|\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-25}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \end{array} \]
Alternative 10
Error81.2%
Cost6984.00
\[\begin{array}{l} \mathbf{if}\;z \leq -6.2 \cdot 10^{+25}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{+138}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 11
Error69.4%
Cost6857.00
\[\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
Error48.3%
Cost6592.00
\[\frac{4}{\left|y\right|} \]

Error

Reproduce?

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