?

Average Error: 1.5 → 0.1
Time: 12.6s
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^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 1000000000:\\ \;\;\;\;\left|\frac{\left(x + 4\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+31)
     t_1
     (if (<= t_0 1000000000.0) (fabs (/ (- (+ x 4.0) (* 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+31) {
		tmp = t_1;
	} else if (t_0 <= 1000000000.0) {
		tmp = fabs((((x + 4.0) - (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+31)) then
        tmp = t_1
    else if (t_0 <= 1000000000.0d0) then
        tmp = abs((((x + 4.0d0) - (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+31) {
		tmp = t_1;
	} else if (t_0 <= 1000000000.0) {
		tmp = Math.abs((((x + 4.0) - (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+31:
		tmp = t_1
	elif t_0 <= 1000000000.0:
		tmp = math.fabs((((x + 4.0) - (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+31)
		tmp = t_1;
	elseif (t_0 <= 1000000000.0)
		tmp = abs(Float64(Float64(Float64(x + 4.0) - 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+31)
		tmp = t_1;
	elseif (t_0 <= 1000000000.0)
		tmp = abs((((x + 4.0) - (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+31], t$95$1, If[LessEqual[t$95$0, 1000000000.0], N[Abs[N[(N[(N[(x + 4.0), $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^{+31}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 1000000000:\\
\;\;\;\;\left|\frac{\left(x + 4\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.9999999999999999e31 or 1e9 < (-.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.9999999999999999e31 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 1e9

    1. Initial program 3.4

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

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

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

      [Start]0.1

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

      rational_best-simplify-1 [<=]0.1

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

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

Alternatives

Alternative 1
Error13.4
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{4 + x}{y}\right|\\ t_1 := \left|-\frac{z \cdot x}{y}\right|\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.12 \cdot 10^{+91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.95 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error9.3
Cost7240
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -78:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.4 \cdot 10^{-56}:\\ \;\;\;\;\left|4 \cdot \frac{1}{y} + \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.4
Cost7240
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{+117}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+15}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error9.2
Cost7112
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -0.0078:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-53}:\\ \;\;\;\;\left|\frac{4 + x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error11.5
Cost7048
\[\begin{array}{l} t_0 := \left|\left(-\frac{z}{y}\right) \cdot x\right|\\ \mathbf{if}\;z \leq -1.28 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+61}:\\ \;\;\;\;\left|\frac{4 + x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
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 7
Error18.1
Cost6720
\[\left|\frac{4 + x}{y}\right| \]
Alternative 8
Error33.0
Cost6592
\[\left|\frac{4}{y}\right| \]

Error

Reproduce?

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