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

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

\mathbf{else}:\\
\;\;\;\;\left|t_0 - \frac{x}{\frac{y}{z}}\right|\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if x < -576.577431909512939

    1. Initial program 0.1

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

    if -576.577431909512939 < x < 7.20697485542787085e-108

    1. Initial program 2.3

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

      \[\leadsto \color{blue}{\left|\frac{\mathsf{fma}\left(x, z, -4 - x\right)}{y}\right|} \]
      Proof
      (fabs.f64 (/.f64 (fma.f64 x z (-.f64 -4 x)) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (-.f64 (Rewrite<= metadata-eval (neg.f64 4)) x)) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 4) (neg.f64 x)))) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 4 x)))) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (fma.f64 x z (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 x 4)))) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (/.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x z) (+.f64 x 4))) y)): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (*.f64 x z) y) (/.f64 (+.f64 x 4) y)))): 0 points increase in error, 2 points decrease in error
      (fabs.f64 (-.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x y) z)) (/.f64 (+.f64 x 4) y))): 14 points increase in error, 18 points decrease in error
      (fabs.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y)) 1))): 0 points increase in error, 0 points decrease in error
      (fabs.f64 (*.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y)) (Rewrite<= metadata-eval (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> fabs-mul_binary64 (*.f64 (fabs.f64 (-.f64 (*.f64 (/.f64 x y) z) (/.f64 (+.f64 x 4) y))) (fabs.f64 (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= fabs-sub_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)))) (fabs.f64 (neg.f64 -1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))) (fabs.f64 (Rewrite=> metadata-eval 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))) (Rewrite=> metadata-eval 1)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> *-rgt-identity_binary64 (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around 0 0.1

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

    if 7.20697485542787085e-108 < x

    1. Initial program 0.6

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

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

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

Alternatives

Alternative 1
Error3.9
Cost7504
\[\begin{array}{l} t_0 := \left|\frac{4}{y} - \frac{x}{\frac{y}{z}}\right|\\ t_1 := \left|\frac{x}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{if}\;x \leq -194.904487718874:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.1092346207637957 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8.882046240916371 \cdot 10^{-172}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 2.0397219311006765 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.3
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -1000000000000:\\ \;\;\;\;\left|\frac{x}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 7.206974855427871 \cdot 10^{-108}:\\ \;\;\;\;\left|\frac{x \cdot z + \left(-4 - x\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x - -4}{y} - \frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 3
Error20.5
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{if}\;x \leq -1.15 \cdot 10^{+196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.286001123858849 \cdot 10^{-40}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.7817444260391855 \cdot 10^{-61}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1100813.027604238:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error20.6
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.15 \cdot 10^{+196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.286001123858849 \cdot 10^{-40}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 3.7817444260391855 \cdot 10^{-61}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1100813.027604238:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error20.4
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1 \cdot 10^{+188}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.286001123858849 \cdot 10^{-40}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 3.7817444260391855 \cdot 10^{-61}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1100813.027604238:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error12.9
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 -1.5 \cdot 10^{+151}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.3816182834057908 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.7267211141327047 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.0878081921771034 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \end{array} \]
Alternative 7
Error12.9
Cost7248
\[\begin{array}{l} t_0 := \left|\frac{-4 - x}{y}\right|\\ \mathbf{if}\;z \leq -1.5 \cdot 10^{+151}:\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;z \leq -1.3816182834057908 \cdot 10^{+64}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.7267211141327047 \cdot 10^{+21}:\\ \;\;\;\;\left|z \cdot \frac{1}{\frac{y}{x}}\right|\\ \mathbf{elif}\;z \leq 1.0878081921771034 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \end{array} \]
Alternative 8
Error0.3
Cost7240
\[\begin{array}{l} t_0 := \left|\frac{x}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -1000000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+79}:\\ \;\;\;\;\left|\frac{x \cdot z + \left(-4 - x\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error2.0
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+98}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x \cdot z + \left(-4 - x\right)}{y}\right|\\ \end{array} \]
Alternative 10
Error18.5
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -194.904487718874:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.0397219311006765 \cdot 10^{-5}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error32.2
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce

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