fabs fraction 1

Percentage Accurate: 91.8% → 99.8%
Time: 2.6s
Alternatives: 9
Speedup: 1.3×

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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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}

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.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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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.8% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 4 \cdot 10^{-36}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4 - x\right)}{y\_m}\right|\\

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


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

    1. Initial program 91.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
      3. lift-*.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
      4. lift-/.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      6. sub-divN/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      7. lower-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      8. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
      10. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      11. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      12. metadata-evalN/A

        \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
      13. *-commutativeN/A

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      14. lower-*.f6495.8

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
    3. Applied rewrites95.8%

      \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
    4. Step-by-step derivation
      1. lift-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x - -4\right) - z \cdot x}{y}}\right| \]
      3. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - -4\right) - z \cdot x}}{y}\right| \]
      4. div-subN/A

        \[\leadsto \left|\color{blue}{\frac{x - -4}{y} - \frac{z \cdot x}{y}}\right| \]
      5. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x - -4}}{y} - \frac{z \cdot x}{y}\right| \]
      6. metadata-evalN/A

        \[\leadsto \left|\frac{x - \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}}{y} - \frac{z \cdot x}{y}\right| \]
      7. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      8. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{z \cdot x}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      10. lift-*.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{y} \cdot x}\right| \]
      12. associate-/r/N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      13. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \frac{z}{\color{blue}{\frac{y}{x}}}\right| \]
      14. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      15. fabs-subN/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      16. lower-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      17. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      18. lift-/.f64N/A

        \[\leadsto \left|\frac{z}{\color{blue}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      19. associate-/r/N/A

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

        \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}} - \frac{x + 4}{y}\right| \]
      21. lift-*.f64N/A

        \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
      22. lift-+.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \frac{\color{blue}{x + 4}}{y}\right| \]
      23. lift-/.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{x + 4}{y}}\right| \]
    5. Applied rewrites95.8%

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

    if 3.9999999999999998e-36 < y

    1. Initial program 91.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
      2. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y}} \cdot z\right| \]
      3. mult-flipN/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\left(x \cdot \frac{1}{y}\right)} \cdot z\right| \]
      4. associate-*l*N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{x \cdot \left(\frac{1}{y} \cdot z\right)}\right| \]
      5. lower-*.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{x \cdot \left(\frac{1}{y} \cdot z\right)}\right| \]
      6. lower-*.f64N/A

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

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

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

Alternative 2: 99.0% accurate, 0.8× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \left|x \cdot \left(\frac{1}{y\_m} - \frac{z}{y\_m}\right)\right|\\ \mathbf{if}\;x \leq -1.6 \cdot 10^{+123}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 0.00045:\\ \;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4 - x\right)}{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 (* x (- (/ 1.0 y_m) (/ z y_m))))))
   (if (<= x -1.6e+123)
     t_0
     (if (<= x 0.00045) (fabs (/ (fma z x (- -4.0 x)) y_m)) t_0))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double t_0 = fabs((x * ((1.0 / y_m) - (z / y_m))));
	double tmp;
	if (x <= -1.6e+123) {
		tmp = t_0;
	} else if (x <= 0.00045) {
		tmp = fabs((fma(z, x, (-4.0 - x)) / y_m));
	} else {
		tmp = t_0;
	}
	return tmp;
}
y_m = abs(y)
function code(x, y_m, z)
	t_0 = abs(Float64(x * Float64(Float64(1.0 / y_m) - Float64(z / y_m))))
	tmp = 0.0
	if (x <= -1.6e+123)
		tmp = t_0;
	elseif (x <= 0.00045)
		tmp = abs(Float64(fma(z, x, Float64(-4.0 - x)) / y_m));
	else
		tmp = t_0;
	end
	return tmp
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := Block[{t$95$0 = N[Abs[N[(x * N[(N[(1.0 / y$95$m), $MachinePrecision] - N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -1.6e+123], t$95$0, If[LessEqual[x, 0.00045], N[Abs[N[(N[(z * x + N[(-4.0 - x), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := \left|x \cdot \left(\frac{1}{y\_m} - \frac{z}{y\_m}\right)\right|\\
\mathbf{if}\;x \leq -1.6 \cdot 10^{+123}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.60000000000000002e123 or 4.4999999999999999e-4 < x

    1. Initial program 91.8%

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

      \[\leadsto \left|\color{blue}{x \cdot \left(\frac{1}{y} - \frac{z}{y}\right)}\right| \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left|x \cdot \color{blue}{\left(\frac{1}{y} - \frac{z}{y}\right)}\right| \]
      2. lower--.f64N/A

        \[\leadsto \left|x \cdot \left(\frac{1}{y} - \color{blue}{\frac{z}{y}}\right)\right| \]
      3. lower-/.f64N/A

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

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

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

    if -1.60000000000000002e123 < x < 4.4999999999999999e-4

    1. Initial program 91.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
      3. lift-*.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
      4. lift-/.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      6. sub-divN/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      7. lower-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      8. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
      10. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      11. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      12. metadata-evalN/A

        \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
      13. *-commutativeN/A

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      14. lower-*.f6495.8

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
    3. Applied rewrites95.8%

      \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
    4. Step-by-step derivation
      1. lift-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x - -4\right) - z \cdot x}{y}}\right| \]
      3. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - -4\right) - z \cdot x}}{y}\right| \]
      4. div-subN/A

        \[\leadsto \left|\color{blue}{\frac{x - -4}{y} - \frac{z \cdot x}{y}}\right| \]
      5. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x - -4}}{y} - \frac{z \cdot x}{y}\right| \]
      6. metadata-evalN/A

        \[\leadsto \left|\frac{x - \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}}{y} - \frac{z \cdot x}{y}\right| \]
      7. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      8. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{z \cdot x}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      10. lift-*.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{y} \cdot x}\right| \]
      12. associate-/r/N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      13. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \frac{z}{\color{blue}{\frac{y}{x}}}\right| \]
      14. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      15. fabs-subN/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      16. lower-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      17. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      18. lift-/.f64N/A

        \[\leadsto \left|\frac{z}{\color{blue}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      19. associate-/r/N/A

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

        \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}} - \frac{x + 4}{y}\right| \]
      21. lift-*.f64N/A

        \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
      22. lift-+.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \frac{\color{blue}{x + 4}}{y}\right| \]
      23. lift-/.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{x + 4}{y}}\right| \]
    5. Applied rewrites95.8%

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

Alternative 3: 98.0% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 10:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4 - x\right)}{y\_m}\right|\\

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


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

    1. Initial program 91.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
      3. lift-*.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
      4. lift-/.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      6. sub-divN/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      7. lower-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      8. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
      10. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      11. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      12. metadata-evalN/A

        \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
      13. *-commutativeN/A

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      14. lower-*.f6495.8

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
    3. Applied rewrites95.8%

      \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
    4. Step-by-step derivation
      1. lift-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x - -4\right) - z \cdot x}{y}}\right| \]
      3. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - -4\right) - z \cdot x}}{y}\right| \]
      4. div-subN/A

        \[\leadsto \left|\color{blue}{\frac{x - -4}{y} - \frac{z \cdot x}{y}}\right| \]
      5. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x - -4}}{y} - \frac{z \cdot x}{y}\right| \]
      6. metadata-evalN/A

        \[\leadsto \left|\frac{x - \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}}{y} - \frac{z \cdot x}{y}\right| \]
      7. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      8. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{z \cdot x}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      10. lift-*.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{y} \cdot x}\right| \]
      12. associate-/r/N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      13. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \frac{z}{\color{blue}{\frac{y}{x}}}\right| \]
      14. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      15. fabs-subN/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      16. lower-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      17. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      18. lift-/.f64N/A

        \[\leadsto \left|\frac{z}{\color{blue}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      19. associate-/r/N/A

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

        \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}} - \frac{x + 4}{y}\right| \]
      21. lift-*.f64N/A

        \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
      22. lift-+.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \frac{\color{blue}{x + 4}}{y}\right| \]
      23. lift-/.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{x + 4}{y}}\right| \]
    5. Applied rewrites95.8%

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

    if 10 < y

    1. Initial program 91.8%

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

Alternative 4: 95.8% accurate, 1.3× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \left|\frac{\mathsf{fma}\left(z, x, -4 - x\right)}{y\_m}\right| \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z) :precision binary64 (fabs (/ (fma z x (- -4.0 x)) y_m)))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	return fabs((fma(z, x, (-4.0 - x)) / y_m));
}
y_m = abs(y)
function code(x, y_m, z)
	return abs(Float64(fma(z, x, Float64(-4.0 - x)) / y_m))
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := N[Abs[N[(N[(z * x + N[(-4.0 - x), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|

\\
\left|\frac{\mathsf{fma}\left(z, x, -4 - x\right)}{y\_m}\right|
\end{array}
Derivation
  1. Initial program 91.8%

    \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
  2. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
    2. lift-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
    3. lift-*.f64N/A

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
    4. lift-/.f64N/A

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

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
    6. sub-divN/A

      \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
    7. lower-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
    8. lower--.f64N/A

      \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
    9. lift-+.f64N/A

      \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
    10. add-flipN/A

      \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
    11. lower--.f64N/A

      \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
    12. metadata-evalN/A

      \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
    13. *-commutativeN/A

      \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
    14. lower-*.f6495.8

      \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
  3. Applied rewrites95.8%

    \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
  4. Step-by-step derivation
    1. lift-fabs.f64N/A

      \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
    2. lift-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{\left(x - -4\right) - z \cdot x}{y}}\right| \]
    3. lift--.f64N/A

      \[\leadsto \left|\frac{\color{blue}{\left(x - -4\right) - z \cdot x}}{y}\right| \]
    4. div-subN/A

      \[\leadsto \left|\color{blue}{\frac{x - -4}{y} - \frac{z \cdot x}{y}}\right| \]
    5. lift--.f64N/A

      \[\leadsto \left|\frac{\color{blue}{x - -4}}{y} - \frac{z \cdot x}{y}\right| \]
    6. metadata-evalN/A

      \[\leadsto \left|\frac{x - \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}}{y} - \frac{z \cdot x}{y}\right| \]
    7. add-flipN/A

      \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
    8. lift-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{z \cdot x}{y}\right| \]
    9. lift-+.f64N/A

      \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
    10. lift-*.f64N/A

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

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{y} \cdot x}\right| \]
    12. associate-/r/N/A

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    13. lift-/.f64N/A

      \[\leadsto \left|\frac{x + 4}{y} - \frac{z}{\color{blue}{\frac{y}{x}}}\right| \]
    14. lift-/.f64N/A

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    15. fabs-subN/A

      \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
    16. lower-fabs.f64N/A

      \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
    17. lift-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
    18. lift-/.f64N/A

      \[\leadsto \left|\frac{z}{\color{blue}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
    19. associate-/r/N/A

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

      \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}} - \frac{x + 4}{y}\right| \]
    21. lift-*.f64N/A

      \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
    22. lift-+.f64N/A

      \[\leadsto \left|\frac{z \cdot x}{y} - \frac{\color{blue}{x + 4}}{y}\right| \]
    23. lift-/.f64N/A

      \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{x + 4}{y}}\right| \]
  5. Applied rewrites95.8%

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

Alternative 5: 94.6% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \left|\frac{x \cdot \left(1 - z\right)}{y\_m}\right|\\ \mathbf{if}\;x \leq -54:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 0.00045:\\ \;\;\;\;\left|\frac{z \cdot x - 4}{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 (/ (* x (- 1.0 z)) y_m))))
   (if (<= x -54.0)
     t_0
     (if (<= x 0.00045) (fabs (/ (- (* z x) 4.0) y_m)) t_0))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double t_0 = fabs(((x * (1.0 - z)) / y_m));
	double tmp;
	if (x <= -54.0) {
		tmp = t_0;
	} else if (x <= 0.00045) {
		tmp = fabs((((z * x) - 4.0) / y_m));
	} else {
		tmp = t_0;
	}
	return tmp;
}
y_m =     private
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y_m, z)
use fmin_fmax_functions
    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(((x * (1.0d0 - z)) / y_m))
    if (x <= (-54.0d0)) then
        tmp = t_0
    else if (x <= 0.00045d0) then
        tmp = abs((((z * x) - 4.0d0) / 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(((x * (1.0 - z)) / y_m));
	double tmp;
	if (x <= -54.0) {
		tmp = t_0;
	} else if (x <= 0.00045) {
		tmp = Math.abs((((z * x) - 4.0) / y_m));
	} else {
		tmp = t_0;
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	t_0 = math.fabs(((x * (1.0 - z)) / y_m))
	tmp = 0
	if x <= -54.0:
		tmp = t_0
	elif x <= 0.00045:
		tmp = math.fabs((((z * x) - 4.0) / y_m))
	else:
		tmp = t_0
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	t_0 = abs(Float64(Float64(x * Float64(1.0 - z)) / y_m))
	tmp = 0.0
	if (x <= -54.0)
		tmp = t_0;
	elseif (x <= 0.00045)
		tmp = abs(Float64(Float64(Float64(z * x) - 4.0) / 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(((x * (1.0 - z)) / y_m));
	tmp = 0.0;
	if (x <= -54.0)
		tmp = t_0;
	elseif (x <= 0.00045)
		tmp = abs((((z * x) - 4.0) / 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[(N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -54.0], t$95$0, If[LessEqual[x, 0.00045], N[Abs[N[(N[(N[(z * x), $MachinePrecision] - 4.0), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
y_m = \left|y\right|

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

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

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


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

    1. Initial program 91.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
      3. lift-*.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
      4. lift-/.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      6. sub-divN/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      7. lower-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      8. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
      10. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      11. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      12. metadata-evalN/A

        \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
      13. *-commutativeN/A

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      14. lower-*.f6495.8

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
    3. Applied rewrites95.8%

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

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

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

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

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

    if -54 < x < 4.4999999999999999e-4

    1. Initial program 91.8%

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

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

        \[\leadsto \left|\frac{\color{blue}{4}}{y} - \frac{x}{y} \cdot z\right| \]
      2. Step-by-step derivation
        1. lift-fabs.f64N/A

          \[\leadsto \color{blue}{\left|\frac{4}{y} - \frac{x}{y} \cdot z\right|} \]
        2. lift--.f64N/A

          \[\leadsto \left|\color{blue}{\frac{4}{y} - \frac{x}{y} \cdot z}\right| \]
        3. fabs-subN/A

          \[\leadsto \color{blue}{\left|\frac{x}{y} \cdot z - \frac{4}{y}\right|} \]
        4. lower-fabs.f64N/A

          \[\leadsto \color{blue}{\left|\frac{x}{y} \cdot z - \frac{4}{y}\right|} \]
        5. lift-*.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot z} - \frac{4}{y}\right| \]
        6. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x}{y}} \cdot z - \frac{4}{y}\right| \]
        7. associate-*l/N/A

          \[\leadsto \left|\color{blue}{\frac{x \cdot z}{y}} - \frac{4}{y}\right| \]
        8. *-commutativeN/A

          \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{4}{y}\right| \]
        9. lift-*.f64N/A

          \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{4}{y}\right| \]
        10. lift-/.f64N/A

          \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{4}{y}}\right| \]
        11. sub-divN/A

          \[\leadsto \left|\color{blue}{\frac{z \cdot x - 4}{y}}\right| \]
        12. lower-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{z \cdot x - 4}{y}}\right| \]
        13. lower--.f6474.0

          \[\leadsto \left|\frac{\color{blue}{z \cdot x - 4}}{y}\right| \]
      3. Applied rewrites74.0%

        \[\leadsto \color{blue}{\left|\frac{z \cdot x - 4}{y}\right|} \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 6: 83.9% accurate, 0.4× speedup?

    \[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \frac{x + 4}{y\_m} - \frac{x}{y\_m} \cdot z\\ t_1 := \left|\frac{x \cdot \left(1 - z\right)}{y\_m}\right|\\ \mathbf{if}\;t\_0 \leq 2 \cdot 10^{-297}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+292}:\\ \;\;\;\;\left|\frac{-4 - x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
    y_m = (fabs.f64 y)
    (FPCore (x y_m z)
     :precision binary64
     (let* ((t_0 (- (/ (+ x 4.0) y_m) (* (/ x y_m) z)))
            (t_1 (fabs (/ (* x (- 1.0 z)) y_m))))
       (if (<= t_0 2e-297)
         t_1
         (if (<= t_0 2e+292) (fabs (/ (- -4.0 x) y_m)) t_1))))
    y_m = fabs(y);
    double code(double x, double y_m, double z) {
    	double t_0 = ((x + 4.0) / y_m) - ((x / y_m) * z);
    	double t_1 = fabs(((x * (1.0 - z)) / y_m));
    	double tmp;
    	if (t_0 <= 2e-297) {
    		tmp = t_1;
    	} else if (t_0 <= 2e+292) {
    		tmp = fabs(((-4.0 - x) / y_m));
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    y_m =     private
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y_m, z)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y_m
        real(8), intent (in) :: z
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = ((x + 4.0d0) / y_m) - ((x / y_m) * z)
        t_1 = abs(((x * (1.0d0 - z)) / y_m))
        if (t_0 <= 2d-297) then
            tmp = t_1
        else if (t_0 <= 2d+292) then
            tmp = abs((((-4.0d0) - x) / y_m))
        else
            tmp = t_1
        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 = ((x + 4.0) / y_m) - ((x / y_m) * z);
    	double t_1 = Math.abs(((x * (1.0 - z)) / y_m));
    	double tmp;
    	if (t_0 <= 2e-297) {
    		tmp = t_1;
    	} else if (t_0 <= 2e+292) {
    		tmp = Math.abs(((-4.0 - x) / y_m));
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    y_m = math.fabs(y)
    def code(x, y_m, z):
    	t_0 = ((x + 4.0) / y_m) - ((x / y_m) * z)
    	t_1 = math.fabs(((x * (1.0 - z)) / y_m))
    	tmp = 0
    	if t_0 <= 2e-297:
    		tmp = t_1
    	elif t_0 <= 2e+292:
    		tmp = math.fabs(((-4.0 - x) / y_m))
    	else:
    		tmp = t_1
    	return tmp
    
    y_m = abs(y)
    function code(x, y_m, z)
    	t_0 = Float64(Float64(Float64(x + 4.0) / y_m) - Float64(Float64(x / y_m) * z))
    	t_1 = abs(Float64(Float64(x * Float64(1.0 - z)) / y_m))
    	tmp = 0.0
    	if (t_0 <= 2e-297)
    		tmp = t_1;
    	elseif (t_0 <= 2e+292)
    		tmp = abs(Float64(Float64(-4.0 - x) / y_m));
    	else
    		tmp = t_1;
    	end
    	return tmp
    end
    
    y_m = abs(y);
    function tmp_2 = code(x, y_m, z)
    	t_0 = ((x + 4.0) / y_m) - ((x / y_m) * z);
    	t_1 = abs(((x * (1.0 - z)) / y_m));
    	tmp = 0.0;
    	if (t_0 <= 2e-297)
    		tmp = t_1;
    	elseif (t_0 <= 2e+292)
    		tmp = abs(((-4.0 - x) / y_m));
    	else
    		tmp = t_1;
    	end
    	tmp_2 = tmp;
    end
    
    y_m = N[Abs[y], $MachinePrecision]
    code[x_, y$95$m_, z_] := Block[{t$95$0 = N[(N[(N[(x + 4.0), $MachinePrecision] / y$95$m), $MachinePrecision] - N[(N[(x / y$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 2e-297], t$95$1, If[LessEqual[t$95$0, 2e+292], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], t$95$1]]]]
    
    \begin{array}{l}
    y_m = \left|y\right|
    
    \\
    \begin{array}{l}
    t_0 := \frac{x + 4}{y\_m} - \frac{x}{y\_m} \cdot z\\
    t_1 := \left|\frac{x \cdot \left(1 - z\right)}{y\_m}\right|\\
    \mathbf{if}\;t\_0 \leq 2 \cdot 10^{-297}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+292}:\\
    \;\;\;\;\left|\frac{-4 - x}{y\_m}\right|\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z)) < 2.00000000000000008e-297 or 2e292 < (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z))

      1. Initial program 91.8%

        \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
        2. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
        3. lift-*.f64N/A

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
        4. lift-/.f64N/A

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

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
        6. sub-divN/A

          \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
        7. lower-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
        8. lower--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
        9. lift-+.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
        10. add-flipN/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
        11. lower--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
        12. metadata-evalN/A

          \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
        13. *-commutativeN/A

          \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
        14. lower-*.f6495.8

          \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      3. Applied rewrites95.8%

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

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

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

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

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

      if 2.00000000000000008e-297 < (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z)) < 2e292

      1. Initial program 91.8%

        \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
        2. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
        3. lift-*.f64N/A

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
        4. lift-/.f64N/A

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

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
        6. sub-divN/A

          \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
        7. lower-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
        8. lower--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
        9. lift-+.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
        10. add-flipN/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
        11. lower--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
        12. metadata-evalN/A

          \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
        13. *-commutativeN/A

          \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
        14. lower-*.f6495.8

          \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      3. Applied rewrites95.8%

        \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
      4. Step-by-step derivation
        1. lift-fabs.f64N/A

          \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
        2. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{\left(x - -4\right) - z \cdot x}{y}}\right| \]
        3. lift--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - -4\right) - z \cdot x}}{y}\right| \]
        4. div-subN/A

          \[\leadsto \left|\color{blue}{\frac{x - -4}{y} - \frac{z \cdot x}{y}}\right| \]
        5. lift--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{x - -4}}{y} - \frac{z \cdot x}{y}\right| \]
        6. metadata-evalN/A

          \[\leadsto \left|\frac{x - \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}}{y} - \frac{z \cdot x}{y}\right| \]
        7. add-flipN/A

          \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
        8. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{z \cdot x}{y}\right| \]
        9. lift-+.f64N/A

          \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
        10. lift-*.f64N/A

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

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{y} \cdot x}\right| \]
        12. associate-/r/N/A

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
        13. lift-/.f64N/A

          \[\leadsto \left|\frac{x + 4}{y} - \frac{z}{\color{blue}{\frac{y}{x}}}\right| \]
        14. lift-/.f64N/A

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
        15. fabs-subN/A

          \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
        16. lower-fabs.f64N/A

          \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
        17. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
        18. lift-/.f64N/A

          \[\leadsto \left|\frac{z}{\color{blue}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
        19. associate-/r/N/A

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

          \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}} - \frac{x + 4}{y}\right| \]
        21. lift-*.f64N/A

          \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
        22. lift-+.f64N/A

          \[\leadsto \left|\frac{z \cdot x}{y} - \frac{\color{blue}{x + 4}}{y}\right| \]
        23. lift-/.f64N/A

          \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{x + 4}{y}}\right| \]
      5. Applied rewrites95.8%

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

        \[\leadsto \left|\frac{\color{blue}{-1 \cdot \left(4 + x\right)}}{y}\right| \]
      7. Step-by-step derivation
        1. lower-*.f64N/A

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

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

        \[\leadsto \left|\frac{\color{blue}{-1 \cdot \left(4 + x\right)}}{y}\right| \]
      9. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(4 + x\right)}}{y}\right| \]
        2. lift-+.f64N/A

          \[\leadsto \left|\frac{-1 \cdot \left(4 + \color{blue}{x}\right)}{y}\right| \]
        3. distribute-lft-inN/A

          \[\leadsto \left|\frac{-1 \cdot 4 + \color{blue}{-1 \cdot x}}{y}\right| \]
        4. metadata-evalN/A

          \[\leadsto \left|\frac{-4 + \color{blue}{-1} \cdot x}{y}\right| \]
        5. mul-1-negN/A

          \[\leadsto \left|\frac{-4 + \left(\mathsf{neg}\left(x\right)\right)}{y}\right| \]
        6. sub-flipN/A

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

          \[\leadsto \left|\frac{-4 - \color{blue}{x}}{y}\right| \]
      10. Applied rewrites69.7%

        \[\leadsto \color{blue}{\left|\frac{-4 - x}{y}\right|} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 7: 70.8% accurate, 1.4× speedup?

    \[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;z \leq 1.37 \cdot 10^{+216}:\\ \;\;\;\;\left|\frac{-4 - x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-z\right) \cdot x}{y\_m}\\ \end{array} \end{array} \]
    y_m = (fabs.f64 y)
    (FPCore (x y_m z)
     :precision binary64
     (if (<= z 1.37e+216) (fabs (/ (- -4.0 x) y_m)) (/ (* (- z) x) y_m)))
    y_m = fabs(y);
    double code(double x, double y_m, double z) {
    	double tmp;
    	if (z <= 1.37e+216) {
    		tmp = fabs(((-4.0 - x) / y_m));
    	} else {
    		tmp = (-z * x) / y_m;
    	}
    	return tmp;
    }
    
    y_m =     private
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y_m, z)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y_m
        real(8), intent (in) :: z
        real(8) :: tmp
        if (z <= 1.37d+216) then
            tmp = abs((((-4.0d0) - x) / y_m))
        else
            tmp = (-z * 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 (z <= 1.37e+216) {
    		tmp = Math.abs(((-4.0 - x) / y_m));
    	} else {
    		tmp = (-z * x) / y_m;
    	}
    	return tmp;
    }
    
    y_m = math.fabs(y)
    def code(x, y_m, z):
    	tmp = 0
    	if z <= 1.37e+216:
    		tmp = math.fabs(((-4.0 - x) / y_m))
    	else:
    		tmp = (-z * x) / y_m
    	return tmp
    
    y_m = abs(y)
    function code(x, y_m, z)
    	tmp = 0.0
    	if (z <= 1.37e+216)
    		tmp = abs(Float64(Float64(-4.0 - x) / y_m));
    	else
    		tmp = Float64(Float64(Float64(-z) * x) / y_m);
    	end
    	return tmp
    end
    
    y_m = abs(y);
    function tmp_2 = code(x, y_m, z)
    	tmp = 0.0;
    	if (z <= 1.37e+216)
    		tmp = abs(((-4.0 - x) / y_m));
    	else
    		tmp = (-z * x) / y_m;
    	end
    	tmp_2 = tmp;
    end
    
    y_m = N[Abs[y], $MachinePrecision]
    code[x_, y$95$m_, z_] := If[LessEqual[z, 1.37e+216], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[(N[((-z) * x), $MachinePrecision] / y$95$m), $MachinePrecision]]
    
    \begin{array}{l}
    y_m = \left|y\right|
    
    \\
    \begin{array}{l}
    \mathbf{if}\;z \leq 1.37 \cdot 10^{+216}:\\
    \;\;\;\;\left|\frac{-4 - x}{y\_m}\right|\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{\left(-z\right) \cdot x}{y\_m}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if z < 1.3700000000000001e216

      1. Initial program 91.8%

        \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
        2. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
        3. lift-*.f64N/A

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
        4. lift-/.f64N/A

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

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
        6. sub-divN/A

          \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
        7. lower-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
        8. lower--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
        9. lift-+.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
        10. add-flipN/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
        11. lower--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
        12. metadata-evalN/A

          \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
        13. *-commutativeN/A

          \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
        14. lower-*.f6495.8

          \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      3. Applied rewrites95.8%

        \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
      4. Step-by-step derivation
        1. lift-fabs.f64N/A

          \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
        2. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{\left(x - -4\right) - z \cdot x}{y}}\right| \]
        3. lift--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\left(x - -4\right) - z \cdot x}}{y}\right| \]
        4. div-subN/A

          \[\leadsto \left|\color{blue}{\frac{x - -4}{y} - \frac{z \cdot x}{y}}\right| \]
        5. lift--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{x - -4}}{y} - \frac{z \cdot x}{y}\right| \]
        6. metadata-evalN/A

          \[\leadsto \left|\frac{x - \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}}{y} - \frac{z \cdot x}{y}\right| \]
        7. add-flipN/A

          \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
        8. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{z \cdot x}{y}\right| \]
        9. lift-+.f64N/A

          \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
        10. lift-*.f64N/A

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

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{y} \cdot x}\right| \]
        12. associate-/r/N/A

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
        13. lift-/.f64N/A

          \[\leadsto \left|\frac{x + 4}{y} - \frac{z}{\color{blue}{\frac{y}{x}}}\right| \]
        14. lift-/.f64N/A

          \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
        15. fabs-subN/A

          \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
        16. lower-fabs.f64N/A

          \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
        17. lift-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
        18. lift-/.f64N/A

          \[\leadsto \left|\frac{z}{\color{blue}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
        19. associate-/r/N/A

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

          \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}} - \frac{x + 4}{y}\right| \]
        21. lift-*.f64N/A

          \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
        22. lift-+.f64N/A

          \[\leadsto \left|\frac{z \cdot x}{y} - \frac{\color{blue}{x + 4}}{y}\right| \]
        23. lift-/.f64N/A

          \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{x + 4}{y}}\right| \]
      5. Applied rewrites95.8%

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

        \[\leadsto \left|\frac{\color{blue}{-1 \cdot \left(4 + x\right)}}{y}\right| \]
      7. Step-by-step derivation
        1. lower-*.f64N/A

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

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

        \[\leadsto \left|\frac{\color{blue}{-1 \cdot \left(4 + x\right)}}{y}\right| \]
      9. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(4 + x\right)}}{y}\right| \]
        2. lift-+.f64N/A

          \[\leadsto \left|\frac{-1 \cdot \left(4 + \color{blue}{x}\right)}{y}\right| \]
        3. distribute-lft-inN/A

          \[\leadsto \left|\frac{-1 \cdot 4 + \color{blue}{-1 \cdot x}}{y}\right| \]
        4. metadata-evalN/A

          \[\leadsto \left|\frac{-4 + \color{blue}{-1} \cdot x}{y}\right| \]
        5. mul-1-negN/A

          \[\leadsto \left|\frac{-4 + \left(\mathsf{neg}\left(x\right)\right)}{y}\right| \]
        6. sub-flipN/A

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

          \[\leadsto \left|\frac{-4 - \color{blue}{x}}{y}\right| \]
      10. Applied rewrites69.7%

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

      if 1.3700000000000001e216 < z

      1. Initial program 91.8%

        \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
      2. Step-by-step derivation
        1. lift-fabs.f64N/A

          \[\leadsto \color{blue}{\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|} \]
        2. rem-sqrt-square-revN/A

          \[\leadsto \color{blue}{\sqrt{\left(\frac{x + 4}{y} - \frac{x}{y} \cdot z\right) \cdot \left(\frac{x + 4}{y} - \frac{x}{y} \cdot z\right)}} \]
        3. sqrt-prodN/A

          \[\leadsto \color{blue}{\sqrt{\frac{x + 4}{y} - \frac{x}{y} \cdot z} \cdot \sqrt{\frac{x + 4}{y} - \frac{x}{y} \cdot z}} \]
        4. rem-square-sqrt65.3

          \[\leadsto \color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z} \]
        5. lift--.f64N/A

          \[\leadsto \color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z} \]
        6. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z \]
        7. lift-*.f64N/A

          \[\leadsto \frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z} \]
        8. lift-/.f64N/A

          \[\leadsto \frac{x + 4}{y} - \color{blue}{\frac{x}{y}} \cdot z \]
        9. associate-*l/N/A

          \[\leadsto \frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}} \]
        10. sub-divN/A

          \[\leadsto \color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}} \]
        11. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}} \]
        12. lower--.f64N/A

          \[\leadsto \frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y} \]
        13. lift-+.f64N/A

          \[\leadsto \frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y} \]
        14. add-flipN/A

          \[\leadsto \frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y} \]
        15. lower--.f64N/A

          \[\leadsto \frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y} \]
        16. metadata-evalN/A

          \[\leadsto \frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y} \]
        17. *-commutativeN/A

          \[\leadsto \frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y} \]
        18. lower-*.f6467.1

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(x \cdot z\right)}}{y} \]
      5. Step-by-step derivation
        1. lower-*.f64N/A

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(x \cdot z\right)}}{y} \]
      7. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \frac{-1 \cdot \color{blue}{\left(x \cdot z\right)}}{y} \]
        2. mul-1-negN/A

          \[\leadsto \frac{\mathsf{neg}\left(x \cdot z\right)}{y} \]
        3. lift-*.f64N/A

          \[\leadsto \frac{\mathsf{neg}\left(x \cdot z\right)}{y} \]
        4. *-commutativeN/A

          \[\leadsto \frac{\mathsf{neg}\left(z \cdot x\right)}{y} \]
        5. distribute-lft-neg-outN/A

          \[\leadsto \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot \color{blue}{x}}{y} \]
        6. lower-*.f64N/A

          \[\leadsto \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot \color{blue}{x}}{y} \]
        7. lower-neg.f6420.5

          \[\leadsto \frac{\left(-z\right) \cdot x}{y} \]
      8. Applied rewrites20.5%

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

    Alternative 8: 69.7% accurate, 2.1× speedup?

    \[\begin{array}{l} y_m = \left|y\right| \\ \left|\frac{-4 - x}{y\_m}\right| \end{array} \]
    y_m = (fabs.f64 y)
    (FPCore (x y_m z) :precision binary64 (fabs (/ (- -4.0 x) y_m)))
    y_m = fabs(y);
    double code(double x, double y_m, double z) {
    	return fabs(((-4.0 - x) / y_m));
    }
    
    y_m =     private
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y_m, z)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y_m
        real(8), intent (in) :: z
        code = abs((((-4.0d0) - x) / 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) / y_m));
    }
    
    y_m = math.fabs(y)
    def code(x, y_m, z):
    	return math.fabs(((-4.0 - x) / y_m))
    
    y_m = abs(y)
    function code(x, y_m, z)
    	return abs(Float64(Float64(-4.0 - x) / y_m))
    end
    
    y_m = abs(y);
    function tmp = code(x, y_m, z)
    	tmp = abs(((-4.0 - x) / y_m));
    end
    
    y_m = N[Abs[y], $MachinePrecision]
    code[x_, y$95$m_, z_] := N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]
    
    \begin{array}{l}
    y_m = \left|y\right|
    
    \\
    \left|\frac{-4 - x}{y\_m}\right|
    \end{array}
    
    Derivation
    1. Initial program 91.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z}\right| \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z\right| \]
      3. lift-*.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z}\right| \]
      4. lift-/.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      6. sub-divN/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      7. lower-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
      8. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y}\right| \]
      10. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      11. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y}\right| \]
      12. metadata-evalN/A

        \[\leadsto \left|\frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y}\right| \]
      13. *-commutativeN/A

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
      14. lower-*.f6495.8

        \[\leadsto \left|\frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y}\right| \]
    3. Applied rewrites95.8%

      \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
    4. Step-by-step derivation
      1. lift-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{\left(x - -4\right) - z \cdot x}{y}\right|} \]
      2. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{\left(x - -4\right) - z \cdot x}{y}}\right| \]
      3. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\left(x - -4\right) - z \cdot x}}{y}\right| \]
      4. div-subN/A

        \[\leadsto \left|\color{blue}{\frac{x - -4}{y} - \frac{z \cdot x}{y}}\right| \]
      5. lift--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x - -4}}{y} - \frac{z \cdot x}{y}\right| \]
      6. metadata-evalN/A

        \[\leadsto \left|\frac{x - \color{blue}{\left(\mathsf{neg}\left(4\right)\right)}}{y} - \frac{z \cdot x}{y}\right| \]
      7. add-flipN/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      8. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{x + 4}{y}} - \frac{z \cdot x}{y}\right| \]
      9. lift-+.f64N/A

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y} - \frac{z \cdot x}{y}\right| \]
      10. lift-*.f64N/A

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

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{y} \cdot x}\right| \]
      12. associate-/r/N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      13. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \frac{z}{\color{blue}{\frac{y}{x}}}\right| \]
      14. lift-/.f64N/A

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
      15. fabs-subN/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      16. lower-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{z}{\frac{y}{x}} - \frac{x + 4}{y}\right|} \]
      17. lift-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      18. lift-/.f64N/A

        \[\leadsto \left|\frac{z}{\color{blue}{\frac{y}{x}}} - \frac{x + 4}{y}\right| \]
      19. associate-/r/N/A

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

        \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}} - \frac{x + 4}{y}\right| \]
      21. lift-*.f64N/A

        \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
      22. lift-+.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \frac{\color{blue}{x + 4}}{y}\right| \]
      23. lift-/.f64N/A

        \[\leadsto \left|\frac{z \cdot x}{y} - \color{blue}{\frac{x + 4}{y}}\right| \]
    5. Applied rewrites95.8%

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

      \[\leadsto \left|\frac{\color{blue}{-1 \cdot \left(4 + x\right)}}{y}\right| \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

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

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

      \[\leadsto \left|\frac{\color{blue}{-1 \cdot \left(4 + x\right)}}{y}\right| \]
    9. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left|\frac{-1 \cdot \color{blue}{\left(4 + x\right)}}{y}\right| \]
      2. lift-+.f64N/A

        \[\leadsto \left|\frac{-1 \cdot \left(4 + \color{blue}{x}\right)}{y}\right| \]
      3. distribute-lft-inN/A

        \[\leadsto \left|\frac{-1 \cdot 4 + \color{blue}{-1 \cdot x}}{y}\right| \]
      4. metadata-evalN/A

        \[\leadsto \left|\frac{-4 + \color{blue}{-1} \cdot x}{y}\right| \]
      5. mul-1-negN/A

        \[\leadsto \left|\frac{-4 + \left(\mathsf{neg}\left(x\right)\right)}{y}\right| \]
      6. sub-flipN/A

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

        \[\leadsto \left|\frac{-4 - \color{blue}{x}}{y}\right| \]
    10. Applied rewrites69.7%

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

    Alternative 9: 40.0% accurate, 3.9× speedup?

    \[\begin{array}{l} y_m = \left|y\right| \\ \frac{4}{y\_m} \end{array} \]
    y_m = (fabs.f64 y)
    (FPCore (x y_m z) :precision binary64 (/ 4.0 y_m))
    y_m = fabs(y);
    double code(double x, double y_m, double z) {
    	return 4.0 / y_m;
    }
    
    y_m =     private
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y_m, z)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y_m
        real(8), intent (in) :: z
        code = 4.0d0 / y_m
    end function
    
    y_m = Math.abs(y);
    public static double code(double x, double y_m, double z) {
    	return 4.0 / y_m;
    }
    
    y_m = math.fabs(y)
    def code(x, y_m, z):
    	return 4.0 / y_m
    
    y_m = abs(y)
    function code(x, y_m, z)
    	return Float64(4.0 / y_m)
    end
    
    y_m = abs(y);
    function tmp = code(x, y_m, z)
    	tmp = 4.0 / y_m;
    end
    
    y_m = N[Abs[y], $MachinePrecision]
    code[x_, y$95$m_, z_] := N[(4.0 / y$95$m), $MachinePrecision]
    
    \begin{array}{l}
    y_m = \left|y\right|
    
    \\
    \frac{4}{y\_m}
    \end{array}
    
    Derivation
    1. Initial program 91.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. lift-fabs.f64N/A

        \[\leadsto \color{blue}{\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|} \]
      2. rem-sqrt-square-revN/A

        \[\leadsto \color{blue}{\sqrt{\left(\frac{x + 4}{y} - \frac{x}{y} \cdot z\right) \cdot \left(\frac{x + 4}{y} - \frac{x}{y} \cdot z\right)}} \]
      3. sqrt-prodN/A

        \[\leadsto \color{blue}{\sqrt{\frac{x + 4}{y} - \frac{x}{y} \cdot z} \cdot \sqrt{\frac{x + 4}{y} - \frac{x}{y} \cdot z}} \]
      4. rem-square-sqrt65.3

        \[\leadsto \color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z} \]
      5. lift--.f64N/A

        \[\leadsto \color{blue}{\frac{x + 4}{y} - \frac{x}{y} \cdot z} \]
      6. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{x + 4}{y}} - \frac{x}{y} \cdot z \]
      7. lift-*.f64N/A

        \[\leadsto \frac{x + 4}{y} - \color{blue}{\frac{x}{y} \cdot z} \]
      8. lift-/.f64N/A

        \[\leadsto \frac{x + 4}{y} - \color{blue}{\frac{x}{y}} \cdot z \]
      9. associate-*l/N/A

        \[\leadsto \frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}} \]
      10. sub-divN/A

        \[\leadsto \color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}} \]
      11. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}} \]
      12. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(x + 4\right) - x \cdot z}}{y} \]
      13. lift-+.f64N/A

        \[\leadsto \frac{\color{blue}{\left(x + 4\right)} - x \cdot z}{y} \]
      14. add-flipN/A

        \[\leadsto \frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y} \]
      15. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(x - \left(\mathsf{neg}\left(4\right)\right)\right)} - x \cdot z}{y} \]
      16. metadata-evalN/A

        \[\leadsto \frac{\left(x - \color{blue}{-4}\right) - x \cdot z}{y} \]
      17. *-commutativeN/A

        \[\leadsto \frac{\left(x - -4\right) - \color{blue}{z \cdot x}}{y} \]
      18. lower-*.f6467.1

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

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

      \[\leadsto \frac{\color{blue}{4}}{y} \]
    5. Step-by-step derivation
      1. Applied rewrites40.0%

        \[\leadsto \frac{\color{blue}{4}}{y} \]
      2. Add Preprocessing

      Reproduce

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