fabs fraction 1

Percentage Accurate: 91.8% → 99.7%
Time: 7.7s
Alternatives: 10
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 10 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.8% 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.7% accurate, 1.0× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;y\_m \leq 4.2 \cdot 10^{-47}:\\ \;\;\;\;\left|\frac{4 + x \cdot \left(1 - z\right)}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{\frac{y\_m}{z}} - \frac{4 + x}{y\_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= y_m 4.2e-47)
   (fabs (/ (+ 4.0 (* x (- 1.0 z))) y_m))
   (fabs (- (/ x (/ y_m z)) (/ (+ 4.0 x) y_m)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (y_m <= 4.2e-47) {
		tmp = fabs(((4.0 + (x * (1.0 - z))) / y_m));
	} else {
		tmp = fabs(((x / (y_m / z)) - ((4.0 + x) / y_m)));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y_m <= 4.2d-47) then
        tmp = abs(((4.0d0 + (x * (1.0d0 - z))) / y_m))
    else
        tmp = abs(((x / (y_m / z)) - ((4.0d0 + x) / y_m)))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (y_m <= 4.2e-47) {
		tmp = Math.abs(((4.0 + (x * (1.0 - z))) / y_m));
	} else {
		tmp = Math.abs(((x / (y_m / z)) - ((4.0 + x) / y_m)));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if y_m <= 4.2e-47:
		tmp = math.fabs(((4.0 + (x * (1.0 - z))) / y_m))
	else:
		tmp = math.fabs(((x / (y_m / z)) - ((4.0 + x) / y_m)))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (y_m <= 4.2e-47)
		tmp = abs(Float64(Float64(4.0 + Float64(x * Float64(1.0 - z))) / y_m));
	else
		tmp = abs(Float64(Float64(x / Float64(y_m / z)) - Float64(Float64(4.0 + x) / y_m)));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (y_m <= 4.2e-47)
		tmp = abs(((4.0 + (x * (1.0 - z))) / y_m));
	else
		tmp = abs(((x / (y_m / z)) - ((4.0 + x) / y_m)));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[y$95$m, 4.2e-47], N[Abs[N[(N[(4.0 + N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x / N[(y$95$m / z), $MachinePrecision]), $MachinePrecision] - N[(N[(4.0 + x), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|

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

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


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

    1. Initial program 92.3%

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

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(x \cdot z - \left(4 + x\right)\right)}{y}}\right| \]
      2. associate--r+98.9%

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

        \[\leadsto \left|\frac{-1 \cdot \left(\color{blue}{\left(x \cdot z + \left(-4\right)\right)} - x\right)}{y}\right| \]
      4. metadata-eval98.9%

        \[\leadsto \left|\frac{-1 \cdot \left(\left(x \cdot z + \color{blue}{-4}\right) - x\right)}{y}\right| \]
      5. associate-+r-98.9%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(x \cdot z + \left(-4 - x\right)\right)}}{y}\right| \]
      6. fma-undefine98.9%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
      7. neg-mul-198.9%

        \[\leadsto \left|\frac{\color{blue}{-\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
    6. Simplified98.9%

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

    if 4.2000000000000001e-47 < y

    1. Initial program 95.1%

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      2. associate-*r/99.9%

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{x \cdot \frac{z}{y}}\right| \]
      3. clear-num99.9%

        \[\leadsto \left|\frac{x + 4}{y} - x \cdot \color{blue}{\frac{1}{\frac{y}{z}}}\right| \]
      4. un-div-inv99.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 simplification99.2%

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

Alternative 2: 68.9% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \left|z \cdot \frac{x}{y\_m}\right|\\ \mathbf{if}\;x \leq -2.15 \cdot 10^{-47}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y\_m}\right|\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{+128} \lor \neg \left(x \leq 9.5 \cdot 10^{+174}\right):\\ \;\;\;\;\left|\frac{x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (let* ((t_0 (fabs (* z (/ x y_m)))))
   (if (<= x -2.15e-47)
     t_0
     (if (<= x 4.0)
       (fabs (/ 4.0 y_m))
       (if (or (<= x 6.2e+128) (not (<= x 9.5e+174))) (fabs (/ x y_m)) t_0)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double t_0 = fabs((z * (x / y_m)));
	double tmp;
	if (x <= -2.15e-47) {
		tmp = t_0;
	} else if (x <= 4.0) {
		tmp = fabs((4.0 / y_m));
	} else if ((x <= 6.2e+128) || !(x <= 9.5e+174)) {
		tmp = fabs((x / y_m));
	} else {
		tmp = t_0;
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs((z * (x / y_m)))
    if (x <= (-2.15d-47)) then
        tmp = t_0
    else if (x <= 4.0d0) then
        tmp = abs((4.0d0 / y_m))
    else if ((x <= 6.2d+128) .or. (.not. (x <= 9.5d+174))) then
        tmp = abs((x / y_m))
    else
        tmp = t_0
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double t_0 = Math.abs((z * (x / y_m)));
	double tmp;
	if (x <= -2.15e-47) {
		tmp = t_0;
	} else if (x <= 4.0) {
		tmp = Math.abs((4.0 / y_m));
	} else if ((x <= 6.2e+128) || !(x <= 9.5e+174)) {
		tmp = Math.abs((x / y_m));
	} else {
		tmp = t_0;
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	t_0 = math.fabs((z * (x / y_m)))
	tmp = 0
	if x <= -2.15e-47:
		tmp = t_0
	elif x <= 4.0:
		tmp = math.fabs((4.0 / y_m))
	elif (x <= 6.2e+128) or not (x <= 9.5e+174):
		tmp = math.fabs((x / y_m))
	else:
		tmp = t_0
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	t_0 = abs(Float64(z * Float64(x / y_m)))
	tmp = 0.0
	if (x <= -2.15e-47)
		tmp = t_0;
	elseif (x <= 4.0)
		tmp = abs(Float64(4.0 / y_m));
	elseif ((x <= 6.2e+128) || !(x <= 9.5e+174))
		tmp = abs(Float64(x / y_m));
	else
		tmp = t_0;
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	t_0 = abs((z * (x / y_m)));
	tmp = 0.0;
	if (x <= -2.15e-47)
		tmp = t_0;
	elseif (x <= 4.0)
		tmp = abs((4.0 / y_m));
	elseif ((x <= 6.2e+128) || ~((x <= 9.5e+174)))
		tmp = abs((x / y_m));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := Block[{t$95$0 = N[Abs[N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -2.15e-47], t$95$0, If[LessEqual[x, 4.0], N[Abs[N[(4.0 / y$95$m), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, 6.2e+128], N[Not[LessEqual[x, 9.5e+174]], $MachinePrecision]], N[Abs[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision], t$95$0]]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := \left|z \cdot \frac{x}{y\_m}\right|\\
\mathbf{if}\;x \leq -2.15 \cdot 10^{-47}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 4:\\
\;\;\;\;\left|\frac{4}{y\_m}\right|\\

\mathbf{elif}\;x \leq 6.2 \cdot 10^{+128} \lor \neg \left(x \leq 9.5 \cdot 10^{+174}\right):\\
\;\;\;\;\left|\frac{x}{y\_m}\right|\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.1499999999999999e-47 or 6.20000000000000008e128 < x < 9.4999999999999992e174

    1. Initial program 94.1%

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

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

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

        \[\leadsto \left|\color{blue}{-\frac{x \cdot z}{y}}\right| \]
      2. distribute-frac-neg257.7%

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

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

      \[\leadsto \left|\color{blue}{x \cdot \frac{z}{-y}}\right| \]
    7. Step-by-step derivation
      1. clear-num63.0%

        \[\leadsto \left|x \cdot \color{blue}{\frac{1}{\frac{-y}{z}}}\right| \]
      2. un-div-inv63.1%

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{z}}}\right| \]
    9. Step-by-step derivation
      1. associate-/r/70.6%

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

        \[\leadsto \left|\color{blue}{z \cdot \frac{x}{y}}\right| \]
    10. Simplified70.6%

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

    if -2.1499999999999999e-47 < x < 4

    1. Initial program 94.4%

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

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

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

    if 4 < x < 6.20000000000000008e128 or 9.4999999999999992e174 < x

    1. Initial program 89.4%

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

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

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

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

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

        \[\leadsto \left|-\color{blue}{\left(z - 1\right) \cdot \frac{x}{y}}\right| \]
      4. distribute-lft-neg-in95.8%

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

        \[\leadsto \left|\color{blue}{\left(0 - \left(z - 1\right)\right)} \cdot \frac{x}{y}\right| \]
      6. associate-+l-95.8%

        \[\leadsto \left|\color{blue}{\left(\left(0 - z\right) + 1\right)} \cdot \frac{x}{y}\right| \]
      7. neg-sub095.8%

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

        \[\leadsto \left|\color{blue}{\left(1 + \left(-z\right)\right)} \cdot \frac{x}{y}\right| \]
      9. unsub-neg95.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.15 \cdot 10^{-47}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{+128} \lor \neg \left(x \leq 9.5 \cdot 10^{+174}\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.7% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 4.2\right):\\ \;\;\;\;\left|\left(1 - z\right) \cdot \frac{x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4 - x \cdot z}{y\_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (or (<= x -1.5) (not (<= x 4.2)))
   (fabs (* (- 1.0 z) (/ x y_m)))
   (fabs (/ (- 4.0 (* x z)) y_m))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if ((x <= -1.5) || !(x <= 4.2)) {
		tmp = fabs(((1.0 - z) * (x / y_m)));
	} else {
		tmp = fabs(((4.0 - (x * z)) / y_m));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-1.5d0)) .or. (.not. (x <= 4.2d0))) then
        tmp = abs(((1.0d0 - z) * (x / y_m)))
    else
        tmp = abs(((4.0d0 - (x * z)) / y_m))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if ((x <= -1.5) || !(x <= 4.2)) {
		tmp = Math.abs(((1.0 - z) * (x / y_m)));
	} else {
		tmp = Math.abs(((4.0 - (x * z)) / y_m));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if (x <= -1.5) or not (x <= 4.2):
		tmp = math.fabs(((1.0 - z) * (x / y_m)))
	else:
		tmp = math.fabs(((4.0 - (x * z)) / y_m))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if ((x <= -1.5) || !(x <= 4.2))
		tmp = abs(Float64(Float64(1.0 - z) * Float64(x / y_m)));
	else
		tmp = abs(Float64(Float64(4.0 - Float64(x * z)) / y_m));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if ((x <= -1.5) || ~((x <= 4.2)))
		tmp = abs(((1.0 - z) * (x / y_m)));
	else
		tmp = abs(((4.0 - (x * z)) / y_m));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[Or[LessEqual[x, -1.5], N[Not[LessEqual[x, 4.2]], $MachinePrecision]], N[Abs[N[(N[(1.0 - z), $MachinePrecision] * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(4.0 - N[(x * z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 4.2\right):\\
\;\;\;\;\left|\left(1 - z\right) \cdot \frac{x}{y\_m}\right|\\

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


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

    1. Initial program 91.9%

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

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

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

        \[\leadsto \left|\color{blue}{-\frac{x \cdot \left(z - 1\right)}{y}}\right| \]
      2. *-commutative93.0%

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

        \[\leadsto \left|-\color{blue}{\left(z - 1\right) \cdot \frac{x}{y}}\right| \]
      4. distribute-lft-neg-in97.8%

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

        \[\leadsto \left|\color{blue}{\left(0 - \left(z - 1\right)\right)} \cdot \frac{x}{y}\right| \]
      6. associate-+l-97.8%

        \[\leadsto \left|\color{blue}{\left(\left(0 - z\right) + 1\right)} \cdot \frac{x}{y}\right| \]
      7. neg-sub097.8%

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

        \[\leadsto \left|\color{blue}{\left(1 + \left(-z\right)\right)} \cdot \frac{x}{y}\right| \]
      9. unsub-neg97.8%

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

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

    if -1.5 < x < 4.20000000000000018

    1. Initial program 94.7%

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

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(x \cdot z - \left(4 + x\right)\right)}{y}}\right| \]
      2. associate--r+99.9%

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

        \[\leadsto \left|\frac{-1 \cdot \left(\color{blue}{\left(x \cdot z + \left(-4\right)\right)} - x\right)}{y}\right| \]
      4. metadata-eval99.9%

        \[\leadsto \left|\frac{-1 \cdot \left(\left(x \cdot z + \color{blue}{-4}\right) - x\right)}{y}\right| \]
      5. associate-+r-99.9%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(x \cdot z + \left(-4 - x\right)\right)}}{y}\right| \]
      6. fma-undefine99.9%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
      7. neg-mul-199.9%

        \[\leadsto \left|\frac{\color{blue}{-\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
    6. Simplified99.9%

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

      \[\leadsto \left|\frac{4 + \color{blue}{-1 \cdot \left(x \cdot z\right)}}{y}\right| \]
    8. Step-by-step derivation
      1. associate-*r*99.0%

        \[\leadsto \left|\frac{4 + \color{blue}{\left(-1 \cdot x\right) \cdot z}}{y}\right| \]
      2. neg-mul-199.0%

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

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

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

Alternative 4: 84.4% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;z \leq -350000:\\ \;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y\_m}\right|\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{+19}:\\ \;\;\;\;\left|\frac{-4 - x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{1 + z}{\frac{y\_m}{x}}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= z -350000.0)
   (fabs (/ (* x (- 1.0 z)) y_m))
   (if (<= z 2.5e+19)
     (fabs (/ (- -4.0 x) y_m))
     (fabs (/ (+ 1.0 z) (/ y_m x))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -350000.0) {
		tmp = fabs(((x * (1.0 - z)) / y_m));
	} else if (z <= 2.5e+19) {
		tmp = fabs(((-4.0 - x) / y_m));
	} else {
		tmp = fabs(((1.0 + z) / (y_m / x)));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-350000.0d0)) then
        tmp = abs(((x * (1.0d0 - z)) / y_m))
    else if (z <= 2.5d+19) then
        tmp = abs((((-4.0d0) - x) / y_m))
    else
        tmp = abs(((1.0d0 + z) / (y_m / x)))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -350000.0) {
		tmp = Math.abs(((x * (1.0 - z)) / y_m));
	} else if (z <= 2.5e+19) {
		tmp = Math.abs(((-4.0 - x) / y_m));
	} else {
		tmp = Math.abs(((1.0 + z) / (y_m / x)));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if z <= -350000.0:
		tmp = math.fabs(((x * (1.0 - z)) / y_m))
	elif z <= 2.5e+19:
		tmp = math.fabs(((-4.0 - x) / y_m))
	else:
		tmp = math.fabs(((1.0 + z) / (y_m / x)))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (z <= -350000.0)
		tmp = abs(Float64(Float64(x * Float64(1.0 - z)) / y_m));
	elseif (z <= 2.5e+19)
		tmp = abs(Float64(Float64(-4.0 - x) / y_m));
	else
		tmp = abs(Float64(Float64(1.0 + z) / Float64(y_m / x)));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (z <= -350000.0)
		tmp = abs(((x * (1.0 - z)) / y_m));
	elseif (z <= 2.5e+19)
		tmp = abs(((-4.0 - x) / y_m));
	else
		tmp = abs(((1.0 + z) / (y_m / x)));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[z, -350000.0], N[Abs[N[(N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 2.5e+19], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(1.0 + z), $MachinePrecision] / N[(y$95$m / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;z \leq -350000:\\
\;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y\_m}\right|\\

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

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


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

    1. Initial program 92.5%

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

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(x \cdot z - \left(4 + x\right)\right)}{y}}\right| \]
      2. associate--r+98.4%

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

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

        \[\leadsto \left|\frac{-1 \cdot \left(\left(x \cdot z + \color{blue}{-4}\right) - x\right)}{y}\right| \]
      5. associate-+r-98.4%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(x \cdot z + \left(-4 - x\right)\right)}}{y}\right| \]
      6. fma-undefine98.4%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
      7. neg-mul-198.4%

        \[\leadsto \left|\frac{\color{blue}{-\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
    6. Simplified98.4%

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

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

    if -3.5e5 < z < 2.5e19

    1. Initial program 95.5%

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

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

      \[\leadsto \left|\color{blue}{\frac{4 + x}{y}}\right| \]
    5. Step-by-step derivation
      1. +-commutative98.3%

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y}\right| \]
      2. rem-square-sqrt49.2%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}}\right| \]
      3. fabs-sqr49.2%

        \[\leadsto \left|\color{blue}{\left|\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}\right|}\right| \]
      4. rem-square-sqrt98.3%

        \[\leadsto \left|\left|\color{blue}{\frac{x + 4}{y}}\right|\right| \]
      5. fabs-neg98.3%

        \[\leadsto \left|\color{blue}{\left|-\frac{x + 4}{y}\right|}\right| \]
      6. distribute-neg-frac98.3%

        \[\leadsto \left|\left|\color{blue}{\frac{-\left(x + 4\right)}{y}}\right|\right| \]
      7. distribute-neg-in98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{\left(-x\right) + \left(-4\right)}}{y}\right|\right| \]
      8. metadata-eval98.3%

        \[\leadsto \left|\left|\frac{\left(-x\right) + \color{blue}{-4}}{y}\right|\right| \]
      9. +-commutative98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{-4 + \left(-x\right)}}{y}\right|\right| \]
      10. sub-neg98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{-4 - x}}{y}\right|\right| \]
      11. rem-square-sqrt48.5%

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

        \[\leadsto \left|\color{blue}{\sqrt{\frac{-4 - x}{y}} \cdot \sqrt{\frac{-4 - x}{y}}}\right| \]
      13. rem-square-sqrt98.3%

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

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

    if 2.5e19 < z

    1. Initial program 88.8%

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

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

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

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

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

        \[\leadsto \left|-\color{blue}{\left(z - 1\right) \cdot \frac{x}{y}}\right| \]
      4. distribute-lft-neg-in80.9%

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

        \[\leadsto \left|\color{blue}{\left(0 - \left(z - 1\right)\right)} \cdot \frac{x}{y}\right| \]
      6. associate-+l-80.9%

        \[\leadsto \left|\color{blue}{\left(\left(0 - z\right) + 1\right)} \cdot \frac{x}{y}\right| \]
      7. neg-sub080.9%

        \[\leadsto \left|\left(\color{blue}{\left(-z\right)} + 1\right) \cdot \frac{x}{y}\right| \]
      8. +-commutative80.9%

        \[\leadsto \left|\color{blue}{\left(1 + \left(-z\right)\right)} \cdot \frac{x}{y}\right| \]
      9. unsub-neg80.9%

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

      \[\leadsto \left|\color{blue}{\left(1 - z\right) \cdot \frac{x}{y}}\right| \]
    7. Step-by-step derivation
      1. clear-num80.9%

        \[\leadsto \left|\left(1 - z\right) \cdot \color{blue}{\frac{1}{\frac{y}{x}}}\right| \]
      2. un-div-inv80.9%

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

        \[\leadsto \left|\frac{\color{blue}{1 + \left(-z\right)}}{\frac{y}{x}}\right| \]
      4. add-sqr-sqrt0.0%

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

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

        \[\leadsto \left|\frac{1 + \sqrt{\color{blue}{z \cdot z}}}{\frac{y}{x}}\right| \]
      7. sqrt-unprod80.6%

        \[\leadsto \left|\frac{1 + \color{blue}{\sqrt{z} \cdot \sqrt{z}}}{\frac{y}{x}}\right| \]
      8. add-sqr-sqrt80.9%

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

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

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

Alternative 5: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;y\_m \leq 2 \cdot 10^{+24}:\\ \;\;\;\;\left|\frac{4 + x \cdot \left(1 - z\right)}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{\left(z + -1\right) - \frac{4}{x}}{y\_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= y_m 2e+24)
   (fabs (/ (+ 4.0 (* x (- 1.0 z))) y_m))
   (fabs (* x (/ (- (+ z -1.0) (/ 4.0 x)) y_m)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (y_m <= 2e+24) {
		tmp = fabs(((4.0 + (x * (1.0 - z))) / y_m));
	} else {
		tmp = fabs((x * (((z + -1.0) - (4.0 / x)) / y_m)));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y_m <= 2d+24) then
        tmp = abs(((4.0d0 + (x * (1.0d0 - z))) / y_m))
    else
        tmp = abs((x * (((z + (-1.0d0)) - (4.0d0 / x)) / y_m)))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (y_m <= 2e+24) {
		tmp = Math.abs(((4.0 + (x * (1.0 - z))) / y_m));
	} else {
		tmp = Math.abs((x * (((z + -1.0) - (4.0 / x)) / y_m)));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if y_m <= 2e+24:
		tmp = math.fabs(((4.0 + (x * (1.0 - z))) / y_m))
	else:
		tmp = math.fabs((x * (((z + -1.0) - (4.0 / x)) / y_m)))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (y_m <= 2e+24)
		tmp = abs(Float64(Float64(4.0 + Float64(x * Float64(1.0 - z))) / y_m));
	else
		tmp = abs(Float64(x * Float64(Float64(Float64(z + -1.0) - Float64(4.0 / x)) / y_m)));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (y_m <= 2e+24)
		tmp = abs(((4.0 + (x * (1.0 - z))) / y_m));
	else
		tmp = abs((x * (((z + -1.0) - (4.0 / x)) / y_m)));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[y$95$m, 2e+24], N[Abs[N[(N[(4.0 + N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(N[(N[(z + -1.0), $MachinePrecision] - N[(4.0 / x), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 2e24

    1. Initial program 93.0%

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

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(x \cdot z - \left(4 + x\right)\right)}{y}}\right| \]
      2. associate--r+99.0%

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

        \[\leadsto \left|\frac{-1 \cdot \left(\color{blue}{\left(x \cdot z + \left(-4\right)\right)} - x\right)}{y}\right| \]
      4. metadata-eval99.0%

        \[\leadsto \left|\frac{-1 \cdot \left(\left(x \cdot z + \color{blue}{-4}\right) - x\right)}{y}\right| \]
      5. associate-+r-99.0%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(x \cdot z + \left(-4 - x\right)\right)}}{y}\right| \]
      6. fma-undefine99.0%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
      7. neg-mul-199.0%

        \[\leadsto \left|\frac{\color{blue}{-\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
    6. Simplified99.0%

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

    if 2e24 < y

    1. Initial program 93.9%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. fabs-sub93.9%

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

        \[\leadsto \left|\color{blue}{\frac{x \cdot z}{y}} - \frac{x + 4}{y}\right| \]
      3. associate-*r/99.9%

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

        \[\leadsto \left|\color{blue}{\mathsf{fma}\left(x, \frac{z}{y}, -\frac{x + 4}{y}\right)}\right| \]
      5. distribute-neg-frac99.9%

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \color{blue}{\frac{-\left(x + 4\right)}{y}}\right)\right| \]
      6. +-commutative99.9%

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-\color{blue}{\left(4 + x\right)}}{y}\right)\right| \]
      7. distribute-neg-in99.9%

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(-4\right) + \left(-x\right)}}{y}\right)\right| \]
      8. unsub-neg99.9%

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(-4\right) - x}}{y}\right)\right| \]
      9. metadata-eval99.9%

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{-4} - x}{y}\right)\right| \]
    3. Simplified99.9%

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

      \[\leadsto \left|\color{blue}{x \cdot \left(\frac{z}{y} - \left(\frac{1}{y} + 4 \cdot \frac{1}{x \cdot y}\right)\right)}\right| \]
    6. Step-by-step derivation
      1. associate--r+99.7%

        \[\leadsto \left|x \cdot \color{blue}{\left(\left(\frac{z}{y} - \frac{1}{y}\right) - 4 \cdot \frac{1}{x \cdot y}\right)}\right| \]
      2. div-sub99.7%

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

        \[\leadsto \left|x \cdot \left(\frac{\color{blue}{z + \left(-1\right)}}{y} - 4 \cdot \frac{1}{x \cdot y}\right)\right| \]
      4. metadata-eval99.7%

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

        \[\leadsto \left|x \cdot \left(\frac{\color{blue}{-1 + z}}{y} - 4 \cdot \frac{1}{x \cdot y}\right)\right| \]
      6. metadata-eval99.7%

        \[\leadsto \left|x \cdot \left(\frac{\color{blue}{-1 \cdot 1} + z}{y} - 4 \cdot \frac{1}{x \cdot y}\right)\right| \]
      7. remove-double-neg99.7%

        \[\leadsto \left|x \cdot \left(\frac{-1 \cdot 1 + \color{blue}{\left(-\left(-z\right)\right)}}{y} - 4 \cdot \frac{1}{x \cdot y}\right)\right| \]
      8. neg-mul-199.7%

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

        \[\leadsto \left|x \cdot \left(\frac{\color{blue}{-1 \cdot \left(1 + \left(-z\right)\right)}}{y} - 4 \cdot \frac{1}{x \cdot y}\right)\right| \]
      10. neg-mul-199.7%

        \[\leadsto \left|x \cdot \left(\frac{-1 \cdot \left(1 + \color{blue}{-1 \cdot z}\right)}{y} - 4 \cdot \frac{1}{x \cdot y}\right)\right| \]
      11. associate-*r/99.7%

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

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

        \[\leadsto \left|x \cdot \left(\frac{z + -1}{y} - \color{blue}{\frac{\frac{4}{x}}{y}}\right)\right| \]
      2. sub-div99.7%

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

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

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

Alternative 6: 84.3% accurate, 1.0× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;z \leq -380000:\\ \;\;\;\;\left|\frac{x \cdot z}{y\_m}\right|\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{+19}:\\ \;\;\;\;\left|\frac{-4 - x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y\_m}{x}}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= z -380000.0)
   (fabs (/ (* x z) y_m))
   (if (<= z 2.5e+19) (fabs (/ (- -4.0 x) y_m)) (fabs (/ z (/ y_m x))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -380000.0) {
		tmp = fabs(((x * z) / y_m));
	} else if (z <= 2.5e+19) {
		tmp = fabs(((-4.0 - x) / y_m));
	} else {
		tmp = fabs((z / (y_m / x)));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-380000.0d0)) then
        tmp = abs(((x * z) / y_m))
    else if (z <= 2.5d+19) then
        tmp = abs((((-4.0d0) - x) / y_m))
    else
        tmp = abs((z / (y_m / x)))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -380000.0) {
		tmp = Math.abs(((x * z) / y_m));
	} else if (z <= 2.5e+19) {
		tmp = Math.abs(((-4.0 - x) / y_m));
	} else {
		tmp = Math.abs((z / (y_m / x)));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if z <= -380000.0:
		tmp = math.fabs(((x * z) / y_m))
	elif z <= 2.5e+19:
		tmp = math.fabs(((-4.0 - x) / y_m))
	else:
		tmp = math.fabs((z / (y_m / x)))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (z <= -380000.0)
		tmp = abs(Float64(Float64(x * z) / y_m));
	elseif (z <= 2.5e+19)
		tmp = abs(Float64(Float64(-4.0 - x) / y_m));
	else
		tmp = abs(Float64(z / Float64(y_m / x)));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (z <= -380000.0)
		tmp = abs(((x * z) / y_m));
	elseif (z <= 2.5e+19)
		tmp = abs(((-4.0 - x) / y_m));
	else
		tmp = abs((z / (y_m / x)));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[z, -380000.0], N[Abs[N[(N[(x * z), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 2.5e+19], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(z / N[(y$95$m / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;z \leq -380000:\\
\;\;\;\;\left|\frac{x \cdot z}{y\_m}\right|\\

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

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


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

    1. Initial program 92.5%

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

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

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

        \[\leadsto \left|\color{blue}{-\frac{x \cdot z}{y}}\right| \]
      2. distribute-frac-neg274.6%

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

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

      \[\leadsto \left|\color{blue}{x \cdot \frac{z}{-y}}\right| \]
    7. Step-by-step derivation
      1. associate-*r/74.6%

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

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

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

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

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

        \[\leadsto \left|\frac{x \cdot z}{\color{blue}{y}}\right| \]
    8. Applied egg-rr74.6%

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

    if -3.8e5 < z < 2.5e19

    1. Initial program 95.5%

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

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

      \[\leadsto \left|\color{blue}{\frac{4 + x}{y}}\right| \]
    5. Step-by-step derivation
      1. +-commutative98.3%

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y}\right| \]
      2. rem-square-sqrt49.2%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}}\right| \]
      3. fabs-sqr49.2%

        \[\leadsto \left|\color{blue}{\left|\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}\right|}\right| \]
      4. rem-square-sqrt98.3%

        \[\leadsto \left|\left|\color{blue}{\frac{x + 4}{y}}\right|\right| \]
      5. fabs-neg98.3%

        \[\leadsto \left|\color{blue}{\left|-\frac{x + 4}{y}\right|}\right| \]
      6. distribute-neg-frac98.3%

        \[\leadsto \left|\left|\color{blue}{\frac{-\left(x + 4\right)}{y}}\right|\right| \]
      7. distribute-neg-in98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{\left(-x\right) + \left(-4\right)}}{y}\right|\right| \]
      8. metadata-eval98.3%

        \[\leadsto \left|\left|\frac{\left(-x\right) + \color{blue}{-4}}{y}\right|\right| \]
      9. +-commutative98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{-4 + \left(-x\right)}}{y}\right|\right| \]
      10. sub-neg98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{-4 - x}}{y}\right|\right| \]
      11. rem-square-sqrt48.5%

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

        \[\leadsto \left|\color{blue}{\sqrt{\frac{-4 - x}{y}} \cdot \sqrt{\frac{-4 - x}{y}}}\right| \]
      13. rem-square-sqrt98.3%

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

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

    if 2.5e19 < z

    1. Initial program 88.8%

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{x \cdot \frac{z}{-y}}\right| \]
    7. Step-by-step derivation
      1. clear-num76.3%

        \[\leadsto \left|x \cdot \color{blue}{\frac{1}{\frac{-y}{z}}}\right| \]
      2. un-div-inv77.1%

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{z}}}\right| \]
    9. Step-by-step derivation
      1. associate-/r/80.9%

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot z}\right| \]
      2. *-commutative80.9%

        \[\leadsto \left|\color{blue}{z \cdot \frac{x}{y}}\right| \]
    10. Simplified80.9%

      \[\leadsto \left|\color{blue}{z \cdot \frac{x}{y}}\right| \]
    11. Step-by-step derivation
      1. clear-num80.9%

        \[\leadsto \left|z \cdot \color{blue}{\frac{1}{\frac{y}{x}}}\right| \]
      2. un-div-inv80.9%

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

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

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

Alternative 7: 84.4% accurate, 1.0× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;z \leq -320000:\\ \;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y\_m}\right|\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+20}:\\ \;\;\;\;\left|\frac{-4 - x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y\_m}{x}}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= z -320000.0)
   (fabs (/ (* x (- 1.0 z)) y_m))
   (if (<= z 1.15e+20) (fabs (/ (- -4.0 x) y_m)) (fabs (/ z (/ y_m x))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -320000.0) {
		tmp = fabs(((x * (1.0 - z)) / y_m));
	} else if (z <= 1.15e+20) {
		tmp = fabs(((-4.0 - x) / y_m));
	} else {
		tmp = fabs((z / (y_m / x)));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-320000.0d0)) then
        tmp = abs(((x * (1.0d0 - z)) / y_m))
    else if (z <= 1.15d+20) then
        tmp = abs((((-4.0d0) - x) / y_m))
    else
        tmp = abs((z / (y_m / x)))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -320000.0) {
		tmp = Math.abs(((x * (1.0 - z)) / y_m));
	} else if (z <= 1.15e+20) {
		tmp = Math.abs(((-4.0 - x) / y_m));
	} else {
		tmp = Math.abs((z / (y_m / x)));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if z <= -320000.0:
		tmp = math.fabs(((x * (1.0 - z)) / y_m))
	elif z <= 1.15e+20:
		tmp = math.fabs(((-4.0 - x) / y_m))
	else:
		tmp = math.fabs((z / (y_m / x)))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (z <= -320000.0)
		tmp = abs(Float64(Float64(x * Float64(1.0 - z)) / y_m));
	elseif (z <= 1.15e+20)
		tmp = abs(Float64(Float64(-4.0 - x) / y_m));
	else
		tmp = abs(Float64(z / Float64(y_m / x)));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (z <= -320000.0)
		tmp = abs(((x * (1.0 - z)) / y_m));
	elseif (z <= 1.15e+20)
		tmp = abs(((-4.0 - x) / y_m));
	else
		tmp = abs((z / (y_m / x)));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[z, -320000.0], N[Abs[N[(N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 1.15e+20], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(z / N[(y$95$m / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;z \leq -320000:\\
\;\;\;\;\left|\frac{x \cdot \left(1 - z\right)}{y\_m}\right|\\

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

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


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

    1. Initial program 92.5%

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

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(x \cdot z - \left(4 + x\right)\right)}{y}}\right| \]
      2. associate--r+98.4%

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

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

        \[\leadsto \left|\frac{-1 \cdot \left(\left(x \cdot z + \color{blue}{-4}\right) - x\right)}{y}\right| \]
      5. associate-+r-98.4%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(x \cdot z + \left(-4 - x\right)\right)}}{y}\right| \]
      6. fma-undefine98.4%

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
      7. neg-mul-198.4%

        \[\leadsto \left|\frac{\color{blue}{-\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
    6. Simplified98.4%

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

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

    if -3.2e5 < z < 1.15e20

    1. Initial program 95.5%

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

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

      \[\leadsto \left|\color{blue}{\frac{4 + x}{y}}\right| \]
    5. Step-by-step derivation
      1. +-commutative98.3%

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y}\right| \]
      2. rem-square-sqrt49.2%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}}\right| \]
      3. fabs-sqr49.2%

        \[\leadsto \left|\color{blue}{\left|\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}\right|}\right| \]
      4. rem-square-sqrt98.3%

        \[\leadsto \left|\left|\color{blue}{\frac{x + 4}{y}}\right|\right| \]
      5. fabs-neg98.3%

        \[\leadsto \left|\color{blue}{\left|-\frac{x + 4}{y}\right|}\right| \]
      6. distribute-neg-frac98.3%

        \[\leadsto \left|\left|\color{blue}{\frac{-\left(x + 4\right)}{y}}\right|\right| \]
      7. distribute-neg-in98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{\left(-x\right) + \left(-4\right)}}{y}\right|\right| \]
      8. metadata-eval98.3%

        \[\leadsto \left|\left|\frac{\left(-x\right) + \color{blue}{-4}}{y}\right|\right| \]
      9. +-commutative98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{-4 + \left(-x\right)}}{y}\right|\right| \]
      10. sub-neg98.3%

        \[\leadsto \left|\left|\frac{\color{blue}{-4 - x}}{y}\right|\right| \]
      11. rem-square-sqrt48.5%

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

        \[\leadsto \left|\color{blue}{\sqrt{\frac{-4 - x}{y}} \cdot \sqrt{\frac{-4 - x}{y}}}\right| \]
      13. rem-square-sqrt98.3%

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

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

    if 1.15e20 < z

    1. Initial program 88.8%

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{x \cdot \frac{z}{-y}}\right| \]
    7. Step-by-step derivation
      1. clear-num76.3%

        \[\leadsto \left|x \cdot \color{blue}{\frac{1}{\frac{-y}{z}}}\right| \]
      2. un-div-inv77.1%

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{z}}}\right| \]
    9. Step-by-step derivation
      1. associate-/r/80.9%

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot z}\right| \]
      2. *-commutative80.9%

        \[\leadsto \left|\color{blue}{z \cdot \frac{x}{y}}\right| \]
    10. Simplified80.9%

      \[\leadsto \left|\color{blue}{z \cdot \frac{x}{y}}\right| \]
    11. Step-by-step derivation
      1. clear-num80.9%

        \[\leadsto \left|z \cdot \color{blue}{\frac{1}{\frac{y}{x}}}\right| \]
      2. un-div-inv80.9%

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

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

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

Alternative 8: 69.8% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 91.9%

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

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

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

        \[\leadsto \left|\color{blue}{-\frac{x \cdot \left(z - 1\right)}{y}}\right| \]
      2. *-commutative93.0%

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

        \[\leadsto \left|-\color{blue}{\left(z - 1\right) \cdot \frac{x}{y}}\right| \]
      4. distribute-lft-neg-in97.8%

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

        \[\leadsto \left|\color{blue}{\left(0 - \left(z - 1\right)\right)} \cdot \frac{x}{y}\right| \]
      6. associate-+l-97.8%

        \[\leadsto \left|\color{blue}{\left(\left(0 - z\right) + 1\right)} \cdot \frac{x}{y}\right| \]
      7. neg-sub097.8%

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

        \[\leadsto \left|\color{blue}{\left(1 + \left(-z\right)\right)} \cdot \frac{x}{y}\right| \]
      9. unsub-neg97.8%

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

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

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

    if -1.5 < x < 4

    1. Initial program 94.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.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: 95.9% accurate, 1.0× speedup?

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

\\
\left|\frac{4 + x \cdot \left(1 - z\right)}{y\_m}\right|
\end{array}
Derivation
  1. Initial program 93.2%

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

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

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

      \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(x \cdot z - \left(4 + x\right)\right)}{y}}\right| \]
    2. associate--r+97.4%

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

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

      \[\leadsto \left|\frac{-1 \cdot \left(\left(x \cdot z + \color{blue}{-4}\right) - x\right)}{y}\right| \]
    5. associate-+r-97.4%

      \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(x \cdot z + \left(-4 - x\right)\right)}}{y}\right| \]
    6. fma-undefine97.4%

      \[\leadsto \left|\frac{-1 \cdot \color{blue}{\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
    7. neg-mul-197.4%

      \[\leadsto \left|\frac{\color{blue}{-\mathsf{fma}\left(x, z, -4 - x\right)}}{y}\right| \]
  6. Simplified97.4%

    \[\leadsto \left|\color{blue}{\frac{4 + x \cdot \left(1 - z\right)}{y}}\right| \]
  7. Final simplification97.4%

    \[\leadsto \left|\frac{4 + x \cdot \left(1 - z\right)}{y}\right| \]
  8. Add Preprocessing

Alternative 10: 41.0% accurate, 1.1× speedup?

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

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

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

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

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

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

Reproduce

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