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

\mathbf{elif}\;x \leq 3.049953276556438 \cdot 10^{-5}:\\
\;\;\;\;\left|\frac{x \cdot \left(z + -1\right)}{y} + 4 \cdot \frac{-1}{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 < -7.60535764287139049

    1. Initial program 0.1

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

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

    if -7.60535764287139049 < x < 3.0499532765564379e-5

    1. Initial program 2.6

      \[\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)): 1 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)))): 3 points increase in error, 4 points decrease in error
      (fabs.f64 (-.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x y) z)) (/.f64 (+.f64 x 4) y))): 13 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}{\frac{\left(z - 1\right) \cdot x}{y} - 4 \cdot \frac{1}{y}}\right| \]

    if 3.0499532765564379e-5 < x

    1. Initial program 0.1

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

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

Alternatives

Alternative 1
Error0.1
Cost8648
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ t_1 := t_0 - z \cdot \frac{x}{y}\\ \mathbf{if}\;t_1 \leq -500000000000:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-97}:\\ \;\;\;\;\left|\frac{x \cdot z + \left(-4 - x\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_1\right|\\ \end{array} \]
Alternative 2
Error0.7
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+128}:\\ \;\;\;\;\left|\left(z + -1\right) \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 924.2898540975752:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 3
Error0.7
Cost7368
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ \mathbf{if}\;x \leq -1 \cdot 10^{+128}:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 924.2898540975752:\\ \;\;\;\;\left|t_0 - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 4
Error12.0
Cost7248
\[\begin{array}{l} t_0 := \left|x \cdot \frac{z}{y}\right|\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+111}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.348727787681267 \cdot 10^{+49}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{+165}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 5
Error1.0
Cost7240
\[\begin{array}{l} t_0 := \left|\left(z + -1\right) \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -15049.729131852737:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.049953276556438 \cdot 10^{-5}:\\ \;\;\;\;\left|\frac{4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error1.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -15049.729131852737:\\ \;\;\;\;\left|\left(z + -1\right) \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 3.049953276556438 \cdot 10^{-5}:\\ \;\;\;\;\left|\frac{4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 7
Error0.7
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+128}:\\ \;\;\;\;\left|\left(z + -1\right) \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 924.2898540975752:\\ \;\;\;\;\left|\frac{x \cdot z + \left(-4 - x\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \]
Alternative 8
Error19.0
Cost7116
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -15049.729131852737:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.049953276556438 \cdot 10^{-5}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{+67}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error19.0
Cost7116
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -15049.729131852737:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.049953276556438 \cdot 10^{-5}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{+67}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error9.0
Cost7112
\[\begin{array}{l} t_0 := \left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{if}\;x \leq -7.213437047730665 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 924.2898540975752:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error9.0
Cost7112
\[\begin{array}{l} t_0 := \left|\left(z + -1\right) \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -7.213437047730665 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 924.2898540975752:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error9.0
Cost7112
\[\begin{array}{l} t_0 := \left|\left(z + -1\right) \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -7.213437047730665 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 924.2898540975752:\\ \;\;\;\;\left|\frac{-4}{y} - \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 13
Error18.7
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -15049.729131852737:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.30530273105918854:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 14
Error46.9
Cost6592
\[\left|\frac{x}{y}\right| \]

Error

Reproduce

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