expq3 (problem 3.4.2)

Percentage Accurate: 0.0% → 99.9%
Time: 15.9s
Alternatives: 7
Speedup: 29.1×

Specification

?
\[\left(\left|a\right| \leq 710 \land \left|b\right| \leq 710\right) \land \left(10^{-27} \cdot \mathsf{min}\left(\left|a\right|, \left|b\right|\right) \leq \varepsilon \land \varepsilon \leq \mathsf{min}\left(\left|a\right|, \left|b\right|\right)\right)\]
\[\begin{array}{l} \\ \frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \end{array} \]
(FPCore (a b eps)
 :precision binary64
 (/
  (* eps (- (exp (* (+ a b) eps)) 1.0))
  (* (- (exp (* a eps)) 1.0) (- (exp (* b eps)) 1.0))))
double code(double a, double b, double eps) {
	return (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0));
}
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(a, b, eps)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: eps
    code = (eps * (exp(((a + b) * eps)) - 1.0d0)) / ((exp((a * eps)) - 1.0d0) * (exp((b * eps)) - 1.0d0))
end function
public static double code(double a, double b, double eps) {
	return (eps * (Math.exp(((a + b) * eps)) - 1.0)) / ((Math.exp((a * eps)) - 1.0) * (Math.exp((b * eps)) - 1.0));
}
def code(a, b, eps):
	return (eps * (math.exp(((a + b) * eps)) - 1.0)) / ((math.exp((a * eps)) - 1.0) * (math.exp((b * eps)) - 1.0))
function code(a, b, eps)
	return Float64(Float64(eps * Float64(exp(Float64(Float64(a + b) * eps)) - 1.0)) / Float64(Float64(exp(Float64(a * eps)) - 1.0) * Float64(exp(Float64(b * eps)) - 1.0)))
end
function tmp = code(a, b, eps)
	tmp = (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0));
end
code[a_, b_, eps_] := N[(N[(eps * N[(N[Exp[N[(N[(a + b), $MachinePrecision] * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Exp[N[(a * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] * N[(N[Exp[N[(b * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\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 7 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: 0.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \end{array} \]
(FPCore (a b eps)
 :precision binary64
 (/
  (* eps (- (exp (* (+ a b) eps)) 1.0))
  (* (- (exp (* a eps)) 1.0) (- (exp (* b eps)) 1.0))))
double code(double a, double b, double eps) {
	return (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0));
}
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(a, b, eps)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: eps
    code = (eps * (exp(((a + b) * eps)) - 1.0d0)) / ((exp((a * eps)) - 1.0d0) * (exp((b * eps)) - 1.0d0))
end function
public static double code(double a, double b, double eps) {
	return (eps * (Math.exp(((a + b) * eps)) - 1.0)) / ((Math.exp((a * eps)) - 1.0) * (Math.exp((b * eps)) - 1.0));
}
def code(a, b, eps):
	return (eps * (math.exp(((a + b) * eps)) - 1.0)) / ((math.exp((a * eps)) - 1.0) * (math.exp((b * eps)) - 1.0))
function code(a, b, eps)
	return Float64(Float64(eps * Float64(exp(Float64(Float64(a + b) * eps)) - 1.0)) / Float64(Float64(exp(Float64(a * eps)) - 1.0) * Float64(exp(Float64(b * eps)) - 1.0)))
end
function tmp = code(a, b, eps)
	tmp = (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0));
end
code[a_, b_, eps_] := N[(N[(eps * N[(N[Exp[N[(N[(a + b), $MachinePrecision] * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Exp[N[(a * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] * N[(N[Exp[N[(b * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)}
\end{array}

Alternative 1: 99.9% accurate, 7.6× speedup?

\[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \varepsilon, -0.5 \cdot \varepsilon\right), b, 1\right)}{b}, a, 1\right)}{a} \end{array} \]
NOTE: a, b, and eps should be sorted in increasing order before calling this function.
(FPCore (a b eps)
 :precision binary64
 (/ (fma (/ (fma (fma 0.5 eps (* -0.5 eps)) b 1.0) b) a 1.0) a))
assert(a < b && b < eps);
double code(double a, double b, double eps) {
	return fma((fma(fma(0.5, eps, (-0.5 * eps)), b, 1.0) / b), a, 1.0) / a;
}
a, b, eps = sort([a, b, eps])
function code(a, b, eps)
	return Float64(fma(Float64(fma(fma(0.5, eps, Float64(-0.5 * eps)), b, 1.0) / b), a, 1.0) / a)
end
NOTE: a, b, and eps should be sorted in increasing order before calling this function.
code[a_, b_, eps_] := N[(N[(N[(N[(N[(0.5 * eps + N[(-0.5 * eps), $MachinePrecision]), $MachinePrecision] * b + 1.0), $MachinePrecision] / b), $MachinePrecision] * a + 1.0), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
[a, b, eps] = \mathsf{sort}([a, b, eps])\\
\\
\frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \varepsilon, -0.5 \cdot \varepsilon\right), b, 1\right)}{b}, a, 1\right)}{a}
\end{array}
Derivation
  1. Initial program 0.0%

    \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0

    \[\leadsto \color{blue}{\frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{a}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{\color{blue}{a}} \]
  5. Applied rewrites43.4%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\varepsilon, \frac{{\left(e^{\varepsilon}\right)}^{b}}{\mathsf{expm1}\left(b \cdot \varepsilon\right)}, -0.5 \cdot \varepsilon\right), a, 1\right)}{a}} \]
  6. Taylor expanded in b around 0

    \[\leadsto \frac{\mathsf{fma}\left(\frac{1 + b \cdot \left(\left(\varepsilon + \frac{-1}{2} \cdot \varepsilon\right) - \frac{1}{2} \cdot \varepsilon\right)}{b}, a, 1\right)}{a} \]
  7. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1 + b \cdot \left(\left(\varepsilon + \frac{-1}{2} \cdot \varepsilon\right) - \frac{1}{2} \cdot \varepsilon\right)}{b}, a, 1\right)}{a} \]
    2. +-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{b \cdot \left(\left(\varepsilon + \frac{-1}{2} \cdot \varepsilon\right) - \frac{1}{2} \cdot \varepsilon\right) + 1}{b}, a, 1\right)}{a} \]
    3. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\left(\left(\varepsilon + \frac{-1}{2} \cdot \varepsilon\right) - \frac{1}{2} \cdot \varepsilon\right) \cdot b + 1}{b}, a, 1\right)}{a} \]
    4. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\left(\varepsilon + \frac{-1}{2} \cdot \varepsilon\right) - \frac{1}{2} \cdot \varepsilon, b, 1\right)}{b}, a, 1\right)}{a} \]
    5. fp-cancel-sub-sign-invN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\left(\varepsilon + \frac{-1}{2} \cdot \varepsilon\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \varepsilon, b, 1\right)}{b}, a, 1\right)}{a} \]
    6. distribute-rgt1-inN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\left(\frac{-1}{2} + 1\right) \cdot \varepsilon + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \varepsilon, b, 1\right)}{b}, a, 1\right)}{a} \]
    7. metadata-evalN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{1}{2} \cdot \varepsilon + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \varepsilon, b, 1\right)}{b}, a, 1\right)}{a} \]
    8. metadata-evalN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{1}{2} \cdot \varepsilon + \frac{-1}{2} \cdot \varepsilon, b, 1\right)}{b}, a, 1\right)}{a} \]
    9. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{2}, \varepsilon, \frac{-1}{2} \cdot \varepsilon\right), b, 1\right)}{b}, a, 1\right)}{a} \]
    10. lift-*.f6499.9

      \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \varepsilon, -0.5 \cdot \varepsilon\right), b, 1\right)}{b}, a, 1\right)}{a} \]
  8. Applied rewrites99.9%

    \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \varepsilon, -0.5 \cdot \varepsilon\right), b, 1\right)}{b}, a, 1\right)}{a} \]
  9. Add Preprocessing

Alternative 2: 79.7% accurate, 13.4× speedup?

\[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \begin{array}{l} \mathbf{if}\;a \leq -4 \cdot 10^{-145}:\\ \;\;\;\;\frac{b + a}{b \cdot a}\\ \mathbf{elif}\;a \leq -1.13 \cdot 10^{-213}:\\ \;\;\;\;\frac{1}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{a}\\ \end{array} \end{array} \]
NOTE: a, b, and eps should be sorted in increasing order before calling this function.
(FPCore (a b eps)
 :precision binary64
 (if (<= a -4e-145)
   (/ (+ b a) (* b a))
   (if (<= a -1.13e-213) (/ 1.0 b) (/ 1.0 a))))
assert(a < b && b < eps);
double code(double a, double b, double eps) {
	double tmp;
	if (a <= -4e-145) {
		tmp = (b + a) / (b * a);
	} else if (a <= -1.13e-213) {
		tmp = 1.0 / b;
	} else {
		tmp = 1.0 / a;
	}
	return tmp;
}
NOTE: a, b, and eps should be sorted in increasing order before calling this function.
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(a, b, eps)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: eps
    real(8) :: tmp
    if (a <= (-4d-145)) then
        tmp = (b + a) / (b * a)
    else if (a <= (-1.13d-213)) then
        tmp = 1.0d0 / b
    else
        tmp = 1.0d0 / a
    end if
    code = tmp
end function
assert a < b && b < eps;
public static double code(double a, double b, double eps) {
	double tmp;
	if (a <= -4e-145) {
		tmp = (b + a) / (b * a);
	} else if (a <= -1.13e-213) {
		tmp = 1.0 / b;
	} else {
		tmp = 1.0 / a;
	}
	return tmp;
}
[a, b, eps] = sort([a, b, eps])
def code(a, b, eps):
	tmp = 0
	if a <= -4e-145:
		tmp = (b + a) / (b * a)
	elif a <= -1.13e-213:
		tmp = 1.0 / b
	else:
		tmp = 1.0 / a
	return tmp
a, b, eps = sort([a, b, eps])
function code(a, b, eps)
	tmp = 0.0
	if (a <= -4e-145)
		tmp = Float64(Float64(b + a) / Float64(b * a));
	elseif (a <= -1.13e-213)
		tmp = Float64(1.0 / b);
	else
		tmp = Float64(1.0 / a);
	end
	return tmp
end
a, b, eps = num2cell(sort([a, b, eps])){:}
function tmp_2 = code(a, b, eps)
	tmp = 0.0;
	if (a <= -4e-145)
		tmp = (b + a) / (b * a);
	elseif (a <= -1.13e-213)
		tmp = 1.0 / b;
	else
		tmp = 1.0 / a;
	end
	tmp_2 = tmp;
end
NOTE: a, b, and eps should be sorted in increasing order before calling this function.
code[a_, b_, eps_] := If[LessEqual[a, -4e-145], N[(N[(b + a), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, -1.13e-213], N[(1.0 / b), $MachinePrecision], N[(1.0 / a), $MachinePrecision]]]
\begin{array}{l}
[a, b, eps] = \mathsf{sort}([a, b, eps])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4 \cdot 10^{-145}:\\
\;\;\;\;\frac{b + a}{b \cdot a}\\

\mathbf{elif}\;a \leq -1.13 \cdot 10^{-213}:\\
\;\;\;\;\frac{1}{b}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a < -3.99999999999999966e-145

    1. Initial program 0.0%

      \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in eps around 0

      \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
      2. lower-/.f64N/A

        \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
      3. lower-/.f64N/A

        \[\leadsto \frac{\frac{a + b}{a}}{b} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{b + a}{a}}{b} \]
      5. lower-+.f64100.0

        \[\leadsto \frac{\frac{b + a}{a}}{b} \]
    5. Applied rewrites100.0%

      \[\leadsto \color{blue}{\frac{\frac{b + a}{a}}{b}} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\frac{b + a}{a}}{\color{blue}{b}} \]
      2. lift-+.f64N/A

        \[\leadsto \frac{\frac{b + a}{a}}{b} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{\frac{b + a}{a}}{b} \]
      4. associate-/l/N/A

        \[\leadsto \frac{b + a}{\color{blue}{a \cdot b}} \]
      5. +-commutativeN/A

        \[\leadsto \frac{a + b}{\color{blue}{a} \cdot b} \]
      6. lower-/.f64N/A

        \[\leadsto \frac{a + b}{\color{blue}{a \cdot b}} \]
      7. +-commutativeN/A

        \[\leadsto \frac{b + a}{\color{blue}{a} \cdot b} \]
      8. lift-+.f64N/A

        \[\leadsto \frac{b + a}{\color{blue}{a} \cdot b} \]
      9. *-commutativeN/A

        \[\leadsto \frac{b + a}{b \cdot \color{blue}{a}} \]
      10. lower-*.f6483.3

        \[\leadsto \frac{b + a}{b \cdot \color{blue}{a}} \]
    7. Applied rewrites83.3%

      \[\leadsto \frac{b + a}{\color{blue}{b \cdot a}} \]

    if -3.99999999999999966e-145 < a < -1.13e-213

    1. Initial program 0.0%

      \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in eps around 0

      \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
      2. lower-/.f64N/A

        \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
      3. lower-/.f64N/A

        \[\leadsto \frac{\frac{a + b}{a}}{b} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\frac{b + a}{a}}{b} \]
      5. lower-+.f6499.8

        \[\leadsto \frac{\frac{b + a}{a}}{b} \]
    5. Applied rewrites99.8%

      \[\leadsto \color{blue}{\frac{\frac{b + a}{a}}{b}} \]
    6. Taylor expanded in a around inf

      \[\leadsto \frac{1}{b} \]
    7. Step-by-step derivation
      1. Applied rewrites41.0%

        \[\leadsto \frac{1}{b} \]

      if -1.13e-213 < a

      1. Initial program 0.0%

        \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in a around 0

        \[\leadsto \color{blue}{\frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{a}} \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{\color{blue}{a}} \]
      5. Applied rewrites38.0%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\varepsilon, \frac{{\left(e^{\varepsilon}\right)}^{b}}{\mathsf{expm1}\left(b \cdot \varepsilon\right)}, -0.5 \cdot \varepsilon\right), a, 1\right)}{a}} \]
      6. Taylor expanded in a around 0

        \[\leadsto \frac{1}{a} \]
      7. Step-by-step derivation
        1. Applied rewrites60.6%

          \[\leadsto \frac{1}{a} \]
      8. Recombined 3 regimes into one program.
      9. Add Preprocessing

      Alternative 3: 99.8% accurate, 13.4× speedup?

      \[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \frac{\frac{b + a}{b}}{a} \end{array} \]
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      (FPCore (a b eps) :precision binary64 (/ (/ (+ b a) b) a))
      assert(a < b && b < eps);
      double code(double a, double b, double eps) {
      	return ((b + a) / b) / a;
      }
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      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(a, b, eps)
      use fmin_fmax_functions
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: eps
          code = ((b + a) / b) / a
      end function
      
      assert a < b && b < eps;
      public static double code(double a, double b, double eps) {
      	return ((b + a) / b) / a;
      }
      
      [a, b, eps] = sort([a, b, eps])
      def code(a, b, eps):
      	return ((b + a) / b) / a
      
      a, b, eps = sort([a, b, eps])
      function code(a, b, eps)
      	return Float64(Float64(Float64(b + a) / b) / a)
      end
      
      a, b, eps = num2cell(sort([a, b, eps])){:}
      function tmp = code(a, b, eps)
      	tmp = ((b + a) / b) / a;
      end
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      code[a_, b_, eps_] := N[(N[(N[(b + a), $MachinePrecision] / b), $MachinePrecision] / a), $MachinePrecision]
      
      \begin{array}{l}
      [a, b, eps] = \mathsf{sort}([a, b, eps])\\
      \\
      \frac{\frac{b + a}{b}}{a}
      \end{array}
      
      Derivation
      1. Initial program 0.0%

        \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in eps around 0

        \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
      4. Step-by-step derivation
        1. associate-/r*N/A

          \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
        2. lower-/.f64N/A

          \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
        3. lower-/.f64N/A

          \[\leadsto \frac{\frac{a + b}{a}}{b} \]
        4. +-commutativeN/A

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
        5. lower-+.f6499.8

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
      5. Applied rewrites99.8%

        \[\leadsto \color{blue}{\frac{\frac{b + a}{a}}{b}} \]
      6. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \frac{\frac{b + a}{a}}{\color{blue}{b}} \]
        2. lift-+.f64N/A

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
        3. lift-/.f64N/A

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
        4. associate-/l/N/A

          \[\leadsto \frac{b + a}{\color{blue}{a \cdot b}} \]
        5. +-commutativeN/A

          \[\leadsto \frac{a + b}{\color{blue}{a} \cdot b} \]
        6. lower-/.f64N/A

          \[\leadsto \frac{a + b}{\color{blue}{a \cdot b}} \]
        7. +-commutativeN/A

          \[\leadsto \frac{b + a}{\color{blue}{a} \cdot b} \]
        8. lift-+.f64N/A

          \[\leadsto \frac{b + a}{\color{blue}{a} \cdot b} \]
        9. *-commutativeN/A

          \[\leadsto \frac{b + a}{b \cdot \color{blue}{a}} \]
        10. lower-*.f6459.8

          \[\leadsto \frac{b + a}{b \cdot \color{blue}{a}} \]
      7. Applied rewrites59.8%

        \[\leadsto \frac{b + a}{\color{blue}{b \cdot a}} \]
      8. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \frac{b + a}{\color{blue}{b} \cdot a} \]
        2. lift-*.f64N/A

          \[\leadsto \frac{b + a}{b \cdot \color{blue}{a}} \]
        3. lift-/.f64N/A

          \[\leadsto \frac{b + a}{\color{blue}{b \cdot a}} \]
        4. associate-/r*N/A

          \[\leadsto \frac{\frac{b + a}{b}}{\color{blue}{a}} \]
        5. lower-/.f64N/A

          \[\leadsto \frac{\frac{b + a}{b}}{\color{blue}{a}} \]
        6. +-commutativeN/A

          \[\leadsto \frac{\frac{a + b}{b}}{a} \]
        7. lower-/.f64N/A

          \[\leadsto \frac{\frac{a + b}{b}}{a} \]
        8. +-commutativeN/A

          \[\leadsto \frac{\frac{b + a}{b}}{a} \]
        9. lift-+.f6499.8

          \[\leadsto \frac{\frac{b + a}{b}}{a} \]
      9. Applied rewrites99.8%

        \[\leadsto \frac{\frac{b + a}{b}}{\color{blue}{a}} \]
      10. Add Preprocessing

      Alternative 4: 99.8% accurate, 13.4× speedup?

      \[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \frac{\frac{b + a}{a}}{b} \end{array} \]
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      (FPCore (a b eps) :precision binary64 (/ (/ (+ b a) a) b))
      assert(a < b && b < eps);
      double code(double a, double b, double eps) {
      	return ((b + a) / a) / b;
      }
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      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(a, b, eps)
      use fmin_fmax_functions
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: eps
          code = ((b + a) / a) / b
      end function
      
      assert a < b && b < eps;
      public static double code(double a, double b, double eps) {
      	return ((b + a) / a) / b;
      }
      
      [a, b, eps] = sort([a, b, eps])
      def code(a, b, eps):
      	return ((b + a) / a) / b
      
      a, b, eps = sort([a, b, eps])
      function code(a, b, eps)
      	return Float64(Float64(Float64(b + a) / a) / b)
      end
      
      a, b, eps = num2cell(sort([a, b, eps])){:}
      function tmp = code(a, b, eps)
      	tmp = ((b + a) / a) / b;
      end
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      code[a_, b_, eps_] := N[(N[(N[(b + a), $MachinePrecision] / a), $MachinePrecision] / b), $MachinePrecision]
      
      \begin{array}{l}
      [a, b, eps] = \mathsf{sort}([a, b, eps])\\
      \\
      \frac{\frac{b + a}{a}}{b}
      \end{array}
      
      Derivation
      1. Initial program 0.0%

        \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in eps around 0

        \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
      4. Step-by-step derivation
        1. associate-/r*N/A

          \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
        2. lower-/.f64N/A

          \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
        3. lower-/.f64N/A

          \[\leadsto \frac{\frac{a + b}{a}}{b} \]
        4. +-commutativeN/A

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
        5. lower-+.f6499.8

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
      5. Applied rewrites99.8%

        \[\leadsto \color{blue}{\frac{\frac{b + a}{a}}{b}} \]
      6. Add Preprocessing

      Alternative 5: 99.8% accurate, 13.4× speedup?

      \[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \frac{\frac{b}{a} + 1}{b} \end{array} \]
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      (FPCore (a b eps) :precision binary64 (/ (+ (/ b a) 1.0) b))
      assert(a < b && b < eps);
      double code(double a, double b, double eps) {
      	return ((b / a) + 1.0) / b;
      }
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      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(a, b, eps)
      use fmin_fmax_functions
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: eps
          code = ((b / a) + 1.0d0) / b
      end function
      
      assert a < b && b < eps;
      public static double code(double a, double b, double eps) {
      	return ((b / a) + 1.0) / b;
      }
      
      [a, b, eps] = sort([a, b, eps])
      def code(a, b, eps):
      	return ((b / a) + 1.0) / b
      
      a, b, eps = sort([a, b, eps])
      function code(a, b, eps)
      	return Float64(Float64(Float64(b / a) + 1.0) / b)
      end
      
      a, b, eps = num2cell(sort([a, b, eps])){:}
      function tmp = code(a, b, eps)
      	tmp = ((b / a) + 1.0) / b;
      end
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      code[a_, b_, eps_] := N[(N[(N[(b / a), $MachinePrecision] + 1.0), $MachinePrecision] / b), $MachinePrecision]
      
      \begin{array}{l}
      [a, b, eps] = \mathsf{sort}([a, b, eps])\\
      \\
      \frac{\frac{b}{a} + 1}{b}
      \end{array}
      
      Derivation
      1. Initial program 0.0%

        \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in eps around 0

        \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
      4. Step-by-step derivation
        1. associate-/r*N/A

          \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
        2. lower-/.f64N/A

          \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
        3. lower-/.f64N/A

          \[\leadsto \frac{\frac{a + b}{a}}{b} \]
        4. +-commutativeN/A

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
        5. lower-+.f6499.8

          \[\leadsto \frac{\frac{b + a}{a}}{b} \]
      5. Applied rewrites99.8%

        \[\leadsto \color{blue}{\frac{\frac{b + a}{a}}{b}} \]
      6. Taylor expanded in a around inf

        \[\leadsto \frac{1 + \frac{b}{a}}{b} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \frac{\frac{b}{a} + 1}{b} \]
        2. lower-+.f64N/A

          \[\leadsto \frac{\frac{b}{a} + 1}{b} \]
        3. lower-/.f6499.8

          \[\leadsto \frac{\frac{b}{a} + 1}{b} \]
      8. Applied rewrites99.8%

        \[\leadsto \frac{\frac{b}{a} + 1}{b} \]
      9. Add Preprocessing

      Alternative 6: 80.4% accurate, 19.4× speedup?

      \[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \begin{array}{l} \mathbf{if}\;a \leq -1.13 \cdot 10^{-213}:\\ \;\;\;\;\frac{1}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{a}\\ \end{array} \end{array} \]
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      (FPCore (a b eps)
       :precision binary64
       (if (<= a -1.13e-213) (/ 1.0 b) (/ 1.0 a)))
      assert(a < b && b < eps);
      double code(double a, double b, double eps) {
      	double tmp;
      	if (a <= -1.13e-213) {
      		tmp = 1.0 / b;
      	} else {
      		tmp = 1.0 / a;
      	}
      	return tmp;
      }
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      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(a, b, eps)
      use fmin_fmax_functions
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: eps
          real(8) :: tmp
          if (a <= (-1.13d-213)) then
              tmp = 1.0d0 / b
          else
              tmp = 1.0d0 / a
          end if
          code = tmp
      end function
      
      assert a < b && b < eps;
      public static double code(double a, double b, double eps) {
      	double tmp;
      	if (a <= -1.13e-213) {
      		tmp = 1.0 / b;
      	} else {
      		tmp = 1.0 / a;
      	}
      	return tmp;
      }
      
      [a, b, eps] = sort([a, b, eps])
      def code(a, b, eps):
      	tmp = 0
      	if a <= -1.13e-213:
      		tmp = 1.0 / b
      	else:
      		tmp = 1.0 / a
      	return tmp
      
      a, b, eps = sort([a, b, eps])
      function code(a, b, eps)
      	tmp = 0.0
      	if (a <= -1.13e-213)
      		tmp = Float64(1.0 / b);
      	else
      		tmp = Float64(1.0 / a);
      	end
      	return tmp
      end
      
      a, b, eps = num2cell(sort([a, b, eps])){:}
      function tmp_2 = code(a, b, eps)
      	tmp = 0.0;
      	if (a <= -1.13e-213)
      		tmp = 1.0 / b;
      	else
      		tmp = 1.0 / a;
      	end
      	tmp_2 = tmp;
      end
      
      NOTE: a, b, and eps should be sorted in increasing order before calling this function.
      code[a_, b_, eps_] := If[LessEqual[a, -1.13e-213], N[(1.0 / b), $MachinePrecision], N[(1.0 / a), $MachinePrecision]]
      
      \begin{array}{l}
      [a, b, eps] = \mathsf{sort}([a, b, eps])\\
      \\
      \begin{array}{l}
      \mathbf{if}\;a \leq -1.13 \cdot 10^{-213}:\\
      \;\;\;\;\frac{1}{b}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{1}{a}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if a < -1.13e-213

        1. Initial program 0.0%

          \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in eps around 0

          \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
        4. Step-by-step derivation
          1. associate-/r*N/A

            \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
          2. lower-/.f64N/A

            \[\leadsto \frac{\frac{a + b}{a}}{\color{blue}{b}} \]
          3. lower-/.f64N/A

            \[\leadsto \frac{\frac{a + b}{a}}{b} \]
          4. +-commutativeN/A

            \[\leadsto \frac{\frac{b + a}{a}}{b} \]
          5. lower-+.f6499.9

            \[\leadsto \frac{\frac{b + a}{a}}{b} \]
        5. Applied rewrites99.9%

          \[\leadsto \color{blue}{\frac{\frac{b + a}{a}}{b}} \]
        6. Taylor expanded in a around inf

          \[\leadsto \frac{1}{b} \]
        7. Step-by-step derivation
          1. Applied rewrites62.6%

            \[\leadsto \frac{1}{b} \]

          if -1.13e-213 < a

          1. Initial program 0.0%

            \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in a around 0

            \[\leadsto \color{blue}{\frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{a}} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{\color{blue}{a}} \]
          5. Applied rewrites38.0%

            \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\varepsilon, \frac{{\left(e^{\varepsilon}\right)}^{b}}{\mathsf{expm1}\left(b \cdot \varepsilon\right)}, -0.5 \cdot \varepsilon\right), a, 1\right)}{a}} \]
          6. Taylor expanded in a around 0

            \[\leadsto \frac{1}{a} \]
          7. Step-by-step derivation
            1. Applied rewrites60.6%

              \[\leadsto \frac{1}{a} \]
          8. Recombined 2 regimes into one program.
          9. Add Preprocessing

          Alternative 7: 50.8% accurate, 29.1× speedup?

          \[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \frac{1}{a} \end{array} \]
          NOTE: a, b, and eps should be sorted in increasing order before calling this function.
          (FPCore (a b eps) :precision binary64 (/ 1.0 a))
          assert(a < b && b < eps);
          double code(double a, double b, double eps) {
          	return 1.0 / a;
          }
          
          NOTE: a, b, and eps should be sorted in increasing order before calling this function.
          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(a, b, eps)
          use fmin_fmax_functions
              real(8), intent (in) :: a
              real(8), intent (in) :: b
              real(8), intent (in) :: eps
              code = 1.0d0 / a
          end function
          
          assert a < b && b < eps;
          public static double code(double a, double b, double eps) {
          	return 1.0 / a;
          }
          
          [a, b, eps] = sort([a, b, eps])
          def code(a, b, eps):
          	return 1.0 / a
          
          a, b, eps = sort([a, b, eps])
          function code(a, b, eps)
          	return Float64(1.0 / a)
          end
          
          a, b, eps = num2cell(sort([a, b, eps])){:}
          function tmp = code(a, b, eps)
          	tmp = 1.0 / a;
          end
          
          NOTE: a, b, and eps should be sorted in increasing order before calling this function.
          code[a_, b_, eps_] := N[(1.0 / a), $MachinePrecision]
          
          \begin{array}{l}
          [a, b, eps] = \mathsf{sort}([a, b, eps])\\
          \\
          \frac{1}{a}
          \end{array}
          
          Derivation
          1. Initial program 0.0%

            \[\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in a around 0

            \[\leadsto \color{blue}{\frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{a}} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \frac{1 + a \cdot \left(\frac{\varepsilon \cdot e^{b \cdot \varepsilon}}{e^{b \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{\color{blue}{a}} \]
          5. Applied rewrites43.4%

            \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\varepsilon, \frac{{\left(e^{\varepsilon}\right)}^{b}}{\mathsf{expm1}\left(b \cdot \varepsilon\right)}, -0.5 \cdot \varepsilon\right), a, 1\right)}{a}} \]
          6. Taylor expanded in a around 0

            \[\leadsto \frac{1}{a} \]
          7. Step-by-step derivation
            1. Applied rewrites54.0%

              \[\leadsto \frac{1}{a} \]
            2. Add Preprocessing

            Developer Target 1: 100.0% accurate, 13.4× speedup?

            \[\begin{array}{l} \\ \frac{1}{a} + \frac{1}{b} \end{array} \]
            (FPCore (a b eps) :precision binary64 (+ (/ 1.0 a) (/ 1.0 b)))
            double code(double a, double b, double eps) {
            	return (1.0 / a) + (1.0 / b);
            }
            
            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(a, b, eps)
            use fmin_fmax_functions
                real(8), intent (in) :: a
                real(8), intent (in) :: b
                real(8), intent (in) :: eps
                code = (1.0d0 / a) + (1.0d0 / b)
            end function
            
            public static double code(double a, double b, double eps) {
            	return (1.0 / a) + (1.0 / b);
            }
            
            def code(a, b, eps):
            	return (1.0 / a) + (1.0 / b)
            
            function code(a, b, eps)
            	return Float64(Float64(1.0 / a) + Float64(1.0 / b))
            end
            
            function tmp = code(a, b, eps)
            	tmp = (1.0 / a) + (1.0 / b);
            end
            
            code[a_, b_, eps_] := N[(N[(1.0 / a), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]
            
            \begin{array}{l}
            
            \\
            \frac{1}{a} + \frac{1}{b}
            \end{array}
            

            Reproduce

            ?
            herbie shell --seed 2025084 
            (FPCore (a b eps)
              :name "expq3 (problem 3.4.2)"
              :precision binary64
              :pre (and (and (<= (fabs a) 710.0) (<= (fabs b) 710.0)) (and (<= (* 1e-27 (fmin (fabs a) (fabs b))) eps) (<= eps (fmin (fabs a) (fabs b)))))
            
              :alt
              (! :herbie-platform default (+ (/ 1 a) (/ 1 b)))
            
              (/ (* eps (- (exp (* (+ a b) eps)) 1.0)) (* (- (exp (* a eps)) 1.0) (- (exp (* b eps)) 1.0))))