symmetry log of sum of exp

Percentage Accurate: 53.4% → 98.5%
Time: 11.8s
Alternatives: 5
Speedup: 0.7×

Specification

?
\[\log \left(e^{a} + e^{b}\right) \]
(FPCore (a b)
  :precision binary64
  (log (+ (exp a) (exp b))))
double code(double a, double b) {
	return log((exp(a) + exp(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)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
	return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b):
	return math.log((math.exp(a) + math.exp(b)))
function code(a, b)
	return log(Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = log((exp(a) + exp(b)));
end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\log \left(e^{a} + e^{b}\right)

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: 53.4% accurate, 1.0× speedup?

\[\log \left(e^{a} + e^{b}\right) \]
(FPCore (a b)
  :precision binary64
  (log (+ (exp a) (exp b))))
double code(double a, double b) {
	return log((exp(a) + exp(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)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
	return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b):
	return math.log((math.exp(a) + math.exp(b)))
function code(a, b)
	return log(Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = log((exp(a) + exp(b)));
end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\log \left(e^{a} + e^{b}\right)

Alternative 1: 98.5% accurate, 0.7× speedup?

\[\begin{array}{l} t_0 := e^{\mathsf{min}\left(a, b\right)}\\ \mathbf{if}\;\mathsf{min}\left(a, b\right) \leq -20:\\ \;\;\;\;\frac{\mathsf{max}\left(a, b\right)}{1 + t\_0}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{53\_log1z0}\left(\left(-t\_0\right)\right) - -0.5 \cdot \mathsf{max}\left(a, b\right)\\ \end{array} \]
(FPCore (a b)
  :precision binary64
  (let* ((t_0 (exp (fmin a b))))
  (if (<= (fmin a b) -20.0)
    (/ (fmax a b) (+ 1.0 t_0))
    (- (53-log1z0 (- t_0)) (* -0.5 (fmax a b))))))
\begin{array}{l}
t_0 := e^{\mathsf{min}\left(a, b\right)}\\
\mathbf{if}\;\mathsf{min}\left(a, b\right) \leq -20:\\
\;\;\;\;\frac{\mathsf{max}\left(a, b\right)}{1 + t\_0}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{53\_log1z0}\left(\left(-t\_0\right)\right) - -0.5 \cdot \mathsf{max}\left(a, b\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -20

    1. Initial program 53.4%

      \[\log \left(e^{a} + e^{b}\right) \]
    2. Taylor expanded in b around 0

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

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. lower-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      4. lower-exp.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      5. lower-/.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
      6. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
      7. lower-exp.f6474.4%

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. Applied rewrites74.4%

      \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. add-flipN/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      3. lower--.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      4. lift-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      5. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      6. add-flipN/A

        \[\leadsto \log \left(1 - \left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      7. lower-53-log1z0N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      9. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right) \]
      10. distribute-neg-frac2N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      12. lift-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      13. distribute-neg-inN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      15. sub-flip-reverseN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
      16. lower--.f6474.4%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
    6. Applied rewrites74.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
    7. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
      2. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{-1 - e^{a}}} \]
      3. sub-to-fractionN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\color{blue}{-1 - e^{a}}} \]
      4. lift--.f64N/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{-1 - \color{blue}{e^{a}}} \]
      5. sub-flipN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{-1 + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      8. lift-exp.f64N/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      9. sub-divN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} - \color{blue}{\frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      10. frac-subN/A

        \[\leadsto \frac{\left(\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot b}{\color{blue}{\left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \frac{\left(\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot b}{\color{blue}{\left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right)}} \]
    8. Applied rewrites74.4%

      \[\leadsto \frac{\left(\left(-1 - e^{a}\right) \cdot \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right)\right) \cdot \left(-1 - e^{a}\right) - \left(-1 - e^{a}\right) \cdot b}{\color{blue}{\left(-1 - e^{a}\right) \cdot \left(-1 - e^{a}\right)}} \]
    9. Taylor expanded in b around inf

      \[\leadsto \frac{b}{\color{blue}{1 + e^{a}}} \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{b}{1 + e^{a}} \]
      3. lower-exp.f6428.5%

        \[\leadsto \frac{b}{1 + e^{a}} \]
    11. Applied rewrites28.5%

      \[\leadsto \frac{b}{\color{blue}{1 + e^{a}}} \]

    if -20 < a

    1. Initial program 53.4%

      \[\log \left(e^{a} + e^{b}\right) \]
    2. Taylor expanded in b around 0

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

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. lower-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      4. lower-exp.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      5. lower-/.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
      6. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
      7. lower-exp.f6474.4%

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. Applied rewrites74.4%

      \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. add-flipN/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      3. lower--.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      4. lift-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      5. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      6. add-flipN/A

        \[\leadsto \log \left(1 - \left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      7. lower-53-log1z0N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      9. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right) \]
      10. distribute-neg-frac2N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      12. lift-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      13. distribute-neg-inN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      15. sub-flip-reverseN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
      16. lower--.f6474.4%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
    6. Applied rewrites74.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
    7. Taylor expanded in a around 0

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{-1}{2} \cdot \color{blue}{b} \]
    8. Step-by-step derivation
      1. lower-*.f6453.4%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - -0.5 \cdot b \]
    9. Applied rewrites53.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - -0.5 \cdot \color{blue}{b} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 98.4% accurate, 0.6× speedup?

\[\begin{array}{l} t_0 := e^{\mathsf{min}\left(a, b\right)}\\ \mathsf{53\_log1z0}\left(\left(-t\_0\right)\right) - \frac{\mathsf{max}\left(a, b\right)}{-1 - t\_0} \end{array} \]
(FPCore (a b)
  :precision binary64
  (let* ((t_0 (exp (fmin a b))))
  (- (53-log1z0 (- t_0)) (/ (fmax a b) (- -1.0 t_0)))))
\begin{array}{l}
t_0 := e^{\mathsf{min}\left(a, b\right)}\\
\mathsf{53\_log1z0}\left(\left(-t\_0\right)\right) - \frac{\mathsf{max}\left(a, b\right)}{-1 - t\_0}
\end{array}
Derivation
  1. Initial program 53.4%

    \[\log \left(e^{a} + e^{b}\right) \]
  2. Taylor expanded in b around 0

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

      \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
    2. lower-log.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
    3. lower-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. lower-exp.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    5. lower-/.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
    6. lower-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
    7. lower-exp.f6474.4%

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
  4. Applied rewrites74.4%

    \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
  5. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
    2. add-flipN/A

      \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
    3. lower--.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
    4. lift-log.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
    5. lift-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
    6. add-flipN/A

      \[\leadsto \log \left(1 - \left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
    7. lower-53-log1z0N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
    8. lower-neg.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
    9. lift-/.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right) \]
    10. distribute-neg-frac2N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
    11. lower-/.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
    12. lift-+.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
    13. distribute-neg-inN/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
    14. metadata-evalN/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
    15. sub-flip-reverseN/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
    16. lower--.f6474.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
  6. Applied rewrites74.4%

    \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
  7. Add Preprocessing

Alternative 3: 98.0% accurate, 0.6× speedup?

\[\begin{array}{l} \mathbf{if}\;\mathsf{min}\left(a, b\right) \leq -20:\\ \;\;\;\;\frac{\mathsf{max}\left(a, b\right)}{1 + e^{\mathsf{min}\left(a, b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\log 2 + \left(0.5 \cdot \mathsf{max}\left(a, b\right) + \mathsf{min}\left(a, b\right) \cdot \left(0.5 + 0.125 \cdot \mathsf{min}\left(a, b\right)\right)\right)\\ \end{array} \]
(FPCore (a b)
  :precision binary64
  (if (<= (fmin a b) -20.0)
  (/ (fmax a b) (+ 1.0 (exp (fmin a b))))
  (+
   (log 2.0)
   (+
    (* 0.5 (fmax a b))
    (* (fmin a b) (+ 0.5 (* 0.125 (fmin a b))))))))
double code(double a, double b) {
	double tmp;
	if (fmin(a, b) <= -20.0) {
		tmp = fmax(a, b) / (1.0 + exp(fmin(a, b)));
	} else {
		tmp = log(2.0) + ((0.5 * fmax(a, b)) + (fmin(a, b) * (0.5 + (0.125 * fmin(a, b)))));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (fmin(a, b) <= (-20.0d0)) then
        tmp = fmax(a, b) / (1.0d0 + exp(fmin(a, b)))
    else
        tmp = log(2.0d0) + ((0.5d0 * fmax(a, b)) + (fmin(a, b) * (0.5d0 + (0.125d0 * fmin(a, b)))))
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (fmin(a, b) <= -20.0) {
		tmp = fmax(a, b) / (1.0 + Math.exp(fmin(a, b)));
	} else {
		tmp = Math.log(2.0) + ((0.5 * fmax(a, b)) + (fmin(a, b) * (0.5 + (0.125 * fmin(a, b)))));
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if fmin(a, b) <= -20.0:
		tmp = fmax(a, b) / (1.0 + math.exp(fmin(a, b)))
	else:
		tmp = math.log(2.0) + ((0.5 * fmax(a, b)) + (fmin(a, b) * (0.5 + (0.125 * fmin(a, b)))))
	return tmp
function code(a, b)
	tmp = 0.0
	if (fmin(a, b) <= -20.0)
		tmp = Float64(fmax(a, b) / Float64(1.0 + exp(fmin(a, b))));
	else
		tmp = Float64(log(2.0) + Float64(Float64(0.5 * fmax(a, b)) + Float64(fmin(a, b) * Float64(0.5 + Float64(0.125 * fmin(a, b))))));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (min(a, b) <= -20.0)
		tmp = max(a, b) / (1.0 + exp(min(a, b)));
	else
		tmp = log(2.0) + ((0.5 * max(a, b)) + (min(a, b) * (0.5 + (0.125 * min(a, b)))));
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[N[Min[a, b], $MachinePrecision], -20.0], N[(N[Max[a, b], $MachinePrecision] / N[(1.0 + N[Exp[N[Min[a, b], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(N[(0.5 * N[Max[a, b], $MachinePrecision]), $MachinePrecision] + N[(N[Min[a, b], $MachinePrecision] * N[(0.5 + N[(0.125 * N[Min[a, b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\mathsf{min}\left(a, b\right) \leq -20:\\
\;\;\;\;\frac{\mathsf{max}\left(a, b\right)}{1 + e^{\mathsf{min}\left(a, b\right)}}\\

\mathbf{else}:\\
\;\;\;\;\log 2 + \left(0.5 \cdot \mathsf{max}\left(a, b\right) + \mathsf{min}\left(a, b\right) \cdot \left(0.5 + 0.125 \cdot \mathsf{min}\left(a, b\right)\right)\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -20

    1. Initial program 53.4%

      \[\log \left(e^{a} + e^{b}\right) \]
    2. Taylor expanded in b around 0

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

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. lower-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      4. lower-exp.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      5. lower-/.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
      6. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
      7. lower-exp.f6474.4%

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. Applied rewrites74.4%

      \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. add-flipN/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      3. lower--.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      4. lift-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      5. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      6. add-flipN/A

        \[\leadsto \log \left(1 - \left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      7. lower-53-log1z0N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      9. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right) \]
      10. distribute-neg-frac2N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      12. lift-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      13. distribute-neg-inN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      15. sub-flip-reverseN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
      16. lower--.f6474.4%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
    6. Applied rewrites74.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
    7. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
      2. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{-1 - e^{a}}} \]
      3. sub-to-fractionN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\color{blue}{-1 - e^{a}}} \]
      4. lift--.f64N/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{-1 - \color{blue}{e^{a}}} \]
      5. sub-flipN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{-1 + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      8. lift-exp.f64N/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      9. sub-divN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} - \color{blue}{\frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      10. frac-subN/A

        \[\leadsto \frac{\left(\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot b}{\color{blue}{\left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \frac{\left(\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot b}{\color{blue}{\left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right)}} \]
    8. Applied rewrites74.4%

      \[\leadsto \frac{\left(\left(-1 - e^{a}\right) \cdot \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right)\right) \cdot \left(-1 - e^{a}\right) - \left(-1 - e^{a}\right) \cdot b}{\color{blue}{\left(-1 - e^{a}\right) \cdot \left(-1 - e^{a}\right)}} \]
    9. Taylor expanded in b around inf

      \[\leadsto \frac{b}{\color{blue}{1 + e^{a}}} \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{b}{1 + e^{a}} \]
      3. lower-exp.f6428.5%

        \[\leadsto \frac{b}{1 + e^{a}} \]
    11. Applied rewrites28.5%

      \[\leadsto \frac{b}{\color{blue}{1 + e^{a}}} \]

    if -20 < a

    1. Initial program 53.4%

      \[\log \left(e^{a} + e^{b}\right) \]
    2. Taylor expanded in b around 0

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

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. lower-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      4. lower-exp.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      5. lower-/.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
      6. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
      7. lower-exp.f6474.4%

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. Applied rewrites74.4%

      \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
    5. Taylor expanded in a around 0

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

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + \color{blue}{a \cdot \left(\left(\frac{1}{2} + a \cdot \left(\frac{1}{8} - \left(\frac{-1}{8} \cdot b + \frac{1}{8} \cdot b\right)\right)\right) - \frac{1}{4} \cdot b\right)}\right) \]
      2. lower-log.f64N/A

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + \color{blue}{a} \cdot \left(\left(\frac{1}{2} + a \cdot \left(\frac{1}{8} - \left(\frac{-1}{8} \cdot b + \frac{1}{8} \cdot b\right)\right)\right) - \frac{1}{4} \cdot b\right)\right) \]
      3. lower-+.f64N/A

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + a \cdot \color{blue}{\left(\left(\frac{1}{2} + a \cdot \left(\frac{1}{8} - \left(\frac{-1}{8} \cdot b + \frac{1}{8} \cdot b\right)\right)\right) - \frac{1}{4} \cdot b\right)}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + a \cdot \left(\color{blue}{\left(\frac{1}{2} + a \cdot \left(\frac{1}{8} - \left(\frac{-1}{8} \cdot b + \frac{1}{8} \cdot b\right)\right)\right)} - \frac{1}{4} \cdot b\right)\right) \]
      5. lower-*.f64N/A

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + a \cdot \left(\left(\frac{1}{2} + a \cdot \left(\frac{1}{8} - \left(\frac{-1}{8} \cdot b + \frac{1}{8} \cdot b\right)\right)\right) - \color{blue}{\frac{1}{4} \cdot b}\right)\right) \]
      6. lower--.f64N/A

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + a \cdot \left(\left(\frac{1}{2} + a \cdot \left(\frac{1}{8} - \left(\frac{-1}{8} \cdot b + \frac{1}{8} \cdot b\right)\right)\right) - \frac{1}{4} \cdot \color{blue}{b}\right)\right) \]
    7. Applied rewrites48.7%

      \[\leadsto \log 2 + \color{blue}{\left(0.5 \cdot b + a \cdot \left(\left(0.5 + a \cdot \left(0.125 - \left(-0.125 \cdot b + 0.125 \cdot b\right)\right)\right) - 0.25 \cdot b\right)\right)} \]
    8. Taylor expanded in b around 0

      \[\leadsto \log 2 + \left(0.5 \cdot b + a \cdot \left(\frac{1}{2} + \color{blue}{\frac{1}{8} \cdot a}\right)\right) \]
    9. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + a \cdot \left(\frac{1}{2} + \frac{1}{8} \cdot \color{blue}{a}\right)\right) \]
      2. lower-+.f64N/A

        \[\leadsto \log 2 + \left(\frac{1}{2} \cdot b + a \cdot \left(\frac{1}{2} + \frac{1}{8} \cdot a\right)\right) \]
      3. lower-*.f6448.7%

        \[\leadsto \log 2 + \left(0.5 \cdot b + a \cdot \left(0.5 + 0.125 \cdot a\right)\right) \]
    10. Applied rewrites48.7%

      \[\leadsto \log 2 + \left(0.5 \cdot b + a \cdot \left(0.5 + \color{blue}{0.125 \cdot a}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 98.0% accurate, 0.3× speedup?

\[\begin{array}{l} t_0 := 1 + \mathsf{min}\left(a, b\right) \cdot \left(1 + \mathsf{min}\left(a, b\right) \cdot \left(0.5 + 0.16666666666666666 \cdot \mathsf{min}\left(a, b\right)\right)\right)\\ \mathbf{if}\;\mathsf{min}\left(a, b\right) \leq -0.4:\\ \;\;\;\;\frac{\mathsf{max}\left(a, b\right)}{1 + e^{\mathsf{min}\left(a, b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{53\_log1z0}\left(\left(-t\_0\right)\right) - \frac{\mathsf{max}\left(a, b\right)}{-1 - t\_0}\\ \end{array} \]
(FPCore (a b)
  :precision binary64
  (let* ((t_0
        (+
         1.0
         (*
          (fmin a b)
          (+
           1.0
           (*
            (fmin a b)
            (+ 0.5 (* 0.16666666666666666 (fmin a b)))))))))
  (if (<= (fmin a b) -0.4)
    (/ (fmax a b) (+ 1.0 (exp (fmin a b))))
    (- (53-log1z0 (- t_0)) (/ (fmax a b) (- -1.0 t_0))))))
\begin{array}{l}
t_0 := 1 + \mathsf{min}\left(a, b\right) \cdot \left(1 + \mathsf{min}\left(a, b\right) \cdot \left(0.5 + 0.16666666666666666 \cdot \mathsf{min}\left(a, b\right)\right)\right)\\
\mathbf{if}\;\mathsf{min}\left(a, b\right) \leq -0.4:\\
\;\;\;\;\frac{\mathsf{max}\left(a, b\right)}{1 + e^{\mathsf{min}\left(a, b\right)}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{53\_log1z0}\left(\left(-t\_0\right)\right) - \frac{\mathsf{max}\left(a, b\right)}{-1 - t\_0}\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -0.40000000000000002

    1. Initial program 53.4%

      \[\log \left(e^{a} + e^{b}\right) \]
    2. Taylor expanded in b around 0

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

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. lower-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      4. lower-exp.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      5. lower-/.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
      6. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
      7. lower-exp.f6474.4%

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. Applied rewrites74.4%

      \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. add-flipN/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      3. lower--.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      4. lift-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      5. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      6. add-flipN/A

        \[\leadsto \log \left(1 - \left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      7. lower-53-log1z0N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      9. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right) \]
      10. distribute-neg-frac2N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      12. lift-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      13. distribute-neg-inN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      15. sub-flip-reverseN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
      16. lower--.f6474.4%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
    6. Applied rewrites74.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
    7. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
      2. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{-1 - e^{a}}} \]
      3. sub-to-fractionN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\color{blue}{-1 - e^{a}}} \]
      4. lift--.f64N/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{-1 - \color{blue}{e^{a}}} \]
      5. sub-flipN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{-1 + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      7. distribute-neg-inN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      8. lift-exp.f64N/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right) - b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      9. sub-divN/A

        \[\leadsto \frac{\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} - \color{blue}{\frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      10. frac-subN/A

        \[\leadsto \frac{\left(\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot b}{\color{blue}{\left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \frac{\left(\mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) \cdot \left(-1 - e^{a}\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot b}{\color{blue}{\left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(1 + e^{a}\right)\right)\right)}} \]
    8. Applied rewrites74.4%

      \[\leadsto \frac{\left(\left(-1 - e^{a}\right) \cdot \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right)\right) \cdot \left(-1 - e^{a}\right) - \left(-1 - e^{a}\right) \cdot b}{\color{blue}{\left(-1 - e^{a}\right) \cdot \left(-1 - e^{a}\right)}} \]
    9. Taylor expanded in b around inf

      \[\leadsto \frac{b}{\color{blue}{1 + e^{a}}} \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{b}{1 + e^{a}} \]
      3. lower-exp.f6428.5%

        \[\leadsto \frac{b}{1 + e^{a}} \]
    11. Applied rewrites28.5%

      \[\leadsto \frac{b}{\color{blue}{1 + e^{a}}} \]

    if -0.40000000000000002 < a

    1. Initial program 53.4%

      \[\log \left(e^{a} + e^{b}\right) \]
    2. Taylor expanded in b around 0

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

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. lower-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      4. lower-exp.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
      5. lower-/.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
      6. lower-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
      7. lower-exp.f6474.4%

        \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. Applied rewrites74.4%

      \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
      2. add-flipN/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      3. lower--.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
      4. lift-log.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      5. lift-+.f64N/A

        \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      6. add-flipN/A

        \[\leadsto \log \left(1 - \left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      7. lower-53-log1z0N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
      9. lift-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right) \]
      10. distribute-neg-frac2N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
      12. lift-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
      13. distribute-neg-inN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
      15. sub-flip-reverseN/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
      16. lower--.f6474.4%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
    6. Applied rewrites74.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
    7. Taylor expanded in a around 0

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
    8. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
      3. lower-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
      5. lower-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
      6. lower-*.f6448.1%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(0.5 + 0.16666666666666666 \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
    9. Applied rewrites48.1%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(0.5 + 0.16666666666666666 \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - e^{a}} \]
    10. Taylor expanded in a around 0

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(0.5 + 0.16666666666666666 \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + \color{blue}{a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)}\right)} \]
    11. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + a \cdot \color{blue}{\left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)}\right)} \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + a \cdot \left(1 + \color{blue}{a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)}\right)\right)} \]
      3. lower-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + a \cdot \left(1 + a \cdot \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot a\right)}\right)\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \color{blue}{\frac{1}{6} \cdot a}\right)\right)\right)} \]
      5. lower-+.f64N/A

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot \color{blue}{a}\right)\right)\right)} \]
      6. lower-*.f6448.1%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(0.5 + 0.16666666666666666 \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + a \cdot \left(1 + a \cdot \left(0.5 + 0.16666666666666666 \cdot a\right)\right)\right)} \]
    12. Applied rewrites48.1%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-\left(1 + a \cdot \left(1 + a \cdot \left(0.5 + 0.16666666666666666 \cdot a\right)\right)\right)\right)\right) - \frac{b}{-1 - \left(1 + \color{blue}{a \cdot \left(1 + a \cdot \left(0.5 + 0.16666666666666666 \cdot a\right)\right)}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 49.0% accurate, 2.4× speedup?

\[\mathsf{53\_log1z0}\left(\left(-1\right)\right) - -0.5 \cdot \mathsf{max}\left(a, b\right) \]
(FPCore (a b)
  :precision binary64
  (- (53-log1z0 (- 1.0)) (* -0.5 (fmax a b))))
\mathsf{53\_log1z0}\left(\left(-1\right)\right) - -0.5 \cdot \mathsf{max}\left(a, b\right)
Derivation
  1. Initial program 53.4%

    \[\log \left(e^{a} + e^{b}\right) \]
  2. Taylor expanded in b around 0

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

      \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
    2. lower-log.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{\color{blue}{b}}{1 + e^{a}} \]
    3. lower-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    4. lower-exp.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
    5. lower-/.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{\color{blue}{1 + e^{a}}} \]
    6. lower-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + \color{blue}{e^{a}}} \]
    7. lower-exp.f6474.4%

      \[\leadsto \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}} \]
  4. Applied rewrites74.4%

    \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
  5. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) + \color{blue}{\frac{b}{1 + e^{a}}} \]
    2. add-flipN/A

      \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
    3. lower--.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) - \color{blue}{\left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right)} \]
    4. lift-log.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
    5. lift-+.f64N/A

      \[\leadsto \log \left(1 + e^{a}\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
    6. add-flipN/A

      \[\leadsto \log \left(1 - \left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
    7. lower-53-log1z0N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(\mathsf{neg}\left(e^{a}\right)\right)\right) - \left(\mathsf{neg}\left(\color{blue}{\frac{b}{1 + e^{a}}}\right)\right) \]
    8. lower-neg.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{\color{blue}{b}}{1 + e^{a}}\right)\right) \]
    9. lift-/.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \left(\mathsf{neg}\left(\frac{b}{1 + e^{a}}\right)\right) \]
    10. distribute-neg-frac2N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
    11. lower-/.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\color{blue}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)}} \]
    12. lift-+.f64N/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\mathsf{neg}\left(\left(1 + e^{a}\right)\right)} \]
    13. distribute-neg-inN/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(e^{a}\right)\right)}} \]
    14. metadata-evalN/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 + \left(\mathsf{neg}\left(\color{blue}{e^{a}}\right)\right)} \]
    15. sub-flip-reverseN/A

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
    16. lower--.f6474.4%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \frac{b}{-1 - \color{blue}{e^{a}}} \]
  6. Applied rewrites74.4%

    \[\leadsto \mathsf{53\_log1z0}\left(\left(-e^{a}\right)\right) - \color{blue}{\frac{b}{-1 - e^{a}}} \]
  7. Taylor expanded in a around 0

    \[\leadsto \mathsf{53\_log1z0}\left(\left(-1\right)\right) - \frac{b}{-1 - e^{a}} \]
  8. Step-by-step derivation
    1. Applied rewrites48.8%

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-1\right)\right) - \frac{b}{-1 - e^{a}} \]
    2. Taylor expanded in a around 0

      \[\leadsto \mathsf{53\_log1z0}\left(\left(-1\right)\right) - \frac{b}{-1 - 1} \]
    3. Step-by-step derivation
      1. Applied rewrites48.6%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-1\right)\right) - \frac{b}{-1 - 1} \]
      2. Taylor expanded in a around 0

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-1\right)\right) - \frac{-1}{2} \cdot \color{blue}{b} \]
      3. Step-by-step derivation
        1. lower-*.f6448.6%

          \[\leadsto \mathsf{53\_log1z0}\left(\left(-1\right)\right) - -0.5 \cdot b \]
      4. Applied rewrites48.6%

        \[\leadsto \mathsf{53\_log1z0}\left(\left(-1\right)\right) - -0.5 \cdot \color{blue}{b} \]
      5. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2025260 -o generate:evaluate
      (FPCore (a b)
        :name "symmetry log of sum of exp"
        :precision binary64
        (log (+ (exp a) (exp b))))