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

\mathbf{elif}\;x \leq 2.260811174163227 \cdot 10^{-155}:\\
\;\;\;\;\left|t_0 - \frac{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 < -9.9999999999999999e45

    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))): 27 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)): 47 points increase in error, 17 points decrease in error
      (Rewrite=> associate-/l*_binary64 (/.f64 (+.f64 (*.f64 -1 z) 1) (/.f64 y x))): 41 points increase in error, 60 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)))): 1 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, 25 points decrease in error
      (-.f64 (*.f64 (/.f64 1 y) x) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 z y) x))): 30 points increase in error, 19 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 x (-.f64 (/.f64 1 y) (/.f64 z y)))): 3 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.9999999999999999e45 < x < 2.2608111741632268e-155

    1. Initial program 2.3

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

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

    if 2.2608111741632268e-155 < x

    1. Initial program 1.2

      \[\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 -1 \cdot 10^{+46}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{elif}\;x \leq 2.260811174163227 \cdot 10^{-155}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost7368
\[\begin{array}{l} t_0 := \left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{if}\;x \leq -1 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+100}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error4.8
Cost7244
\[\begin{array}{l} t_0 := \left|\frac{4 - x \cdot z}{y}\right|\\ \mathbf{if}\;z \leq -30786486.299687263:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.43084176186724 \cdot 10^{-9}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{elif}\;z \leq 10^{+175}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \]
Alternative 3
Error1.1
Cost7240
\[\begin{array}{l} t_0 := \left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{if}\;x \leq -591353427706.8567:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.9908120938300156 \cdot 10^{-10}:\\ \;\;\;\;\left|\frac{4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.3
Cost7240
\[\begin{array}{l} t_0 := \left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{if}\;x \leq -1 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+100}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.0
Cost7112
\[\begin{array}{l} t_0 := \left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{if}\;x \leq -591353427706.8567:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.9908120938300156 \cdot 10^{-10}:\\ \;\;\;\;\left|\frac{4 - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error19.3
Cost6988
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.369526861616593:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.375575257912459 \cdot 10^{-63}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 1.4475894409323352 \cdot 10^{-8}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error19.2
Cost6988
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.369526861616593:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.375575257912459 \cdot 10^{-63}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 1.4475894409323352 \cdot 10^{-8}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error11.6
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -9.1 \cdot 10^{+77}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+61}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \end{array} \]
Alternative 9
Error18.9
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -591353427706.8567:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.4475894409323352 \cdot 10^{-8}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error46.7
Cost6592
\[\left|\frac{x}{y}\right| \]

Error

Reproduce

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