Average Error: 1.8 → 0.5
Time: 8.7s
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 -9 \cdot 10^{-18}:\\ \;\;\;\;\left|t_0 - \frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 10^{-142}:\\ \;\;\;\;\left|\frac{-4 + x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_0 - z \cdot \frac{x}{y}\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 -9e-18)
     (fabs (- t_0 (/ x (/ y z))))
     (if (<= x 1e-142)
       (fabs (/ (+ -4.0 (* x z)) y))
       (fabs (- t_0 (* z (/ x y))))))))
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 <= -9e-18) {
		tmp = fabs((t_0 - (x / (y / z))));
	} else if (x <= 1e-142) {
		tmp = fabs(((-4.0 + (x * z)) / y));
	} else {
		tmp = fabs((t_0 - (z * (x / y))));
	}
	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 <= (-9d-18)) then
        tmp = abs((t_0 - (x / (y / z))))
    else if (x <= 1d-142) then
        tmp = abs((((-4.0d0) + (x * z)) / y))
    else
        tmp = abs((t_0 - (z * (x / y))))
    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 <= -9e-18) {
		tmp = Math.abs((t_0 - (x / (y / z))));
	} else if (x <= 1e-142) {
		tmp = Math.abs(((-4.0 + (x * z)) / y));
	} else {
		tmp = Math.abs((t_0 - (z * (x / y))));
	}
	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 <= -9e-18:
		tmp = math.fabs((t_0 - (x / (y / z))))
	elif x <= 1e-142:
		tmp = math.fabs(((-4.0 + (x * z)) / y))
	else:
		tmp = math.fabs((t_0 - (z * (x / y))))
	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 <= -9e-18)
		tmp = abs(Float64(t_0 - Float64(x / Float64(y / z))));
	elseif (x <= 1e-142)
		tmp = abs(Float64(Float64(-4.0 + Float64(x * z)) / y));
	else
		tmp = abs(Float64(t_0 - Float64(z * Float64(x / y))));
	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 <= -9e-18)
		tmp = abs((t_0 - (x / (y / z))));
	elseif (x <= 1e-142)
		tmp = abs(((-4.0 + (x * z)) / y));
	else
		tmp = abs((t_0 - (z * (x / y))));
	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, -9e-18], N[Abs[N[(t$95$0 - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 1e-142], N[Abs[N[(N[(-4.0 + N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(t$95$0 - N[(z * N[(x / y), $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 -9 \cdot 10^{-18}:\\
\;\;\;\;\left|t_0 - \frac{x}{\frac{y}{z}}\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|t_0 - z \cdot \frac{x}{y}\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 < -8.99999999999999987e-18

    1. Initial program 0.1

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

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

    if -8.99999999999999987e-18 < x < 1e-142

    1. Initial program 2.8

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

      \[\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)): 1 points increase in error, 1 points decrease in error
      (fabs.f64 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (*.f64 x z) y) (/.f64 (+.f64 x 4) y)))): 1 points increase in error, 0 points decrease in error
      (fabs.f64 (-.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x y) z)) (/.f64 (+.f64 x 4) y))): 17 points increase in error, 21 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 x around -inf 0.1

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

      \[\leadsto \left|\color{blue}{\frac{-4}{y} - \frac{x}{y} \cdot \left(1 - z\right)}\right| \]
      Proof
      (-.f64 (/.f64 -4 y) (*.f64 (/.f64 x y) (-.f64 1 z))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 4)) y) (*.f64 (/.f64 x y) (-.f64 1 z))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 4 y))) (*.f64 (/.f64 x y) (-.f64 1 z))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 4 1)) y)) (*.f64 (/.f64 x y) (-.f64 1 z))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 4 (/.f64 1 y)))) (*.f64 (/.f64 x y) (-.f64 1 z))): 1 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (*.f64 (/.f64 x y) (Rewrite<= unsub-neg_binary64 (+.f64 1 (neg.f64 z))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (*.f64 (/.f64 x y) (+.f64 1 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 z))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (*.f64 (/.f64 x y) (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 z) 1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (Rewrite<= associate-/r/_binary64 (/.f64 x (/.f64 y (+.f64 (*.f64 -1 z) 1))))): 26 points increase in error, 14 points decrease in error
      (-.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x (+.f64 (*.f64 -1 z) 1)) y))): 25 points increase in error, 19 points decrease in error
      (-.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 (*.f64 -1 z) 1) x)) y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (neg.f64 (/.f64 (*.f64 (+.f64 (*.f64 -1 z) 1) x) y)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (*.f64 4 (/.f64 1 y))) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 (+.f64 (*.f64 -1 z) 1) x) y)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 (+.f64 (*.f64 -1 z) 1) x) y)) (neg.f64 (*.f64 4 (/.f64 1 y))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 -1 (/.f64 (*.f64 (+.f64 (*.f64 -1 z) 1) x) y)) (*.f64 4 (/.f64 1 y)))): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in y around 0 0.0

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

      \[\leadsto \left|\color{blue}{\frac{-4 - \left(1 - z\right) \cdot x}{y}}\right| \]
      Proof
      (/.f64 (-.f64 -4 (*.f64 (-.f64 1 z) x)) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 -4 (Rewrite<= *-commutative_binary64 (*.f64 x (-.f64 1 z)))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite=> sub-neg_binary64 (+.f64 -4 (neg.f64 (*.f64 x (-.f64 1 z))))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= metadata-eval (*.f64 -1 4)) (neg.f64 (*.f64 x (-.f64 1 z)))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (*.f64 -1 4) (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (*.f64 x (-.f64 1 z))))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= distribute-lft-in_binary64 (*.f64 -1 (+.f64 4 (*.f64 x (-.f64 1 z))))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 -1 (Rewrite<= cancel-sign-sub_binary64 (-.f64 4 (*.f64 (neg.f64 x) (-.f64 1 z))))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 -1 (-.f64 4 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 z) (neg.f64 x))))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 -1 (-.f64 4 (Rewrite=> distribute-rgt-neg-out_binary64 (neg.f64 (*.f64 (-.f64 1 z) x))))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 -1 (-.f64 4 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 (-.f64 1 z) x))))) y): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 (-.f64 4 (*.f64 -1 (*.f64 (-.f64 1 z) x))) y))): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (/.f64 (-.f64 4 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 -1 (-.f64 1 z)) x))) y)): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (/.f64 (-.f64 4 (*.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 1 z))) x)) y)): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (/.f64 (Rewrite=> cancel-sign-sub_binary64 (+.f64 4 (*.f64 (-.f64 1 z) x))) y)): 0 points increase in error, 0 points decrease in error
    7. Taylor expanded in z around inf 0.0

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

      \[\leadsto \left|\frac{-4 - \color{blue}{x \cdot \left(-z\right)}}{y}\right| \]
      Proof
      (*.f64 x (neg.f64 z)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> *-commutative_binary64 (*.f64 (neg.f64 z) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-lft-neg-out_binary64 (neg.f64 (*.f64 z x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 z x))): 0 points increase in error, 0 points decrease in error

    if 1e-142 < x

    1. Initial program 1.4

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

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

Alternatives

Alternative 1
Error0.8
Cost7368
\[\begin{array}{l} t_0 := \left|\frac{-4}{y} + \frac{x}{y} \cdot \left(z + -1\right)\right|\\ \mathbf{if}\;x \leq -2 \cdot 10^{+106}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-146}:\\ \;\;\;\;\left|\frac{-4 + x \cdot \left(z + -1\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.5
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-17}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-143}:\\ \;\;\;\;\left|\frac{-4 + x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4}{y} + \frac{x}{y} \cdot \left(z + -1\right)\right|\\ \end{array} \]
Alternative 3
Error5.2
Cost7244
\[\begin{array}{l} t_0 := \left|\frac{-4 + x \cdot z}{y}\right|\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.0185:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{+150}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 4
Error4.5
Cost7108
\[\begin{array}{l} \mathbf{if}\;z \leq 8.5 \cdot 10^{+149}:\\ \;\;\;\;\left|\frac{-4 + x \cdot \left(z + -1\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 5
Error19.5
Cost6988
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -2.15 \cdot 10^{+24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.4 \cdot 10^{-18}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error12.3
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -6.8 \cdot 10^{+58}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{+105}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 7
Error12.9
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -8 \cdot 10^{-10}:\\ \;\;\;\;\left|\frac{x \cdot \left(z + -1\right)}{y}\right|\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+104}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 8
Error19.5
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -10.2:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error32.7
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce

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