Average Error: 1.7 → 0.1
Time: 9.0s
Precision: binary64
Cost: 7368
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{if}\;x \leq -1 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+16}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{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 (/ y (- 1.0 z))))))
   (if (<= x -1e+28)
     t_0
     (if (<= x 1e+16) (fabs (- (/ (+ x 4.0) y) (/ (* x z) 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 / (y / (1.0 - z))));
	double tmp;
	if (x <= -1e+28) {
		tmp = t_0;
	} else if (x <= 1e+16) {
		tmp = fabs((((x + 4.0) / y) - ((x * z) / 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 / (y / (1.0d0 - z))))
    if (x <= (-1d+28)) then
        tmp = t_0
    else if (x <= 1d+16) then
        tmp = abs((((x + 4.0d0) / y) - ((x * z) / 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 / (y / (1.0 - z))));
	double tmp;
	if (x <= -1e+28) {
		tmp = t_0;
	} else if (x <= 1e+16) {
		tmp = Math.abs((((x + 4.0) / y) - ((x * z) / 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 / (y / (1.0 - z))))
	tmp = 0
	if x <= -1e+28:
		tmp = t_0
	elif x <= 1e+16:
		tmp = math.fabs((((x + 4.0) / y) - ((x * z) / 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(x / Float64(y / Float64(1.0 - z))))
	tmp = 0.0
	if (x <= -1e+28)
		tmp = t_0;
	elseif (x <= 1e+16)
		tmp = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x * z) / 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 / (y / (1.0 - z))));
	tmp = 0.0;
	if (x <= -1e+28)
		tmp = t_0;
	elseif (x <= 1e+16)
		tmp = abs((((x + 4.0) / y) - ((x * z) / 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[(x / N[(y / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -1e+28], t$95$0, If[LessEqual[x, 1e+16], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \left|\frac{x}{\frac{y}{1 - z}}\right|\\
\mathbf{if}\;x \leq -1 \cdot 10^{+28}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 10^{+16}:\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{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 x < -9.99999999999999958e27 or 1e16 < x

    1. Initial program 0.1

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
      Proof
      (/.f64 x (/.f64 y (-.f64 1 z))): 0 points increase in error, 0 points decrease in error
      (/.f64 x (/.f64 y (Rewrite<= unsub-neg_binary64 (+.f64 1 (neg.f64 z))))): 0 points increase in error, 0 points decrease in error
      (/.f64 x (/.f64 y (+.f64 1 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 z))))): 0 points increase in error, 0 points decrease in error
      (/.f64 x (/.f64 y (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 z) 1)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 x y) (+.f64 (*.f64 -1 z) 1))): 17 points increase in error, 26 points decrease in error
      (Rewrite=> *-commutative_binary64 (*.f64 (+.f64 (*.f64 -1 z) 1) (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (+.f64 (*.f64 -1 z) 1) x) y)): 30 points increase in error, 16 points decrease in error
      (Rewrite=> associate-/l*_binary64 (/.f64 (+.f64 (*.f64 -1 z) 1) (/.f64 y x))): 32 points increase in error, 42 points decrease in error
      (/.f64 (Rewrite=> +-commutative_binary64 (+.f64 1 (*.f64 -1 z))) (/.f64 y x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 1 (Rewrite<= neg-mul-1_binary64 (neg.f64 z))) (/.f64 y x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite=> unsub-neg_binary64 (-.f64 1 z)) (/.f64 y x)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> div-sub_binary64 (-.f64 (/.f64 1 (/.f64 y x)) (/.f64 z (/.f64 y x)))): 0 points increase in error, 1 points decrease in error
      (-.f64 (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 1 y) x)) (/.f64 z (/.f64 y x))): 27 points increase in error, 27 points decrease in error
      (-.f64 (*.f64 (/.f64 1 y) x) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 z y) x))): 25 points increase in error, 13 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 x (-.f64 (/.f64 1 y) (/.f64 z y)))): 5 points increase in error, 1 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 (/.f64 1 y) (/.f64 z y)) x)): 0 points increase in error, 0 points decrease in error

    if -9.99999999999999958e27 < x < 1e16

    1. Initial program 2.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+28}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{elif}\;x \leq 10^{+16}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{1 - z}}\right|\\ \end{array} \]

Alternatives

Alternative 1
Error12.2
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -5.1 \cdot 10^{+132}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+141}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \]
Alternative 2
Error18.5
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -80.29434893793298:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.8257128455901355:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]

Error

Reproduce

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