Average Error: 1.7 → 0.6
Time: 9.3s
Precision: binary64
Cost: 7369
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+145} \lor \neg \left(x \leq 7.5 \cdot 10^{+16}\right):\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -2.5e+145) (not (<= x 7.5e+16)))
   (fabs (- (/ (+ x 4.0) y) (/ z (/ y x))))
   (fabs (/ (- (+ x 4.0) (* x z)) 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 tmp;
	if ((x <= -2.5e+145) || !(x <= 7.5e+16)) {
		tmp = fabs((((x + 4.0) / y) - (z / (y / x))));
	} else {
		tmp = fabs((((x + 4.0) - (x * z)) / 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) :: tmp
    if ((x <= (-2.5d+145)) .or. (.not. (x <= 7.5d+16))) then
        tmp = abs((((x + 4.0d0) / y) - (z / (y / x))))
    else
        tmp = abs((((x + 4.0d0) - (x * z)) / 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 tmp;
	if ((x <= -2.5e+145) || !(x <= 7.5e+16)) {
		tmp = Math.abs((((x + 4.0) / y) - (z / (y / x))));
	} else {
		tmp = Math.abs((((x + 4.0) - (x * z)) / y));
	}
	return tmp;
}
def code(x, y, z):
	return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
def code(x, y, z):
	tmp = 0
	if (x <= -2.5e+145) or not (x <= 7.5e+16):
		tmp = math.fabs((((x + 4.0) / y) - (z / (y / x))))
	else:
		tmp = math.fabs((((x + 4.0) - (x * z)) / 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)
	tmp = 0.0
	if ((x <= -2.5e+145) || !(x <= 7.5e+16))
		tmp = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(z / Float64(y / x))));
	else
		tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / 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)
	tmp = 0.0;
	if ((x <= -2.5e+145) || ~((x <= 7.5e+16)))
		tmp = abs((((x + 4.0) / y) - (z / (y / x))));
	else
		tmp = abs((((x + 4.0) - (x * z)) / 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_] := If[Or[LessEqual[x, -2.5e+145], N[Not[LessEqual[x, 7.5e+16]], $MachinePrecision]], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+145} \lor \neg \left(x \leq 7.5 \cdot 10^{+16}\right):\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\


\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 < -2.49999999999999983e145 or 7.5e16 < x

    1. Initial program 0.1

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

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

      [Start]0.1

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

      *-lft-identity [<=]0.1

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

      metadata-eval [<=]0.1

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

      fabs-sub [=>]0.1

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

      fabs-mul [<=]0.1

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

      neg-mul-1 [<=]0.1

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

      sub0-neg [<=]0.1

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

      associate-+l- [<=]0.1

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

      neg-sub0 [<=]0.1

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

      +-commutative [<=]0.1

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

      sub-neg [<=]0.1

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

      associate-*l/ [=>]11.9

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

      *-commutative [=>]11.9

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

      associate-/l* [=>]0.1

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

    if -2.49999999999999983e145 < x < 7.5e16

    1. Initial program 2.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+145} \lor \neg \left(x \leq 7.5 \cdot 10^{+16}\right):\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]

Alternatives

Alternative 1
Error20.5
Cost7644
\[\begin{array}{l} t_0 := \left|\frac{x \cdot z}{y}\right|\\ t_1 := \left|\frac{x}{y}\right|\\ t_2 := \frac{4}{\left|y\right|}\\ \mathbf{if}\;x \leq -3.1 \cdot 10^{+58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+32}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq -1.55:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-64}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error20.0
Cost7380
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1 \cdot 10^{+59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.55:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-24}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+77}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error19.9
Cost7380
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -1.05 \cdot 10^{+59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{+32}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq -1.55:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-23}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+78}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error20.0
Cost7380
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -3 \cdot 10^{+58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.9 \cdot 10^{+31}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq -1.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-23}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+77}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error9.2
Cost7376
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y}\right|\\ t_1 := \left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{if}\;x \leq -0.225:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-64}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-13}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error9.1
Cost7376
\[\begin{array}{l} t_0 := \left|\frac{x}{y} + \frac{4}{y}\right|\\ t_1 := \left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{if}\;x \leq -7.3:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.1 \cdot 10^{-64}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-16}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error9.1
Cost7376
\[\begin{array}{l} t_0 := \left|\frac{x}{y} + \frac{4}{y}\right|\\ t_1 := \left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{if}\;x \leq -0.185:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.5 \cdot 10^{-40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.1 \cdot 10^{-64}:\\ \;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y}\right|\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{-13}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error9.3
Cost7376
\[\begin{array}{l} t_0 := \left|\frac{x}{y} + \frac{4}{y}\right|\\ t_1 := \left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{if}\;x \leq -0.96:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-64}:\\ \;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y}\right|\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error0.6
Cost7369
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+145} \lor \neg \left(x \leq 1.25 \cdot 10^{+44}\right):\\ \;\;\;\;\left|z \cdot \frac{x}{y} + \frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 10
Error1.0
Cost7241
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+145} \lor \neg \left(x \leq 8.5 \cdot 10^{+133}\right):\\ \;\;\;\;\left|\frac{1 - z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]
Alternative 11
Error11.7
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+120}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{+27}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \]
Alternative 12
Error19.1
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \end{array} \]
Alternative 13
Error32.6
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce

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