?

Average Error: 1.5 → 0.3
Time: 10.4s
Precision: binary64
Cost: 8648

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\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^{+72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+74}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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) (* (/ x y) z))) (t_1 (fabs t_0)))
   (if (<= t_0 -2e+72)
     t_1
     (if (<= t_0 2e+74) (fabs (/ (- (+ 4.0 x) (* z x)) y)) 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) - ((x / y) * z);
	double t_1 = fabs(t_0);
	double tmp;
	if (t_0 <= -2e+72) {
		tmp = t_1;
	} else if (t_0 <= 2e+74) {
		tmp = fabs((((4.0 + x) - (z * x)) / y));
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = ((x + 4.0d0) / y) - ((x / y) * z)
    t_1 = abs(t_0)
    if (t_0 <= (-2d+72)) then
        tmp = t_1
    else if (t_0 <= 2d+74) then
        tmp = abs((((4.0d0 + x) - (z * x)) / y))
    else
        tmp = t_1
    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 = ((x + 4.0) / y) - ((x / y) * z);
	double t_1 = Math.abs(t_0);
	double tmp;
	if (t_0 <= -2e+72) {
		tmp = t_1;
	} else if (t_0 <= 2e+74) {
		tmp = Math.abs((((4.0 + x) - (z * x)) / y));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
def code(x, y, z):
	t_0 = ((x + 4.0) / y) - ((x / y) * z)
	t_1 = math.fabs(t_0)
	tmp = 0
	if t_0 <= -2e+72:
		tmp = t_1
	elif t_0 <= 2e+74:
		tmp = math.fabs((((4.0 + x) - (z * x)) / y))
	else:
		tmp = 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(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))
	t_1 = abs(t_0)
	tmp = 0.0
	if (t_0 <= -2e+72)
		tmp = t_1;
	elseif (t_0 <= 2e+74)
		tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(z * x)) / y));
	else
		tmp = t_1;
	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 = ((x + 4.0) / y) - ((x / y) * z);
	t_1 = abs(t_0);
	tmp = 0.0;
	if (t_0 <= -2e+72)
		tmp = t_1;
	elseif (t_0 <= 2e+74)
		tmp = abs((((4.0 + x) - (z * x)) / y));
	else
		tmp = t_1;
	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[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Abs[t$95$0], $MachinePrecision]}, If[LessEqual[t$95$0, -2e+72], t$95$1, If[LessEqual[t$95$0, 2e+74], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\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^{+72}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\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 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -1.99999999999999989e72 or 1.9999999999999999e74 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 0.1

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

    if -1.99999999999999989e72 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 1.9999999999999999e74

    1. Initial program 2.7

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Taylor expanded in y around 0 0.4

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

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

Alternatives

Alternative 1
Error12.1
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{4 + x}{y}\right|\\ t_1 := \left|x \cdot \frac{-z}{y}\right|\\ \mathbf{if}\;z \leq -2.8 \cdot 10^{+103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.6 \cdot 10^{+75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+132}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error11.9
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{4 + x}{y}\right|\\ t_1 := \left|x \cdot \frac{-z}{y}\right|\\ \mathbf{if}\;z \leq -9 \cdot 10^{+103}:\\ \;\;\;\;\left|z \cdot \frac{x}{-y}\right|\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{+83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{+132}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error11.8
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{4 + x}{y}\right|\\ \mathbf{if}\;z \leq -8 \cdot 10^{+97}:\\ \;\;\;\;\left|z \cdot \frac{x}{-y}\right|\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{+80}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{+51}:\\ \;\;\;\;\left|\frac{-x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+132}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{-z}{y}\right|\\ \end{array} \]
Alternative 4
Error0.4
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{+96}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 4200:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(1 - z\right) \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 5
Error9.0
Cost7112
\[\begin{array}{l} t_0 := \left|\left(1 - z\right) \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -3.1 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-13}:\\ \;\;\;\;\left|\frac{4 + x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error9.0
Cost7112
\[\begin{array}{l} t_0 := \left|\left(1 - z\right) \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -2.4 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-12}:\\ \;\;\;\;\left|\frac{1}{y} \cdot \left(4 + x\right)\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error9.0
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{-18}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-12}:\\ \;\;\;\;\left|\frac{1}{y} \cdot \left(4 + x\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(1 - z\right) \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 8
Error19.0
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -10.6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error18.2
Cost6720
\[\left|\frac{4 + x}{y}\right| \]
Alternative 10
Error32.1
Cost6592
\[\left|\frac{4}{y}\right| \]

Error

Reproduce?

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