?

Average Error: 1.6 → 0.2
Time: 8.7s
Precision: binary64
Cost: 7241

?

\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{+46} \lor \neg \left(x \leq 5 \cdot 10^{+32}\right):\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y}\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 -3.9e+46) (not (<= x 5e+32)))
   (fabs (* x (/ (- 1.0 z) y)))
   (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 <= -3.9e+46) || !(x <= 5e+32)) {
		tmp = fabs((x * ((1.0 - z) / y)));
	} 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 <= (-3.9d+46)) .or. (.not. (x <= 5d+32))) then
        tmp = abs((x * ((1.0d0 - z) / y)))
    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 <= -3.9e+46) || !(x <= 5e+32)) {
		tmp = Math.abs((x * ((1.0 - z) / y)));
	} 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 <= -3.9e+46) or not (x <= 5e+32):
		tmp = math.fabs((x * ((1.0 - z) / y)))
	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 <= -3.9e+46) || !(x <= 5e+32))
		tmp = abs(Float64(x * Float64(Float64(1.0 - z) / y)));
	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 <= -3.9e+46) || ~((x <= 5e+32)))
		tmp = abs((x * ((1.0 - z) / y)));
	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, -3.9e+46], N[Not[LessEqual[x, 5e+32]], $MachinePrecision]], N[Abs[N[(x * N[(N[(1.0 - z), $MachinePrecision] / y), $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 -3.9 \cdot 10^{+46} \lor \neg \left(x \leq 5 \cdot 10^{+32}\right):\\
\;\;\;\;\left|x \cdot \frac{1 - z}{y}\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 < -3.89999999999999995e46 or 4.9999999999999997e32 < x

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\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/ [=>]10.2

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

      div-sub [<=]10.2

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

      /-rgt-identity [<=]10.2

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

      metadata-eval [<=]10.2

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

      associate-/l* [<=]10.2

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

      *-commutative [=>]10.2

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

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

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

      [Start]10.2

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

      associate-/l* [=>]0.3

      \[ \left|\color{blue}{\frac{1 - z}{\frac{y}{x}}}\right| \]
    5. Applied egg-rr0.3

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

    if -3.89999999999999995e46 < x < 4.9999999999999997e32

    1. Initial program 2.4

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

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

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

Alternatives

Alternative 1
Error9.0
Cost7113
\[\begin{array}{l} \mathbf{if}\;x \leq -170000 \lor \neg \left(x \leq 6.8 \cdot 10^{-36}\right):\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \end{array} \]
Alternative 2
Error1.6
Cost7104
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
Alternative 3
Error11.3
Cost6985
\[\begin{array}{l} \mathbf{if}\;z \leq -1.22 \cdot 10^{+49} \lor \neg \left(z \leq 1.62 \cdot 10^{+122}\right):\\ \;\;\;\;\left|\frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y}\right|\\ \end{array} \]
Alternative 4
Error18.6
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -1.52 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{4}{\left|y\right|}\\ \end{array} \]
Alternative 5
Error32.6
Cost6592
\[\frac{4}{\left|y\right|} \]

Error

Reproduce?

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