Average Error: 1.5 → 0.5
Time: 16.2s
Precision: binary64
Cost: 7368
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y} - \frac{z}{y} \cdot x\right|\\ \mathbf{if}\;y \leq -4 \cdot 10^{+84}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-89}:\\ \;\;\;\;\left|\frac{\left(z + -1\right) \cdot x - 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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 (fabs (- (/ (+ x 4.0) y) (* (/ z y) x)))))
   (if (<= y -4e+84)
     t_0
     (if (<= y 1e-89) (fabs (/ (- (* (+ z -1.0) x) 4.0) y)) 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 = fabs((((x + 4.0) / y) - ((z / y) * x)));
	double tmp;
	if (y <= -4e+84) {
		tmp = t_0;
	} else if (y <= 1e-89) {
		tmp = fabs(((((z + -1.0) * x) - 4.0) / y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs((((x + 4.0d0) / y) - ((z / y) * x)))
    if (y <= (-4d+84)) then
        tmp = t_0
    else if (y <= 1d-89) then
        tmp = abs(((((z + (-1.0d0)) * x) - 4.0d0) / y))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
public static double code(double x, double y, double z) {
	double t_0 = Math.abs((((x + 4.0) / y) - ((z / y) * x)));
	double tmp;
	if (y <= -4e+84) {
		tmp = t_0;
	} else if (y <= 1e-89) {
		tmp = Math.abs(((((z + -1.0) * x) - 4.0) / y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
def code(x, y, z):
	t_0 = math.fabs((((x + 4.0) / y) - ((z / y) * x)))
	tmp = 0
	if y <= -4e+84:
		tmp = t_0
	elif y <= 1e-89:
		tmp = math.fabs(((((z + -1.0) * x) - 4.0) / y))
	else:
		tmp = 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 = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(z / y) * x)))
	tmp = 0.0
	if (y <= -4e+84)
		tmp = t_0;
	elseif (y <= 1e-89)
		tmp = abs(Float64(Float64(Float64(Float64(z + -1.0) * x) - 4.0) / y));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = abs((((x + 4.0) / y) - ((x / y) * z)));
end
function tmp_2 = code(x, y, z)
	t_0 = abs((((x + 4.0) / y) - ((z / y) * x)));
	tmp = 0.0;
	if (y <= -4e+84)
		tmp = t_0;
	elseif (y <= 1e-89)
		tmp = abs(((((z + -1.0) * x) - 4.0) / y));
	else
		tmp = t_0;
	end
	tmp_2 = 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[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(z / y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y, -4e+84], t$95$0, If[LessEqual[y, 1e-89], N[Abs[N[(N[(N[(N[(z + -1.0), $MachinePrecision] * x), $MachinePrecision] - 4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \left|\frac{x + 4}{y} - \frac{z}{y} \cdot x\right|\\
\mathbf{if}\;y \leq -4 \cdot 10^{+84}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 10^{-89}:\\
\;\;\;\;\left|\frac{\left(z + -1\right) \cdot x - 4}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if y < -4.00000000000000023e84 or 1.00000000000000004e-89 < y

    1. Initial program 2.5

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

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

    if -4.00000000000000023e84 < y < 1.00000000000000004e-89

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\left|\frac{\mathsf{fma}\left(x, z, -4 - x\right)}{y}\right|} \]
      Proof
    3. Taylor expanded in x around 0 8.4

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

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

Alternatives

Alternative 1
Error0.2
Cost8648
\[\begin{array}{l} t_0 := \frac{x + 4}{y} - \frac{x}{y} \cdot z\\ t_1 := \left|t_0\right|\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-63}:\\ \;\;\;\;\left|\frac{\left(z + -1\right) \cdot x - 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error20.8
Cost7380
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -1.62 \cdot 10^{+146}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{-36}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{+120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{+271}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error20.8
Cost7380
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -2.6 \cdot 10^{+141}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7.4 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-14}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+120}:\\ \;\;\;\;\left|\frac{z}{y} \cdot x\right|\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+269}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error12.2
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot z\right|\\ t_1 := \left|\frac{-4 - x}{y}\right|\\ \mathbf{if}\;z \leq -8.6 \cdot 10^{+102}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{+53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+189}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{y} \cdot x\right|\\ \end{array} \]
Alternative 5
Error1.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{z \cdot x - 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{x}{y} \cdot z\right|\\ \end{array} \]
Alternative 6
Error8.7
Cost7112
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -2300000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 22500000000:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error1.0
Cost7112
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -1.6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{z \cdot x - 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error1.9
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 8 \cdot 10^{+44}:\\ \;\;\;\;\left|\frac{\left(z + -1\right) \cdot x - 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{x}{y} \cdot z\right|\\ \end{array} \]
Alternative 9
Error19.0
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error32.6
Cost6592
\[\left|\frac{4}{y}\right| \]

Error

Reproduce

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