?

Average Error: 1.6 → 0.8
Time: 40.3s
Precision: binary64
Cost: 7368

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+77}:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-149}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{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 (<= x -2.5e+77)
   (fabs (* (/ x y) (- 1.0 z)))
   (if (<= x 5e-149)
     (fabs (/ (- (+ x 4.0) (* z x)) y))
     (fabs (- (/ (+ x 4.0) y) (* 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+77) {
		tmp = fabs(((x / y) * (1.0 - z)));
	} else if (x <= 5e-149) {
		tmp = fabs((((x + 4.0) - (z * x)) / y));
	} else {
		tmp = fabs((((x + 4.0) / y) - (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+77)) then
        tmp = abs(((x / y) * (1.0d0 - z)))
    else if (x <= 5d-149) then
        tmp = abs((((x + 4.0d0) - (z * x)) / y))
    else
        tmp = abs((((x + 4.0d0) / y) - (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+77) {
		tmp = Math.abs(((x / y) * (1.0 - z)));
	} else if (x <= 5e-149) {
		tmp = Math.abs((((x + 4.0) - (z * x)) / y));
	} else {
		tmp = Math.abs((((x + 4.0) / y) - (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+77:
		tmp = math.fabs(((x / y) * (1.0 - z)))
	elif x <= 5e-149:
		tmp = math.fabs((((x + 4.0) - (z * x)) / y))
	else:
		tmp = math.fabs((((x + 4.0) / y) - (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+77)
		tmp = abs(Float64(Float64(x / y) * Float64(1.0 - z)));
	elseif (x <= 5e-149)
		tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(z * x)) / y));
	else
		tmp = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(x * Float64(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+77)
		tmp = abs(((x / y) * (1.0 - z)));
	elseif (x <= 5e-149)
		tmp = abs((((x + 4.0) - (z * x)) / y));
	else
		tmp = abs((((x + 4.0) / y) - (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[LessEqual[x, -2.5e+77], N[Abs[N[(N[(x / y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 5e-149], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+77}:\\
\;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{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 3 regimes
  2. if x < -2.50000000000000002e77

    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} - x \cdot \frac{z}{y}\right|} \]
      Proof

      [Start]0.1

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

      rational_best-simplify-1 [=>]0.1

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

      rational_best-simplify-55 [=>]0.1

      \[ \left|\frac{x + 4}{y} - \color{blue}{x \cdot \frac{z}{y}}\right| \]
    3. Taylor expanded in x around inf 0.3

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

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

      [Start]0.3

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

      rational_best-simplify-1 [=>]0.3

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

      rational_best-simplify-66 [=>]0.3

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

      rational_best-simplify-55 [=>]0.1

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

      rational_best-simplify-1 [=>]0.1

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

    if -2.50000000000000002e77 < x < 4.99999999999999968e-149

    1. Initial program 2.1

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

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

      [Start]2.1

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

      rational_best-simplify-1 [=>]2.1

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

      rational_best-simplify-55 [=>]5.4

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

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

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

      [Start]0.2

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

      rational_best-simplify-3 [=>]0.2

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

    if 4.99999999999999968e-149 < x

    1. Initial program 1.2

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

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

      [Start]1.2

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

      rational_best-simplify-1 [=>]1.2

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

      rational_best-simplify-55 [=>]1.8

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

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

Alternatives

Alternative 1
Error13.2
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y}\right|\\ t_1 := \left|-\frac{z \cdot x}{y}\right|\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{+85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{+26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+131}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error12.6
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y}\right|\\ t_1 := \left|x \cdot \frac{-z}{y}\right|\\ \mathbf{if}\;z \leq -3.8 \cdot 10^{+143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{+26}:\\ \;\;\;\;\left|-\frac{z \cdot x}{y}\right|\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{+131}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error11.9
Cost7312
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y}\right|\\ t_1 := \left|z \cdot \frac{x}{-y}\right|\\ \mathbf{if}\;z \leq -1.75 \cdot 10^{+143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+125}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error0.3
Cost7240
\[\begin{array}{l} t_0 := \left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{if}\;x \leq -2.15 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{+65}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - z \cdot x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.6
Cost7104
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
Alternative 6
Error18.8
Cost6856
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -10.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error17.9
Cost6720
\[\left|\frac{x + 4}{y}\right| \]
Alternative 8
Error32.3
Cost6592
\[\left|\frac{4}{y}\right| \]

Error

Reproduce?

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