expq3 (problem 3.4.2)

Percentage Accurate: 0.0% → 99.9%
Time: 23.7s
Alternatives: 5
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}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 5 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, 12.0× speedup?

\[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \frac{\mathsf{fma}\left(\frac{1}{a}, b, 1\right)}{b} \end{array} \]
NOTE: a, b, and eps should be sorted in increasing order before calling this function.
(FPCore (a b eps) :precision binary64 (/ (fma (/ 1.0 a) b 1.0) b))
assert(a < b && b < eps);
double code(double a, double b, double eps) {
	return fma((1.0 / a), b, 1.0) / b;
}
a, b, eps = sort([a, b, eps])
function code(a, b, eps)
	return Float64(fma(Float64(1.0 / a), b, 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[(1.0 / a), $MachinePrecision] * b + 1.0), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
[a, b, eps] = \mathsf{sort}([a, b, eps])\\
\\
\frac{\mathsf{fma}\left(\frac{1}{a}, b, 1\right)}{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 b around 0

    \[\leadsto \color{blue}{\frac{1 + b \cdot \left(\frac{\varepsilon \cdot e^{a \cdot \varepsilon}}{e^{a \cdot \varepsilon} - 1} - \frac{1}{2} \cdot \varepsilon\right)}{b}} \]
  4. Step-by-step derivation
    1. Applied rewrites41.9%

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

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{a}, b, 1\right)}{b} \]
    3. Step-by-step derivation
      1. Applied rewrites99.9%

        \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{a}, b, 1\right)}{b} \]
      2. Add Preprocessing

      Alternative 2: 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. Applied rewrites99.8%

          \[\leadsto \color{blue}{\frac{\frac{b + a}{b}}{a}} \]
        2. Taylor expanded in eps around 0

          \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
        3. Step-by-step derivation
          1. Applied rewrites99.8%

            \[\leadsto \color{blue}{\frac{\frac{b + a}{a}}{b}} \]
          2. Step-by-step derivation
            1. Applied rewrites99.8%

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

            Alternative 3: 99.8% accurate, 13.4× speedup?

            \[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \frac{\frac{a}{b} + 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 (/ (+ (/ a b) 1.0) a))
            assert(a < b && b < eps);
            double code(double a, double b, double eps) {
            	return ((a / b) + 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 = ((a / b) + 1.0d0) / a
            end function
            
            assert a < b && b < eps;
            public static double code(double a, double b, double eps) {
            	return ((a / b) + 1.0) / a;
            }
            
            [a, b, eps] = sort([a, b, eps])
            def code(a, b, eps):
            	return ((a / b) + 1.0) / a
            
            a, b, eps = sort([a, b, eps])
            function code(a, b, eps)
            	return Float64(Float64(Float64(a / b) + 1.0) / a)
            end
            
            a, b, eps = num2cell(sort([a, b, eps])){:}
            function tmp = code(a, b, eps)
            	tmp = ((a / b) + 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[(a / b), $MachinePrecision] + 1.0), $MachinePrecision] / a), $MachinePrecision]
            
            \begin{array}{l}
            [a, b, eps] = \mathsf{sort}([a, b, eps])\\
            \\
            \frac{\frac{a}{b} + 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 eps around 0

              \[\leadsto \color{blue}{\frac{a + b}{a \cdot b}} \]
            4. Step-by-step derivation
              1. Applied rewrites99.8%

                \[\leadsto \color{blue}{\frac{\frac{b + a}{b}}{a}} \]
              2. Step-by-step derivation
                1. Applied rewrites99.8%

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

                Alternative 4: 80.4% accurate, 19.4× speedup?

                \[\begin{array}{l} [a, b, eps] = \mathsf{sort}([a, b, eps])\\ \\ \begin{array}{l} \mathbf{if}\;a \leq -4.4 \cdot 10^{-197}:\\ \;\;\;\;\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 -4.4e-197) (/ 1.0 b) (/ 1.0 a)))
                assert(a < b && b < eps);
                double code(double a, double b, double eps) {
                	double tmp;
                	if (a <= -4.4e-197) {
                		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 <= (-4.4d-197)) 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 <= -4.4e-197) {
                		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 <= -4.4e-197:
                		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 <= -4.4e-197)
                		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 <= -4.4e-197)
                		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, -4.4e-197], 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.4 \cdot 10^{-197}:\\
                \;\;\;\;\frac{1}{b}\\
                
                \mathbf{else}:\\
                \;\;\;\;\frac{1}{a}\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if a < -4.4000000000000001e-197

                  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 b around 0

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

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

                    if -4.4000000000000001e-197 < 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}} \]
                    4. Step-by-step derivation
                      1. Applied rewrites61.5%

                        \[\leadsto \color{blue}{\frac{1}{a}} \]
                    5. Recombined 2 regimes into one program.
                    6. Add Preprocessing

                    Alternative 5: 51.2% 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}} \]
                    4. Step-by-step derivation
                      1. Applied rewrites54.0%

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

                      Developer Target 1: 99.9% 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 2025021 
                      (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))))