fabs fraction 1

Percentage Accurate: 91.4% → 99.6%
Time: 7.1s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
	return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
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
public static double code(double x, double y, double z) {
	return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z):
	return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z)
	return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)))
end
function tmp = code(x, y, z)
	tmp = abs((((x + 4.0) / y) - ((x / y) * z)));
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]
\begin{array}{l}

\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 91.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
	return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
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
public static double code(double x, double y, double z) {
	return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z):
	return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z)
	return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)))
end
function tmp = code(x, y, z)
	tmp = abs((((x + 4.0) / y) - ((x / y) * z)));
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]
\begin{array}{l}

\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}

Alternative 1: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+109} \lor \neg \left(x \leq 3.6 \cdot 10^{+16}\right):\\ \;\;\;\;\left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.85e+109) (not (<= x 3.6e+16)))
   (fabs (/ x (/ y (- 1.0 z))))
   (fabs (/ (- (+ 4.0 x) (* x z)) y))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.85e+109) || !(x <= 3.6e+16)) {
		tmp = fabs((x / (y / (1.0 - z))));
	} else {
		tmp = fabs((((4.0 + x) - (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
    real(8) :: tmp
    if ((x <= (-1.85d+109)) .or. (.not. (x <= 3.6d+16))) then
        tmp = abs((x / (y / (1.0d0 - z))))
    else
        tmp = abs((((4.0d0 + x) - (x * z)) / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.85e+109) || !(x <= 3.6e+16)) {
		tmp = Math.abs((x / (y / (1.0 - z))));
	} else {
		tmp = Math.abs((((4.0 + x) - (x * z)) / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -1.85e+109) or not (x <= 3.6e+16):
		tmp = math.fabs((x / (y / (1.0 - z))))
	else:
		tmp = math.fabs((((4.0 + x) - (x * z)) / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -1.85e+109) || !(x <= 3.6e+16))
		tmp = abs(Float64(x / Float64(y / Float64(1.0 - z))));
	else
		tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -1.85e+109) || ~((x <= 3.6e+16)))
		tmp = abs((x / (y / (1.0 - z))));
	else
		tmp = abs((((4.0 + x) - (x * z)) / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.85e+109], N[Not[LessEqual[x, 3.6e+16]], $MachinePrecision]], N[Abs[N[(x / N[(y / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+109} \lor \neg \left(x \leq 3.6 \cdot 10^{+16}\right):\\
\;\;\;\;\left|\frac{x}{\frac{y}{1 - z}}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.8500000000000001e109 or 3.6e16 < x

    1. Initial program 87.0%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 90.5%

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

      \[\leadsto \left|\color{blue}{\frac{x \cdot \left(1 - z\right)}{y}}\right| \]
    5. Step-by-step derivation
      1. associate-/l*99.9%

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
    6. Simplified99.9%

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

    if -1.8500000000000001e109 < x < 3.6e16

    1. Initial program 96.7%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 99.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+109} \lor \neg \left(x \leq 3.6 \cdot 10^{+16}\right):\\ \;\;\;\;\left|\frac{x}{\frac{y}{1 - z}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 97.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.3 \cdot 10^{-99}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 1.3e-99)
   (fabs (/ (- (+ 4.0 x) (* x z)) y))
   (fabs (fma x (/ z y) (/ (- -4.0 x) y)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.3e-99) {
		tmp = fabs((((4.0 + x) - (x * z)) / y));
	} else {
		tmp = fabs(fma(x, (z / y), ((-4.0 - x) / y)));
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= 1.3e-99)
		tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / y));
	else
		tmp = abs(fma(x, Float64(z / y), Float64(Float64(-4.0 - x) / y)));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, 1.3e-99], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(z / y), $MachinePrecision] + N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-99}:\\
\;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.30000000000000003e-99

    1. Initial program 90.4%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 96.5%

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

    if 1.30000000000000003e-99 < y

    1. Initial program 96.6%

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

      \[\leadsto \color{blue}{\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|} \]
    3. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification97.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.3 \cdot 10^{-99}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 67.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{if}\;x \leq -1.05 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-20}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+38} \lor \neg \left(x \leq 1.5 \cdot 10^{+103}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fabs (/ x y))) (t_1 (fabs (/ x (/ y z)))))
   (if (<= x -1.05e+21)
     t_0
     (if (<= x -5.8e-12)
       t_1
       (if (<= x 2.15e-20)
         (fabs (/ 4.0 y))
         (if (or (<= x 1.35e+38) (not (<= x 1.5e+103))) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = fabs((x / y));
	double t_1 = fabs((x / (y / z)));
	double tmp;
	if (x <= -1.05e+21) {
		tmp = t_0;
	} else if (x <= -5.8e-12) {
		tmp = t_1;
	} else if (x <= 2.15e-20) {
		tmp = fabs((4.0 / y));
	} else if ((x <= 1.35e+38) || !(x <= 1.5e+103)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
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) :: t_1
    real(8) :: tmp
    t_0 = abs((x / y))
    t_1 = abs((x / (y / z)))
    if (x <= (-1.05d+21)) then
        tmp = t_0
    else if (x <= (-5.8d-12)) then
        tmp = t_1
    else if (x <= 2.15d-20) then
        tmp = abs((4.0d0 / y))
    else if ((x <= 1.35d+38) .or. (.not. (x <= 1.5d+103))) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = Math.abs((x / y));
	double t_1 = Math.abs((x / (y / z)));
	double tmp;
	if (x <= -1.05e+21) {
		tmp = t_0;
	} else if (x <= -5.8e-12) {
		tmp = t_1;
	} else if (x <= 2.15e-20) {
		tmp = Math.abs((4.0 / y));
	} else if ((x <= 1.35e+38) || !(x <= 1.5e+103)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = math.fabs((x / y))
	t_1 = math.fabs((x / (y / z)))
	tmp = 0
	if x <= -1.05e+21:
		tmp = t_0
	elif x <= -5.8e-12:
		tmp = t_1
	elif x <= 2.15e-20:
		tmp = math.fabs((4.0 / y))
	elif (x <= 1.35e+38) or not (x <= 1.5e+103):
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = abs(Float64(x / y))
	t_1 = abs(Float64(x / Float64(y / z)))
	tmp = 0.0
	if (x <= -1.05e+21)
		tmp = t_0;
	elseif (x <= -5.8e-12)
		tmp = t_1;
	elseif (x <= 2.15e-20)
		tmp = abs(Float64(4.0 / y));
	elseif ((x <= 1.35e+38) || !(x <= 1.5e+103))
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = abs((x / y));
	t_1 = abs((x / (y / z)));
	tmp = 0.0;
	if (x <= -1.05e+21)
		tmp = t_0;
	elseif (x <= -5.8e-12)
		tmp = t_1;
	elseif (x <= 2.15e-20)
		tmp = abs((4.0 / y));
	elseif ((x <= 1.35e+38) || ~((x <= 1.5e+103)))
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -1.05e+21], t$95$0, If[LessEqual[x, -5.8e-12], t$95$1, If[LessEqual[x, 2.15e-20], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, 1.35e+38], N[Not[LessEqual[x, 1.5e+103]], $MachinePrecision]], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
t_1 := \left|\frac{x}{\frac{y}{z}}\right|\\
\mathbf{if}\;x \leq -1.05 \cdot 10^{+21}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -5.8 \cdot 10^{-12}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 2.15 \cdot 10^{-20}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\

\mathbf{elif}\;x \leq 1.35 \cdot 10^{+38} \lor \neg \left(x \leq 1.5 \cdot 10^{+103}\right):\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.05e21 or 1.34999999999999998e38 < x < 1.5e103

    1. Initial program 88.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 90.8%

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

      \[\leadsto \left|\color{blue}{\frac{x \cdot \left(1 - z\right)}{y}}\right| \]
    5. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
    6. Simplified99.8%

      \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
    7. Taylor expanded in z around 0 70.0%

      \[\leadsto \left|\frac{x}{\color{blue}{y}}\right| \]

    if -1.05e21 < x < -5.8000000000000003e-12 or 2.15000000000000006e-20 < x < 1.34999999999999998e38 or 1.5e103 < x

    1. Initial program 89.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 68.4%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x \cdot z}{y}}\right| \]
    4. Step-by-step derivation
      1. mul-1-neg68.4%

        \[\leadsto \left|\color{blue}{-\frac{x \cdot z}{y}}\right| \]
      2. associate-*l/79.1%

        \[\leadsto \left|-\color{blue}{\frac{x}{y} \cdot z}\right| \]
      3. distribute-rgt-neg-out79.1%

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

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    6. Step-by-step derivation
      1. associate-*l/68.4%

        \[\leadsto \left|\color{blue}{\frac{x \cdot \left(-z\right)}{y}}\right| \]
      2. associate-/l*73.7%

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{-z}}}\right| \]
      3. add-sqr-sqrt41.6%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{-z} \cdot \sqrt{-z}}}}\right| \]
      4. sqrt-unprod59.8%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}}}\right| \]
      5. sqr-neg59.8%

        \[\leadsto \left|\frac{x}{\frac{y}{\sqrt{\color{blue}{z \cdot z}}}}\right| \]
      6. sqrt-unprod32.0%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}}\right| \]
      7. add-sqr-sqrt73.7%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{z}}}\right| \]
    7. Applied egg-rr73.7%

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

    if -5.8000000000000003e-12 < x < 2.15000000000000006e-20

    1. Initial program 96.6%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 80.3%

      \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.05 \cdot 10^{+21}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-12}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-20}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+38} \lor \neg \left(x \leq 1.5 \cdot 10^{+103}\right):\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 69.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{if}\;x \leq -4.4 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-20}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{+97}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fabs (/ x y))) (t_1 (fabs (/ x (/ y z)))))
   (if (<= x -4.4e+27)
     t_0
     (if (<= x -4.5e-13)
       t_1
       (if (<= x 1.25e-20)
         (fabs (/ 4.0 y))
         (if (<= x 1.65e+38)
           t_1
           (if (<= x 6.5e+97) t_0 (fabs (/ z (/ y x))))))))))
double code(double x, double y, double z) {
	double t_0 = fabs((x / y));
	double t_1 = fabs((x / (y / z)));
	double tmp;
	if (x <= -4.4e+27) {
		tmp = t_0;
	} else if (x <= -4.5e-13) {
		tmp = t_1;
	} else if (x <= 1.25e-20) {
		tmp = fabs((4.0 / y));
	} else if (x <= 1.65e+38) {
		tmp = t_1;
	} else if (x <= 6.5e+97) {
		tmp = t_0;
	} else {
		tmp = fabs((z / (y / x)));
	}
	return tmp;
}
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) :: t_1
    real(8) :: tmp
    t_0 = abs((x / y))
    t_1 = abs((x / (y / z)))
    if (x <= (-4.4d+27)) then
        tmp = t_0
    else if (x <= (-4.5d-13)) then
        tmp = t_1
    else if (x <= 1.25d-20) then
        tmp = abs((4.0d0 / y))
    else if (x <= 1.65d+38) then
        tmp = t_1
    else if (x <= 6.5d+97) then
        tmp = t_0
    else
        tmp = abs((z / (y / x)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = Math.abs((x / y));
	double t_1 = Math.abs((x / (y / z)));
	double tmp;
	if (x <= -4.4e+27) {
		tmp = t_0;
	} else if (x <= -4.5e-13) {
		tmp = t_1;
	} else if (x <= 1.25e-20) {
		tmp = Math.abs((4.0 / y));
	} else if (x <= 1.65e+38) {
		tmp = t_1;
	} else if (x <= 6.5e+97) {
		tmp = t_0;
	} else {
		tmp = Math.abs((z / (y / x)));
	}
	return tmp;
}
def code(x, y, z):
	t_0 = math.fabs((x / y))
	t_1 = math.fabs((x / (y / z)))
	tmp = 0
	if x <= -4.4e+27:
		tmp = t_0
	elif x <= -4.5e-13:
		tmp = t_1
	elif x <= 1.25e-20:
		tmp = math.fabs((4.0 / y))
	elif x <= 1.65e+38:
		tmp = t_1
	elif x <= 6.5e+97:
		tmp = t_0
	else:
		tmp = math.fabs((z / (y / x)))
	return tmp
function code(x, y, z)
	t_0 = abs(Float64(x / y))
	t_1 = abs(Float64(x / Float64(y / z)))
	tmp = 0.0
	if (x <= -4.4e+27)
		tmp = t_0;
	elseif (x <= -4.5e-13)
		tmp = t_1;
	elseif (x <= 1.25e-20)
		tmp = abs(Float64(4.0 / y));
	elseif (x <= 1.65e+38)
		tmp = t_1;
	elseif (x <= 6.5e+97)
		tmp = t_0;
	else
		tmp = abs(Float64(z / Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = abs((x / y));
	t_1 = abs((x / (y / z)));
	tmp = 0.0;
	if (x <= -4.4e+27)
		tmp = t_0;
	elseif (x <= -4.5e-13)
		tmp = t_1;
	elseif (x <= 1.25e-20)
		tmp = abs((4.0 / y));
	elseif (x <= 1.65e+38)
		tmp = t_1;
	elseif (x <= 6.5e+97)
		tmp = t_0;
	else
		tmp = abs((z / (y / x)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -4.4e+27], t$95$0, If[LessEqual[x, -4.5e-13], t$95$1, If[LessEqual[x, 1.25e-20], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 1.65e+38], t$95$1, If[LessEqual[x, 6.5e+97], t$95$0, N[Abs[N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
t_1 := \left|\frac{x}{\frac{y}{z}}\right|\\
\mathbf{if}\;x \leq -4.4 \cdot 10^{+27}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -4.5 \cdot 10^{-13}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.25 \cdot 10^{-20}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\

\mathbf{elif}\;x \leq 1.65 \cdot 10^{+38}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 6.5 \cdot 10^{+97}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -4.3999999999999997e27 or 1.65e38 < x < 6.4999999999999999e97

    1. Initial program 88.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 90.8%

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

      \[\leadsto \left|\color{blue}{\frac{x \cdot \left(1 - z\right)}{y}}\right| \]
    5. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
    6. Simplified99.8%

      \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
    7. Taylor expanded in z around 0 70.0%

      \[\leadsto \left|\frac{x}{\color{blue}{y}}\right| \]

    if -4.3999999999999997e27 < x < -4.5e-13 or 1.25e-20 < x < 1.65e38

    1. Initial program 99.7%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 77.4%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x \cdot z}{y}}\right| \]
    4. Step-by-step derivation
      1. mul-1-neg77.4%

        \[\leadsto \left|\color{blue}{-\frac{x \cdot z}{y}}\right| \]
      2. associate-*l/77.3%

        \[\leadsto \left|-\color{blue}{\frac{x}{y} \cdot z}\right| \]
      3. distribute-rgt-neg-out77.3%

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Simplified77.3%

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    6. Step-by-step derivation
      1. associate-*l/77.4%

        \[\leadsto \left|\color{blue}{\frac{x \cdot \left(-z\right)}{y}}\right| \]
      2. associate-/l*77.5%

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{-z}}}\right| \]
      3. add-sqr-sqrt48.0%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{-z} \cdot \sqrt{-z}}}}\right| \]
      4. sqrt-unprod54.5%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}}}\right| \]
      5. sqr-neg54.5%

        \[\leadsto \left|\frac{x}{\frac{y}{\sqrt{\color{blue}{z \cdot z}}}}\right| \]
      6. sqrt-unprod29.5%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}}\right| \]
      7. add-sqr-sqrt77.5%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{z}}}\right| \]
    7. Applied egg-rr77.5%

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

    if -4.5e-13 < x < 1.25e-20

    1. Initial program 96.6%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 80.3%

      \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]

    if 6.4999999999999999e97 < x

    1. Initial program 85.6%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 64.5%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x \cdot z}{y}}\right| \]
    4. Step-by-step derivation
      1. mul-1-neg64.5%

        \[\leadsto \left|\color{blue}{-\frac{x \cdot z}{y}}\right| \]
      2. associate-*l/79.8%

        \[\leadsto \left|-\color{blue}{\frac{x}{y} \cdot z}\right| \]
      3. distribute-rgt-neg-out79.8%

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Simplified79.8%

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    6. Step-by-step derivation
      1. add-sqr-sqrt44.8%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{\left(\sqrt{-z} \cdot \sqrt{-z}\right)}\right| \]
      2. sqrt-unprod63.8%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}\right| \]
      3. sqr-neg63.8%

        \[\leadsto \left|\frac{x}{y} \cdot \sqrt{\color{blue}{z \cdot z}}\right| \]
      4. sqrt-unprod34.9%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)}\right| \]
      5. add-sqr-sqrt79.8%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{z}\right| \]
      6. associate-*l/64.5%

        \[\leadsto \left|\color{blue}{\frac{x \cdot z}{y}}\right| \]
      7. *-commutative64.5%

        \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y}\right| \]
      8. associate-/l*79.9%

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    7. Applied egg-rr79.9%

      \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
  3. Recombined 4 regimes into one program.
  4. Final simplification77.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{+27}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-13}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-20}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+38}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{+97}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 97.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 5 \cdot 10^{-11}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4 + x}{y} - z \cdot \frac{x}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 5e-11)
   (fabs (/ (- (+ 4.0 x) (* x z)) y))
   (fabs (- (/ (+ 4.0 x) y) (* z (/ x y))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 5e-11) {
		tmp = fabs((((4.0 + x) - (x * z)) / y));
	} else {
		tmp = fabs((((4.0 + x) / y) - (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
    real(8) :: tmp
    if (y <= 5d-11) then
        tmp = abs((((4.0d0 + x) - (x * z)) / y))
    else
        tmp = abs((((4.0d0 + x) / y) - (z * (x / y))))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 5e-11) {
		tmp = Math.abs((((4.0 + x) - (x * z)) / y));
	} else {
		tmp = Math.abs((((4.0 + x) / y) - (z * (x / y))));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 5e-11:
		tmp = math.fabs((((4.0 + x) - (x * z)) / y))
	else:
		tmp = math.fabs((((4.0 + x) / y) - (z * (x / y))))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 5e-11)
		tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / y));
	else
		tmp = abs(Float64(Float64(Float64(4.0 + x) / y) - Float64(z * Float64(x / y))));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 5e-11)
		tmp = abs((((4.0 + x) - (x * z)) / y));
	else
		tmp = abs((((4.0 + x) / y) - (z * (x / y))));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 5e-11], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] / y), $MachinePrecision] - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 5.00000000000000018e-11

    1. Initial program 90.4%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 96.9%

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

    if 5.00000000000000018e-11 < y

    1. Initial program 98.5%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification97.3%

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

Alternative 6: 97.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 5 \cdot 10^{-57}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4 + x}{y} - \frac{x}{\frac{y}{z}}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 5e-57)
   (fabs (/ (- (+ 4.0 x) (* x z)) y))
   (fabs (- (/ (+ 4.0 x) y) (/ x (/ y z))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 5e-57) {
		tmp = fabs((((4.0 + x) - (x * z)) / y));
	} else {
		tmp = fabs((((4.0 + x) / y) - (x / (y / z))));
	}
	return tmp;
}
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 (y <= 5d-57) then
        tmp = abs((((4.0d0 + x) - (x * z)) / y))
    else
        tmp = abs((((4.0d0 + x) / y) - (x / (y / z))))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 5e-57) {
		tmp = Math.abs((((4.0 + x) - (x * z)) / y));
	} else {
		tmp = Math.abs((((4.0 + x) / y) - (x / (y / z))));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 5e-57:
		tmp = math.fabs((((4.0 + x) - (x * z)) / y))
	else:
		tmp = math.fabs((((4.0 + x) / y) - (x / (y / z))))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 5e-57)
		tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / y));
	else
		tmp = abs(Float64(Float64(Float64(4.0 + x) / y) - Float64(x / Float64(y / z))));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 5e-57)
		tmp = abs((((4.0 + x) - (x * z)) / y));
	else
		tmp = abs((((4.0 + x) / y) - (x / (y / z))));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 5e-57], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] / y), $MachinePrecision] - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-57}:\\
\;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 5.0000000000000002e-57

    1. Initial program 89.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 96.7%

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

    if 5.0000000000000002e-57 < y

    1. Initial program 98.7%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-/r/99.9%

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{\frac{y}{z}}}\right| \]
    4. Applied egg-rr99.9%

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{\frac{y}{z}}}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.7%

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

Alternative 7: 86.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{+53}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{+21}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -4.8e+53)
   (fabs (/ x (/ y z)))
   (if (<= z 4.1e+21) (fabs (/ (- -4.0 x) y)) (fabs (/ z (/ y x))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.8e+53) {
		tmp = fabs((x / (y / z)));
	} else if (z <= 4.1e+21) {
		tmp = fabs(((-4.0 - x) / y));
	} else {
		tmp = fabs((z / (y / x)));
	}
	return tmp;
}
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 (z <= (-4.8d+53)) then
        tmp = abs((x / (y / z)))
    else if (z <= 4.1d+21) then
        tmp = abs((((-4.0d0) - x) / y))
    else
        tmp = abs((z / (y / x)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.8e+53) {
		tmp = Math.abs((x / (y / z)));
	} else if (z <= 4.1e+21) {
		tmp = Math.abs(((-4.0 - x) / y));
	} else {
		tmp = Math.abs((z / (y / x)));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -4.8e+53:
		tmp = math.fabs((x / (y / z)))
	elif z <= 4.1e+21:
		tmp = math.fabs(((-4.0 - x) / y))
	else:
		tmp = math.fabs((z / (y / x)))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -4.8e+53)
		tmp = abs(Float64(x / Float64(y / z)));
	elseif (z <= 4.1e+21)
		tmp = abs(Float64(Float64(-4.0 - x) / y));
	else
		tmp = abs(Float64(z / Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -4.8e+53)
		tmp = abs((x / (y / z)));
	elseif (z <= 4.1e+21)
		tmp = abs(((-4.0 - x) / y));
	else
		tmp = abs((z / (y / x)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -4.8e+53], N[Abs[N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 4.1e+21], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+53}:\\
\;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\

\mathbf{elif}\;z \leq 4.1 \cdot 10^{+21}:\\
\;\;\;\;\left|\frac{-4 - x}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -4.8e53

    1. Initial program 93.6%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 76.4%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x \cdot z}{y}}\right| \]
    4. Step-by-step derivation
      1. mul-1-neg76.4%

        \[\leadsto \left|\color{blue}{-\frac{x \cdot z}{y}}\right| \]
      2. associate-*l/79.2%

        \[\leadsto \left|-\color{blue}{\frac{x}{y} \cdot z}\right| \]
      3. distribute-rgt-neg-out79.2%

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Simplified79.2%

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    6. Step-by-step derivation
      1. associate-*l/76.4%

        \[\leadsto \left|\color{blue}{\frac{x \cdot \left(-z\right)}{y}}\right| \]
      2. associate-/l*84.0%

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{-z}}}\right| \]
      3. add-sqr-sqrt83.8%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{-z} \cdot \sqrt{-z}}}}\right| \]
      4. sqrt-unprod51.4%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}}}\right| \]
      5. sqr-neg51.4%

        \[\leadsto \left|\frac{x}{\frac{y}{\sqrt{\color{blue}{z \cdot z}}}}\right| \]
      6. sqrt-unprod0.0%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}}\right| \]
      7. add-sqr-sqrt84.0%

        \[\leadsto \left|\frac{x}{\frac{y}{\color{blue}{z}}}\right| \]
    7. Applied egg-rr84.0%

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

    if -4.8e53 < z < 4.1e21

    1. Initial program 93.7%

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

      \[\leadsto \color{blue}{\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|} \]
    3. Add Preprocessing
    4. Taylor expanded in z around 0 96.2%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{4 + x}{y}}\right| \]
    5. Step-by-step derivation
      1. associate-*r/96.2%

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(4 + x\right)}{y}}\right| \]
      2. distribute-lft-in96.2%

        \[\leadsto \left|\frac{\color{blue}{-1 \cdot 4 + -1 \cdot x}}{y}\right| \]
      3. metadata-eval96.2%

        \[\leadsto \left|\frac{\color{blue}{-4} + -1 \cdot x}{y}\right| \]
      4. neg-mul-196.2%

        \[\leadsto \left|\frac{-4 + \color{blue}{\left(-x\right)}}{y}\right| \]
      5. sub-neg96.2%

        \[\leadsto \left|\frac{\color{blue}{-4 - x}}{y}\right| \]
    6. Simplified96.2%

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

    if 4.1e21 < z

    1. Initial program 88.3%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 71.6%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x \cdot z}{y}}\right| \]
    4. Step-by-step derivation
      1. mul-1-neg71.6%

        \[\leadsto \left|\color{blue}{-\frac{x \cdot z}{y}}\right| \]
      2. associate-*l/80.7%

        \[\leadsto \left|-\color{blue}{\frac{x}{y} \cdot z}\right| \]
      3. distribute-rgt-neg-out80.7%

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Simplified80.7%

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{\left(\sqrt{-z} \cdot \sqrt{-z}\right)}\right| \]
      2. sqrt-unprod59.9%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}\right| \]
      3. sqr-neg59.9%

        \[\leadsto \left|\frac{x}{y} \cdot \sqrt{\color{blue}{z \cdot z}}\right| \]
      4. sqrt-unprod80.5%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)}\right| \]
      5. add-sqr-sqrt80.7%

        \[\leadsto \left|\frac{x}{y} \cdot \color{blue}{z}\right| \]
      6. associate-*l/71.6%

        \[\leadsto \left|\color{blue}{\frac{x \cdot z}{y}}\right| \]
      7. *-commutative71.6%

        \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y}\right| \]
      8. associate-/l*80.7%

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    7. Applied egg-rr80.7%

      \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification90.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{+53}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{+21}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 68.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -10.5) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 y))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -10.5) || !(x <= 4.0)) {
		tmp = fabs((x / y));
	} else {
		tmp = fabs((4.0 / 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
    real(8) :: tmp
    if ((x <= (-10.5d0)) .or. (.not. (x <= 4.0d0))) then
        tmp = abs((x / y))
    else
        tmp = abs((4.0d0 / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -10.5) || !(x <= 4.0)) {
		tmp = Math.abs((x / y));
	} else {
		tmp = Math.abs((4.0 / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -10.5) or not (x <= 4.0):
		tmp = math.fabs((x / y))
	else:
		tmp = math.fabs((4.0 / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -10.5) || !(x <= 4.0))
		tmp = abs(Float64(x / y));
	else
		tmp = abs(Float64(4.0 / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -10.5) || ~((x <= 4.0)))
		tmp = abs((x / y));
	else
		tmp = abs((4.0 / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -10.5], N[Not[LessEqual[x, 4.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -10.5 or 4 < x

    1. Initial program 88.6%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 92.2%

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

      \[\leadsto \left|\color{blue}{\frac{x \cdot \left(1 - z\right)}{y}}\right| \]
    5. Step-by-step derivation
      1. associate-/l*99.1%

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
    6. Simplified99.1%

      \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{1 - z}}}\right| \]
    7. Taylor expanded in z around 0 59.0%

      \[\leadsto \left|\frac{x}{\color{blue}{y}}\right| \]

    if -10.5 < x < 4

    1. Initial program 96.9%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 75.8%

      \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 39.7% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \left|\frac{4}{y}\right| \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (/ 4.0 y)))
double code(double x, double y, double z) {
	return fabs((4.0 / y));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = abs((4.0d0 / y))
end function
public static double code(double x, double y, double z) {
	return Math.abs((4.0 / y));
}
def code(x, y, z):
	return math.fabs((4.0 / y))
function code(x, y, z)
	return abs(Float64(4.0 / y))
end
function tmp = code(x, y, z)
	tmp = abs((4.0 / y));
end
code[x_, y_, z_] := N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\left|\frac{4}{y}\right|
\end{array}
Derivation
  1. Initial program 92.6%

    \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 39.0%

    \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]
  4. Final simplification39.0%

    \[\leadsto \left|\frac{4}{y}\right| \]
  5. Add Preprocessing

Reproduce

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