Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A

Percentage Accurate: 88.3% → 99.8%
Time: 3.9s
Alternatives: 10
Speedup: 0.3×

Specification

?
\[\begin{array}{l} \\ \frac{x + y}{1 - \frac{y}{z}} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
double code(double x, double y, double z) {
	return (x + y) / (1.0 - (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 = (x + y) / (1.0d0 - (y / z))
end function
public static double code(double x, double y, double z) {
	return (x + y) / (1.0 - (y / z));
}
def code(x, y, z):
	return (x + y) / (1.0 - (y / z))
function code(x, y, z)
	return Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)))
end
function tmp = code(x, y, z)
	tmp = (x + y) / (1.0 - (y / z));
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x + y}{1 - \frac{y}{z}}
\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 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: 88.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x + y}{1 - \frac{y}{z}} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
double code(double x, double y, double z) {
	return (x + y) / (1.0 - (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 = (x + y) / (1.0d0 - (y / z))
end function
public static double code(double x, double y, double z) {
	return (x + y) / (1.0 - (y / z));
}
def code(x, y, z):
	return (x + y) / (1.0 - (y / z))
function code(x, y, z)
	return Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)))
end
function tmp = code(x, y, z)
	tmp = (x + y) / (1.0 - (y / z));
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x + y}{1 - \frac{y}{z}}
\end{array}

Alternative 1: 99.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-284}:\\ \;\;\;\;\frac{x + y}{\frac{z - y}{z}}\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-283}:\\ \;\;\;\;-z \cdot \frac{x + y}{y}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x y) (- 1.0 (/ y z)))))
   (if (<= t_0 -2e-284)
     (/ (+ x y) (/ (- z y) z))
     (if (<= t_0 2e-283) (- (* z (/ (+ x y) y))) t_0))))
double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double tmp;
	if (t_0 <= -2e-284) {
		tmp = (x + y) / ((z - y) / z);
	} else if (t_0 <= 2e-283) {
		tmp = -(z * ((x + y) / y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x + y) / (1.0d0 - (y / z))
    if (t_0 <= (-2d-284)) then
        tmp = (x + y) / ((z - y) / z)
    else if (t_0 <= 2d-283) then
        tmp = -(z * ((x + y) / y))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double tmp;
	if (t_0 <= -2e-284) {
		tmp = (x + y) / ((z - y) / z);
	} else if (t_0 <= 2e-283) {
		tmp = -(z * ((x + y) / y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x + y) / (1.0 - (y / z))
	tmp = 0
	if t_0 <= -2e-284:
		tmp = (x + y) / ((z - y) / z)
	elif t_0 <= 2e-283:
		tmp = -(z * ((x + y) / y))
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)))
	tmp = 0.0
	if (t_0 <= -2e-284)
		tmp = Float64(Float64(x + y) / Float64(Float64(z - y) / z));
	elseif (t_0 <= 2e-283)
		tmp = Float64(-Float64(z * Float64(Float64(x + y) / y)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x + y) / (1.0 - (y / z));
	tmp = 0.0;
	if (t_0 <= -2e-284)
		tmp = (x + y) / ((z - y) / z);
	elseif (t_0 <= 2e-283)
		tmp = -(z * ((x + y) / y));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-284], N[(N[(x + y), $MachinePrecision] / N[(N[(z - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-283], (-N[(z * N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-284}:\\
\;\;\;\;\frac{x + y}{\frac{z - y}{z}}\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-283}:\\
\;\;\;\;-z \cdot \frac{x + y}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z))) < -2.00000000000000007e-284

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]
    3. Applied rewrites88.3%

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]

    if -2.00000000000000007e-284 < (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z))) < 1.99999999999999989e-283

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

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

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

      \[\leadsto -z \cdot \frac{x + y}{y} \]

    if 1.99999999999999989e-283 < (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z)))

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ t_1 := \frac{x + y}{\frac{z - y}{z}}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-284}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-283}:\\ \;\;\;\;-z \cdot \frac{x + y}{y}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x y) (- 1.0 (/ y z)))) (t_1 (/ (+ x y) (/ (- z y) z))))
   (if (<= t_0 -2e-284) t_1 (if (<= t_0 2e-283) (- (* z (/ (+ x y) y))) t_1))))
double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double t_1 = (x + y) / ((z - y) / z);
	double tmp;
	if (t_0 <= -2e-284) {
		tmp = t_1;
	} else if (t_0 <= 2e-283) {
		tmp = -(z * ((x + y) / y));
	} else {
		tmp = t_1;
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (x + y) / (1.0d0 - (y / z))
    t_1 = (x + y) / ((z - y) / z)
    if (t_0 <= (-2d-284)) then
        tmp = t_1
    else if (t_0 <= 2d-283) then
        tmp = -(z * ((x + y) / y))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double t_1 = (x + y) / ((z - y) / z);
	double tmp;
	if (t_0 <= -2e-284) {
		tmp = t_1;
	} else if (t_0 <= 2e-283) {
		tmp = -(z * ((x + y) / y));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x + y) / (1.0 - (y / z))
	t_1 = (x + y) / ((z - y) / z)
	tmp = 0
	if t_0 <= -2e-284:
		tmp = t_1
	elif t_0 <= 2e-283:
		tmp = -(z * ((x + y) / y))
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)))
	t_1 = Float64(Float64(x + y) / Float64(Float64(z - y) / z))
	tmp = 0.0
	if (t_0 <= -2e-284)
		tmp = t_1;
	elseif (t_0 <= 2e-283)
		tmp = Float64(-Float64(z * Float64(Float64(x + y) / y)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x + y) / (1.0 - (y / z));
	t_1 = (x + y) / ((z - y) / z);
	tmp = 0.0;
	if (t_0 <= -2e-284)
		tmp = t_1;
	elseif (t_0 <= 2e-283)
		tmp = -(z * ((x + y) / y));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] / N[(N[(z - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-284], t$95$1, If[LessEqual[t$95$0, 2e-283], (-N[(z * N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
t_1 := \frac{x + y}{\frac{z - y}{z}}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-284}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-283}:\\
\;\;\;\;-z \cdot \frac{x + y}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z))) < -2.00000000000000007e-284 or 1.99999999999999989e-283 < (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z)))

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]
    3. Applied rewrites88.3%

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]

    if -2.00000000000000007e-284 < (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z))) < 1.99999999999999989e-283

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

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

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

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

Alternative 3: 74.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{\frac{z - y}{z}}\\ t_1 := -z \cdot \frac{x + y}{y}\\ \mathbf{if}\;y \leq -0.28:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -2.3 \cdot 10^{-48}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-32}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{+86}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ y (/ (- z y) z))) (t_1 (- (* z (/ (+ x y) y)))))
   (if (<= y -0.28)
     t_1
     (if (<= y -2.3e-48)
       t_0
       (if (<= y 3.6e-32)
         (/ x (- 1.0 (/ y z)))
         (if (<= y 1.7e+86) t_0 t_1))))))
double code(double x, double y, double z) {
	double t_0 = y / ((z - y) / z);
	double t_1 = -(z * ((x + y) / y));
	double tmp;
	if (y <= -0.28) {
		tmp = t_1;
	} else if (y <= -2.3e-48) {
		tmp = t_0;
	} else if (y <= 3.6e-32) {
		tmp = x / (1.0 - (y / z));
	} else if (y <= 1.7e+86) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = y / ((z - y) / z)
    t_1 = -(z * ((x + y) / y))
    if (y <= (-0.28d0)) then
        tmp = t_1
    else if (y <= (-2.3d-48)) then
        tmp = t_0
    else if (y <= 3.6d-32) then
        tmp = x / (1.0d0 - (y / z))
    else if (y <= 1.7d+86) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y / ((z - y) / z);
	double t_1 = -(z * ((x + y) / y));
	double tmp;
	if (y <= -0.28) {
		tmp = t_1;
	} else if (y <= -2.3e-48) {
		tmp = t_0;
	} else if (y <= 3.6e-32) {
		tmp = x / (1.0 - (y / z));
	} else if (y <= 1.7e+86) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y / ((z - y) / z)
	t_1 = -(z * ((x + y) / y))
	tmp = 0
	if y <= -0.28:
		tmp = t_1
	elif y <= -2.3e-48:
		tmp = t_0
	elif y <= 3.6e-32:
		tmp = x / (1.0 - (y / z))
	elif y <= 1.7e+86:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(y / Float64(Float64(z - y) / z))
	t_1 = Float64(-Float64(z * Float64(Float64(x + y) / y)))
	tmp = 0.0
	if (y <= -0.28)
		tmp = t_1;
	elseif (y <= -2.3e-48)
		tmp = t_0;
	elseif (y <= 3.6e-32)
		tmp = Float64(x / Float64(1.0 - Float64(y / z)));
	elseif (y <= 1.7e+86)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y / ((z - y) / z);
	t_1 = -(z * ((x + y) / y));
	tmp = 0.0;
	if (y <= -0.28)
		tmp = t_1;
	elseif (y <= -2.3e-48)
		tmp = t_0;
	elseif (y <= 3.6e-32)
		tmp = x / (1.0 - (y / z));
	elseif (y <= 1.7e+86)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(N[(z - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[(z * N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[y, -0.28], t$95$1, If[LessEqual[y, -2.3e-48], t$95$0, If[LessEqual[y, 3.6e-32], N[(x / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.7e+86], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y}{\frac{z - y}{z}}\\
t_1 := -z \cdot \frac{x + y}{y}\\
\mathbf{if}\;y \leq -0.28:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -2.3 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 3.6 \cdot 10^{-32}:\\
\;\;\;\;\frac{x}{1 - \frac{y}{z}}\\

\mathbf{elif}\;y \leq 1.7 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -0.28000000000000003 or 1.6999999999999999e86 < y

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

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

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

      \[\leadsto -z \cdot \frac{x + y}{y} \]

    if -0.28000000000000003 < y < -2.3000000000000001e-48 or 3.59999999999999993e-32 < y < 1.6999999999999999e86

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]
    3. Applied rewrites88.3%

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{y}}{\frac{z - y}{z}} \]
    5. Applied rewrites41.8%

      \[\leadsto \frac{\color{blue}{y}}{\frac{z - y}{z}} \]

    if -2.3000000000000001e-48 < y < 3.59999999999999993e-32

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
    3. Applied rewrites49.0%

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 68.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{\frac{z - y}{z}}\\ t_1 := \frac{x}{1 - \frac{y}{z}}\\ \mathbf{if}\;y \leq -5.2 \cdot 10^{+91}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -0.28:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -2.3 \cdot 10^{-48}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-32}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+127}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ y (/ (- z y) z))) (t_1 (/ x (- 1.0 (/ y z)))))
   (if (<= y -5.2e+91)
     (- z)
     (if (<= y -0.28)
       t_1
       (if (<= y -2.3e-48)
         t_0
         (if (<= y 3.6e-32) t_1 (if (<= y 9.5e+127) t_0 (- z))))))))
double code(double x, double y, double z) {
	double t_0 = y / ((z - y) / z);
	double t_1 = x / (1.0 - (y / z));
	double tmp;
	if (y <= -5.2e+91) {
		tmp = -z;
	} else if (y <= -0.28) {
		tmp = t_1;
	} else if (y <= -2.3e-48) {
		tmp = t_0;
	} else if (y <= 3.6e-32) {
		tmp = t_1;
	} else if (y <= 9.5e+127) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = y / ((z - y) / z)
    t_1 = x / (1.0d0 - (y / z))
    if (y <= (-5.2d+91)) then
        tmp = -z
    else if (y <= (-0.28d0)) then
        tmp = t_1
    else if (y <= (-2.3d-48)) then
        tmp = t_0
    else if (y <= 3.6d-32) then
        tmp = t_1
    else if (y <= 9.5d+127) then
        tmp = t_0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y / ((z - y) / z);
	double t_1 = x / (1.0 - (y / z));
	double tmp;
	if (y <= -5.2e+91) {
		tmp = -z;
	} else if (y <= -0.28) {
		tmp = t_1;
	} else if (y <= -2.3e-48) {
		tmp = t_0;
	} else if (y <= 3.6e-32) {
		tmp = t_1;
	} else if (y <= 9.5e+127) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y / ((z - y) / z)
	t_1 = x / (1.0 - (y / z))
	tmp = 0
	if y <= -5.2e+91:
		tmp = -z
	elif y <= -0.28:
		tmp = t_1
	elif y <= -2.3e-48:
		tmp = t_0
	elif y <= 3.6e-32:
		tmp = t_1
	elif y <= 9.5e+127:
		tmp = t_0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	t_0 = Float64(y / Float64(Float64(z - y) / z))
	t_1 = Float64(x / Float64(1.0 - Float64(y / z)))
	tmp = 0.0
	if (y <= -5.2e+91)
		tmp = Float64(-z);
	elseif (y <= -0.28)
		tmp = t_1;
	elseif (y <= -2.3e-48)
		tmp = t_0;
	elseif (y <= 3.6e-32)
		tmp = t_1;
	elseif (y <= 9.5e+127)
		tmp = t_0;
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y / ((z - y) / z);
	t_1 = x / (1.0 - (y / z));
	tmp = 0.0;
	if (y <= -5.2e+91)
		tmp = -z;
	elseif (y <= -0.28)
		tmp = t_1;
	elseif (y <= -2.3e-48)
		tmp = t_0;
	elseif (y <= 3.6e-32)
		tmp = t_1;
	elseif (y <= 9.5e+127)
		tmp = t_0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(N[(z - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.2e+91], (-z), If[LessEqual[y, -0.28], t$95$1, If[LessEqual[y, -2.3e-48], t$95$0, If[LessEqual[y, 3.6e-32], t$95$1, If[LessEqual[y, 9.5e+127], t$95$0, (-z)]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y}{\frac{z - y}{z}}\\
t_1 := \frac{x}{1 - \frac{y}{z}}\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+91}:\\
\;\;\;\;-z\\

\mathbf{elif}\;y \leq -0.28:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -2.3 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 3.6 \cdot 10^{-32}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 9.5 \cdot 10^{+127}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.2000000000000001e91 or 9.49999999999999975e127 < y

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Applied rewrites35.0%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Applied rewrites35.0%

      \[\leadsto -z \]

    if -5.2000000000000001e91 < y < -0.28000000000000003 or -2.3000000000000001e-48 < y < 3.59999999999999993e-32

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
    3. Applied rewrites49.0%

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

    if -0.28000000000000003 < y < -2.3000000000000001e-48 or 3.59999999999999993e-32 < y < 9.49999999999999975e127

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]
    3. Applied rewrites88.3%

      \[\leadsto \frac{x + y}{\color{blue}{\frac{z - y}{z}}} \]
    4. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{y}}{\frac{z - y}{z}} \]
    5. Applied rewrites41.8%

      \[\leadsto \frac{\color{blue}{y}}{\frac{z - y}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 68.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5.2 \cdot 10^{+91}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -0.28:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\ \;\;\;\;\frac{x + y}{1}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -5.2e+91)
   (- z)
   (if (<= y -0.28)
     (/ x (- 1.0 (/ y z)))
     (if (<= y 1.65e+86) (/ (+ x y) 1.0) (- z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5.2e+91) {
		tmp = -z;
	} else if (y <= -0.28) {
		tmp = x / (1.0 - (y / z));
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
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
    real(8) :: tmp
    if (y <= (-5.2d+91)) then
        tmp = -z
    else if (y <= (-0.28d0)) then
        tmp = x / (1.0d0 - (y / z))
    else if (y <= 1.65d+86) then
        tmp = (x + y) / 1.0d0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -5.2e+91) {
		tmp = -z;
	} else if (y <= -0.28) {
		tmp = x / (1.0 - (y / z));
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -5.2e+91:
		tmp = -z
	elif y <= -0.28:
		tmp = x / (1.0 - (y / z))
	elif y <= 1.65e+86:
		tmp = (x + y) / 1.0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -5.2e+91)
		tmp = Float64(-z);
	elseif (y <= -0.28)
		tmp = Float64(x / Float64(1.0 - Float64(y / z)));
	elseif (y <= 1.65e+86)
		tmp = Float64(Float64(x + y) / 1.0);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -5.2e+91)
		tmp = -z;
	elseif (y <= -0.28)
		tmp = x / (1.0 - (y / z));
	elseif (y <= 1.65e+86)
		tmp = (x + y) / 1.0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -5.2e+91], (-z), If[LessEqual[y, -0.28], N[(x / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.65e+86], N[(N[(x + y), $MachinePrecision] / 1.0), $MachinePrecision], (-z)]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+91}:\\
\;\;\;\;-z\\

\mathbf{elif}\;y \leq -0.28:\\
\;\;\;\;\frac{x}{1 - \frac{y}{z}}\\

\mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\
\;\;\;\;\frac{x + y}{1}\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.2000000000000001e91 or 1.65e86 < y

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Applied rewrites35.0%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Applied rewrites35.0%

      \[\leadsto -z \]

    if -5.2000000000000001e91 < y < -0.28000000000000003

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
    3. Applied rewrites49.0%

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

    if -0.28000000000000003 < y < 1.65e86

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around 0

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
    3. Applied rewrites50.8%

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 68.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.6 \cdot 10^{+91}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.3:\\ \;\;\;\;-1 \cdot \frac{x \cdot z}{y}\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\ \;\;\;\;\frac{x + y}{1}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -3.6e+91)
   (- z)
   (if (<= y -1.3)
     (* -1.0 (/ (* x z) y))
     (if (<= y 1.65e+86) (/ (+ x y) 1.0) (- z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -3.6e+91) {
		tmp = -z;
	} else if (y <= -1.3) {
		tmp = -1.0 * ((x * z) / y);
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
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
    real(8) :: tmp
    if (y <= (-3.6d+91)) then
        tmp = -z
    else if (y <= (-1.3d0)) then
        tmp = (-1.0d0) * ((x * z) / y)
    else if (y <= 1.65d+86) then
        tmp = (x + y) / 1.0d0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -3.6e+91) {
		tmp = -z;
	} else if (y <= -1.3) {
		tmp = -1.0 * ((x * z) / y);
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -3.6e+91:
		tmp = -z
	elif y <= -1.3:
		tmp = -1.0 * ((x * z) / y)
	elif y <= 1.65e+86:
		tmp = (x + y) / 1.0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -3.6e+91)
		tmp = Float64(-z);
	elseif (y <= -1.3)
		tmp = Float64(-1.0 * Float64(Float64(x * z) / y));
	elseif (y <= 1.65e+86)
		tmp = Float64(Float64(x + y) / 1.0);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -3.6e+91)
		tmp = -z;
	elseif (y <= -1.3)
		tmp = -1.0 * ((x * z) / y);
	elseif (y <= 1.65e+86)
		tmp = (x + y) / 1.0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -3.6e+91], (-z), If[LessEqual[y, -1.3], N[(-1.0 * N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.65e+86], N[(N[(x + y), $MachinePrecision] / 1.0), $MachinePrecision], (-z)]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{+91}:\\
\;\;\;\;-z\\

\mathbf{elif}\;y \leq -1.3:\\
\;\;\;\;-1 \cdot \frac{x \cdot z}{y}\\

\mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\
\;\;\;\;\frac{x + y}{1}\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.6e91 or 1.65e86 < y

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Applied rewrites35.0%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Applied rewrites35.0%

      \[\leadsto -z \]

    if -3.6e91 < y < -1.30000000000000004

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0

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

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

      \[\leadsto -1 \cdot \frac{x \cdot z}{y} \]
    5. Applied rewrites16.9%

      \[\leadsto -1 \cdot \frac{x \cdot z}{y} \]

    if -1.30000000000000004 < y < 1.65e86

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around 0

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
    3. Applied rewrites50.8%

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 66.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+90}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.3:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\ \;\;\;\;\frac{x + y}{1}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -3.5e+90)
   (- z)
   (if (<= y -1.3)
     (* x (- (/ z y)))
     (if (<= y 1.65e+86) (/ (+ x y) 1.0) (- z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -3.5e+90) {
		tmp = -z;
	} else if (y <= -1.3) {
		tmp = x * -(z / y);
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
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
    real(8) :: tmp
    if (y <= (-3.5d+90)) then
        tmp = -z
    else if (y <= (-1.3d0)) then
        tmp = x * -(z / y)
    else if (y <= 1.65d+86) then
        tmp = (x + y) / 1.0d0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -3.5e+90) {
		tmp = -z;
	} else if (y <= -1.3) {
		tmp = x * -(z / y);
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -3.5e+90:
		tmp = -z
	elif y <= -1.3:
		tmp = x * -(z / y)
	elif y <= 1.65e+86:
		tmp = (x + y) / 1.0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -3.5e+90)
		tmp = Float64(-z);
	elseif (y <= -1.3)
		tmp = Float64(x * Float64(-Float64(z / y)));
	elseif (y <= 1.65e+86)
		tmp = Float64(Float64(x + y) / 1.0);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -3.5e+90)
		tmp = -z;
	elseif (y <= -1.3)
		tmp = x * -(z / y);
	elseif (y <= 1.65e+86)
		tmp = (x + y) / 1.0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -3.5e+90], (-z), If[LessEqual[y, -1.3], N[(x * (-N[(z / y), $MachinePrecision])), $MachinePrecision], If[LessEqual[y, 1.65e+86], N[(N[(x + y), $MachinePrecision] / 1.0), $MachinePrecision], (-z)]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+90}:\\
\;\;\;\;-z\\

\mathbf{elif}\;y \leq -1.3:\\
\;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\

\mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\
\;\;\;\;\frac{x + y}{1}\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.4999999999999998e90 or 1.65e86 < y

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Applied rewrites35.0%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Applied rewrites35.0%

      \[\leadsto -z \]

    if -3.4999999999999998e90 < y < -1.30000000000000004

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
    3. Applied rewrites49.0%

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
    4. Applied rewrites49.0%

      \[\leadsto x \cdot \color{blue}{\frac{1}{1 - \frac{y}{z}}} \]
    5. Taylor expanded in y around inf

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

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

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

    if -1.30000000000000004 < y < 1.65e86

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around 0

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
    3. Applied rewrites50.8%

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 66.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+92}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\ \;\;\;\;\frac{x + y}{1}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -7.8e+92) (- z) (if (<= y 1.65e+86) (/ (+ x y) 1.0) (- z))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -7.8e+92) {
		tmp = -z;
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
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
    real(8) :: tmp
    if (y <= (-7.8d+92)) then
        tmp = -z
    else if (y <= 1.65d+86) then
        tmp = (x + y) / 1.0d0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -7.8e+92) {
		tmp = -z;
	} else if (y <= 1.65e+86) {
		tmp = (x + y) / 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -7.8e+92:
		tmp = -z
	elif y <= 1.65e+86:
		tmp = (x + y) / 1.0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -7.8e+92)
		tmp = Float64(-z);
	elseif (y <= 1.65e+86)
		tmp = Float64(Float64(x + y) / 1.0);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -7.8e+92)
		tmp = -z;
	elseif (y <= 1.65e+86)
		tmp = (x + y) / 1.0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -7.8e+92], (-z), If[LessEqual[y, 1.65e+86], N[(N[(x + y), $MachinePrecision] / 1.0), $MachinePrecision], (-z)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+92}:\\
\;\;\;\;-z\\

\mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\
\;\;\;\;\frac{x + y}{1}\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.80000000000000022e92 or 1.65e86 < y

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Applied rewrites35.0%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Applied rewrites35.0%

      \[\leadsto -z \]

    if -7.80000000000000022e92 < y < 1.65e86

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around 0

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
    3. Applied rewrites50.8%

      \[\leadsto \frac{x + y}{\color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 57.6% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+90}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-32}:\\ \;\;\;\;x \cdot 1\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -3.5e+90) (- z) (if (<= y 4e-32) (* x 1.0) (- z))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -3.5e+90) {
		tmp = -z;
	} else if (y <= 4e-32) {
		tmp = x * 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
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
    real(8) :: tmp
    if (y <= (-3.5d+90)) then
        tmp = -z
    else if (y <= 4d-32) then
        tmp = x * 1.0d0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -3.5e+90) {
		tmp = -z;
	} else if (y <= 4e-32) {
		tmp = x * 1.0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -3.5e+90:
		tmp = -z
	elif y <= 4e-32:
		tmp = x * 1.0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -3.5e+90)
		tmp = Float64(-z);
	elseif (y <= 4e-32)
		tmp = Float64(x * 1.0);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -3.5e+90)
		tmp = -z;
	elseif (y <= 4e-32)
		tmp = x * 1.0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -3.5e+90], (-z), If[LessEqual[y, 4e-32], N[(x * 1.0), $MachinePrecision], (-z)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+90}:\\
\;\;\;\;-z\\

\mathbf{elif}\;y \leq 4 \cdot 10^{-32}:\\
\;\;\;\;x \cdot 1\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.4999999999999998e90 or 4.00000000000000022e-32 < y

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Applied rewrites35.0%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Applied rewrites35.0%

      \[\leadsto -z \]

    if -3.4999999999999998e90 < y < 4.00000000000000022e-32

    1. Initial program 88.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
    3. Applied rewrites49.0%

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}}} \]
    4. Applied rewrites49.0%

      \[\leadsto x \cdot \color{blue}{\frac{1}{1 - \frac{y}{z}}} \]
    5. Taylor expanded in y around 0

      \[\leadsto x \cdot 1 \]
    6. Applied rewrites35.1%

      \[\leadsto x \cdot 1 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 35.0% accurate, 6.7× speedup?

\[\begin{array}{l} \\ -z \end{array} \]
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
	return -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 = -z
end function
public static double code(double x, double y, double z) {
	return -z;
}
def code(x, y, z):
	return -z
function code(x, y, z)
	return Float64(-z)
end
function tmp = code(x, y, z)
	tmp = -z;
end
code[x_, y_, z_] := (-z)
\begin{array}{l}

\\
-z
\end{array}
Derivation
  1. Initial program 88.3%

    \[\frac{x + y}{1 - \frac{y}{z}} \]
  2. Taylor expanded in y around inf

    \[\leadsto \color{blue}{-1 \cdot z} \]
  3. Applied rewrites35.0%

    \[\leadsto \color{blue}{-1 \cdot z} \]
  4. Applied rewrites35.0%

    \[\leadsto -z \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2025161 
(FPCore (x y z)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"
  :precision binary64
  (/ (+ x y) (- 1.0 (/ y z))))