(log (* (+ z0 z1) z2))

Percentage Accurate: 76.2% → 99.1%
Time: 11.7s
Alternatives: 6
Speedup: 0.9×

Specification

?
\[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
(FPCore (z0 z1 z2)
  :precision binary64
  (log (* (+ z0 z1) z2)))
double code(double z0, double z1, double z2) {
	return log(((z0 + z1) * z2));
}
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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    code = log(((z0 + z1) * z2))
end function
public static double code(double z0, double z1, double z2) {
	return Math.log(((z0 + z1) * z2));
}
def code(z0, z1, z2):
	return math.log(((z0 + z1) * z2))
function code(z0, z1, z2)
	return log(Float64(Float64(z0 + z1) * z2))
end
function tmp = code(z0, z1, z2)
	tmp = log(((z0 + z1) * z2));
end
code[z0_, z1_, z2_] := N[Log[N[(N[(z0 + z1), $MachinePrecision] * z2), $MachinePrecision]], $MachinePrecision]
\log \left(\left(z0 + z1\right) \cdot z2\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 6 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: 76.2% accurate, 1.0× speedup?

\[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
(FPCore (z0 z1 z2)
  :precision binary64
  (log (* (+ z0 z1) z2)))
double code(double z0, double z1, double z2) {
	return log(((z0 + z1) * z2));
}
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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    code = log(((z0 + z1) * z2))
end function
public static double code(double z0, double z1, double z2) {
	return Math.log(((z0 + z1) * z2));
}
def code(z0, z1, z2):
	return math.log(((z0 + z1) * z2))
function code(z0, z1, z2)
	return log(Float64(Float64(z0 + z1) * z2))
end
function tmp = code(z0, z1, z2)
	tmp = log(((z0 + z1) * z2));
end
code[z0_, z1_, z2_] := N[Log[N[(N[(z0 + z1), $MachinePrecision] * z2), $MachinePrecision]], $MachinePrecision]
\log \left(\left(z0 + z1\right) \cdot z2\right)

Alternative 1: 99.1% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;z2 \leq \frac{-20240225330731}{101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392}:\\ \;\;\;\;\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(z2 + z2\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)\\ \end{array} \]
(FPCore (z0 z1 z2)
  :precision binary64
  (if (<=
     z2
     -20240225330731/101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392)
  (+ (log (- (- z0) z1)) (log (- z2)))
  (+ (log (+ z2 z2)) (log (* 1/2 (+ z1 z0))))))
double code(double z0, double z1, double z2) {
	double tmp;
	if (z2 <= -2e-310) {
		tmp = log((-z0 - z1)) + log(-z2);
	} else {
		tmp = log((z2 + z2)) + log((0.5 * (z1 + z0)));
	}
	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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    real(8) :: tmp
    if (z2 <= (-2d-310)) then
        tmp = log((-z0 - z1)) + log(-z2)
    else
        tmp = log((z2 + z2)) + log((0.5d0 * (z1 + z0)))
    end if
    code = tmp
end function
public static double code(double z0, double z1, double z2) {
	double tmp;
	if (z2 <= -2e-310) {
		tmp = Math.log((-z0 - z1)) + Math.log(-z2);
	} else {
		tmp = Math.log((z2 + z2)) + Math.log((0.5 * (z1 + z0)));
	}
	return tmp;
}
def code(z0, z1, z2):
	tmp = 0
	if z2 <= -2e-310:
		tmp = math.log((-z0 - z1)) + math.log(-z2)
	else:
		tmp = math.log((z2 + z2)) + math.log((0.5 * (z1 + z0)))
	return tmp
function code(z0, z1, z2)
	tmp = 0.0
	if (z2 <= -2e-310)
		tmp = Float64(log(Float64(Float64(-z0) - z1)) + log(Float64(-z2)));
	else
		tmp = Float64(log(Float64(z2 + z2)) + log(Float64(0.5 * Float64(z1 + z0))));
	end
	return tmp
end
function tmp_2 = code(z0, z1, z2)
	tmp = 0.0;
	if (z2 <= -2e-310)
		tmp = log((-z0 - z1)) + log(-z2);
	else
		tmp = log((z2 + z2)) + log((0.5 * (z1 + z0)));
	end
	tmp_2 = tmp;
end
code[z0_, z1_, z2_] := If[LessEqual[z2, -20240225330731/101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392], N[(N[Log[N[((-z0) - z1), $MachinePrecision]], $MachinePrecision] + N[Log[(-z2)], $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(z2 + z2), $MachinePrecision]], $MachinePrecision] + N[Log[N[(1/2 * N[(z1 + z0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;z2 \leq \frac{-20240225330731}{101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392}:\\
\;\;\;\;\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(z2 + z2\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z2 < -1.9999999999999939e-310

    1. Initial program 76.2%

      \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
      3. lift-+.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(z0 + z1\right)} \cdot z2\right) \]
      4. add-flipN/A

        \[\leadsto \log \left(\color{blue}{\left(z0 - \left(\mathsf{neg}\left(z1\right)\right)\right)} \cdot z2\right) \]
      5. sub-negate-revN/A

        \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)\right)\right)} \cdot z2\right) \]
      6. distribute-lft-neg-outN/A

        \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot z2\right)\right)} \]
      7. distribute-rgt-neg-inN/A

        \[\leadsto \log \color{blue}{\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot \left(\mathsf{neg}\left(z2\right)\right)\right)} \]
      8. log-prodN/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      9. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      10. lower-unsound-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      11. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z1\right)\right) + \left(\mathsf{neg}\left(z0\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      12. +-commutativeN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) + \left(\mathsf{neg}\left(z1\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      13. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      14. lower--.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      15. lower-neg.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(-z0\right)} - z1\right) + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      16. lower-unsound-log.f64N/A

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \color{blue}{\log \left(\mathsf{neg}\left(z2\right)\right)} \]
      17. lower-neg.f6449.7%

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \log \color{blue}{\left(-z2\right)} \]
    3. Applied rewrites49.7%

      \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]

    if -1.9999999999999939e-310 < z2

    1. Initial program 76.2%

      \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
      3. lift-+.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(z0 + z1\right)} \cdot z2\right) \]
      4. add-flipN/A

        \[\leadsto \log \left(\color{blue}{\left(z0 - \left(\mathsf{neg}\left(z1\right)\right)\right)} \cdot z2\right) \]
      5. sub-negate-revN/A

        \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)\right)\right)} \cdot z2\right) \]
      6. distribute-lft-neg-outN/A

        \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot z2\right)\right)} \]
      7. distribute-rgt-neg-inN/A

        \[\leadsto \log \color{blue}{\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot \left(\mathsf{neg}\left(z2\right)\right)\right)} \]
      8. log-prodN/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      9. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      10. lower-unsound-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      11. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z1\right)\right) + \left(\mathsf{neg}\left(z0\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      12. +-commutativeN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) + \left(\mathsf{neg}\left(z1\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      13. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      14. lower--.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      15. lower-neg.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(-z0\right)} - z1\right) + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      16. lower-unsound-log.f64N/A

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \color{blue}{\log \left(\mathsf{neg}\left(z2\right)\right)} \]
      17. lower-neg.f6449.7%

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \log \color{blue}{\left(-z2\right)} \]
    3. Applied rewrites49.7%

      \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
    4. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\log \left(-z2\right) + \log \left(\left(-z0\right) - z1\right)} \]
      3. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(-z2\right)} + \log \left(\left(-z0\right) - z1\right) \]
      4. lift-log.f64N/A

        \[\leadsto \log \left(-z2\right) + \color{blue}{\log \left(\left(-z0\right) - z1\right)} \]
      5. sum-logN/A

        \[\leadsto \color{blue}{\log \left(\left(-z2\right) \cdot \left(\left(-z0\right) - z1\right)\right)} \]
      6. lift-neg.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(z2\right)\right)} \cdot \left(\left(-z0\right) - z1\right)\right) \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(z2 \cdot \left(\left(-z0\right) - z1\right)\right)\right)} \]
      8. distribute-rgt-neg-outN/A

        \[\leadsto \log \color{blue}{\left(z2 \cdot \left(\mathsf{neg}\left(\left(\left(-z0\right) - z1\right)\right)\right)\right)} \]
      9. lift--.f64N/A

        \[\leadsto \log \left(z2 \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(-z0\right) - z1\right)}\right)\right)\right) \]
      10. sub-negate-revN/A

        \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 - \left(-z0\right)\right)}\right) \]
      11. lift-neg.f64N/A

        \[\leadsto \log \left(z2 \cdot \left(z1 - \color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right) \]
      12. add-flipN/A

        \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
      13. lift-+.f64N/A

        \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
      14. sum-logN/A

        \[\leadsto \color{blue}{\log z2 + \log \left(z1 + z0\right)} \]
      15. lift-log.f64N/A

        \[\leadsto \color{blue}{\log z2} + \log \left(z1 + z0\right) \]
      16. lift-log.f64N/A

        \[\leadsto \log z2 + \color{blue}{\log \left(z1 + z0\right)} \]
      17. +-commutativeN/A

        \[\leadsto \color{blue}{\log \left(z1 + z0\right) + \log z2} \]
      18. sum-to-multN/A

        \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
      19. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
      20. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right)} \cdot \log \left(z1 + z0\right) \]
      21. lower-unsound-/.f6449.3%

        \[\leadsto \left(1 + \color{blue}{\frac{\log z2}{\log \left(z1 + z0\right)}}\right) \cdot \log \left(z1 + z0\right) \]
    5. Applied rewrites49.3%

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
    6. Applied rewrites77.2%

      \[\leadsto \color{blue}{-\log \left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
    7. Step-by-step derivation
      1. lift-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\log \left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)\right)} \]
      2. lift-log.f64N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\log \left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)}\right) \]
      3. neg-logN/A

        \[\leadsto \color{blue}{\log \left(\frac{1}{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}\right)} \]
      4. lift-/.f64N/A

        \[\leadsto \log \left(\frac{1}{\color{blue}{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}\right) \]
      5. associate-/r/N/A

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{\frac{1}{2}}{z2}} \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)\right)} \]
      6. log-prodN/A

        \[\leadsto \color{blue}{\log \left(\frac{1}{\frac{\frac{1}{2}}{z2}}\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)} \]
      7. lift-/.f64N/A

        \[\leadsto \log \left(\frac{1}{\color{blue}{\frac{\frac{1}{2}}{z2}}}\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
      8. associate-/r/N/A

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{1}{2}} \cdot z2\right)} + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \log \left(\color{blue}{2} \cdot z2\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
      10. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(2 \cdot z2\right)} + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
      11. log-prodN/A

        \[\leadsto \color{blue}{\log \left(\left(2 \cdot z2\right) \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)\right)} \]
      12. sum-logN/A

        \[\leadsto \color{blue}{\log \left(2 \cdot z2\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)} \]
      13. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(2 \cdot z2\right)} + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
      14. lift-log.f64N/A

        \[\leadsto \log \left(2 \cdot z2\right) + \color{blue}{\log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)} \]
      15. lower-+.f6449.4%

        \[\leadsto \color{blue}{\log \left(2 \cdot z2\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)} \]
      16. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(2 \cdot z2\right)} + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
      17. count-2-revN/A

        \[\leadsto \log \color{blue}{\left(z2 + z2\right)} + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
      18. lower-+.f6449.4%

        \[\leadsto \log \color{blue}{\left(z2 + z2\right)} + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \]
    8. Applied rewrites49.4%

      \[\leadsto \color{blue}{\log \left(z2 + z2\right) + \log \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.1% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;z2 \leq \frac{-20240225330731}{101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392}:\\ \;\;\;\;\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(z1 + z0\right) + \log z2\\ \end{array} \]
(FPCore (z0 z1 z2)
  :precision binary64
  (if (<=
     z2
     -20240225330731/101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392)
  (+ (log (- (- z0) z1)) (log (- z2)))
  (+ (log (+ z1 z0)) (log z2))))
double code(double z0, double z1, double z2) {
	double tmp;
	if (z2 <= -2e-310) {
		tmp = log((-z0 - z1)) + log(-z2);
	} else {
		tmp = log((z1 + z0)) + log(z2);
	}
	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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    real(8) :: tmp
    if (z2 <= (-2d-310)) then
        tmp = log((-z0 - z1)) + log(-z2)
    else
        tmp = log((z1 + z0)) + log(z2)
    end if
    code = tmp
end function
public static double code(double z0, double z1, double z2) {
	double tmp;
	if (z2 <= -2e-310) {
		tmp = Math.log((-z0 - z1)) + Math.log(-z2);
	} else {
		tmp = Math.log((z1 + z0)) + Math.log(z2);
	}
	return tmp;
}
def code(z0, z1, z2):
	tmp = 0
	if z2 <= -2e-310:
		tmp = math.log((-z0 - z1)) + math.log(-z2)
	else:
		tmp = math.log((z1 + z0)) + math.log(z2)
	return tmp
function code(z0, z1, z2)
	tmp = 0.0
	if (z2 <= -2e-310)
		tmp = Float64(log(Float64(Float64(-z0) - z1)) + log(Float64(-z2)));
	else
		tmp = Float64(log(Float64(z1 + z0)) + log(z2));
	end
	return tmp
end
function tmp_2 = code(z0, z1, z2)
	tmp = 0.0;
	if (z2 <= -2e-310)
		tmp = log((-z0 - z1)) + log(-z2);
	else
		tmp = log((z1 + z0)) + log(z2);
	end
	tmp_2 = tmp;
end
code[z0_, z1_, z2_] := If[LessEqual[z2, -20240225330731/101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392], N[(N[Log[N[((-z0) - z1), $MachinePrecision]], $MachinePrecision] + N[Log[(-z2)], $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(z1 + z0), $MachinePrecision]], $MachinePrecision] + N[Log[z2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;z2 \leq \frac{-20240225330731}{101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392}:\\
\;\;\;\;\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(z1 + z0\right) + \log z2\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z2 < -1.9999999999999939e-310

    1. Initial program 76.2%

      \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
      3. lift-+.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(z0 + z1\right)} \cdot z2\right) \]
      4. add-flipN/A

        \[\leadsto \log \left(\color{blue}{\left(z0 - \left(\mathsf{neg}\left(z1\right)\right)\right)} \cdot z2\right) \]
      5. sub-negate-revN/A

        \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)\right)\right)} \cdot z2\right) \]
      6. distribute-lft-neg-outN/A

        \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot z2\right)\right)} \]
      7. distribute-rgt-neg-inN/A

        \[\leadsto \log \color{blue}{\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot \left(\mathsf{neg}\left(z2\right)\right)\right)} \]
      8. log-prodN/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      9. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      10. lower-unsound-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      11. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z1\right)\right) + \left(\mathsf{neg}\left(z0\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      12. +-commutativeN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) + \left(\mathsf{neg}\left(z1\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      13. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      14. lower--.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      15. lower-neg.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(-z0\right)} - z1\right) + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      16. lower-unsound-log.f64N/A

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \color{blue}{\log \left(\mathsf{neg}\left(z2\right)\right)} \]
      17. lower-neg.f6449.7%

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \log \color{blue}{\left(-z2\right)} \]
    3. Applied rewrites49.7%

      \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]

    if -1.9999999999999939e-310 < z2

    1. Initial program 76.2%

      \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
      3. log-prodN/A

        \[\leadsto \color{blue}{\log \left(z0 + z1\right) + \log z2} \]
      4. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\log \left(z0 + z1\right) + \log z2} \]
      5. lower-unsound-log.f64N/A

        \[\leadsto \color{blue}{\log \left(z0 + z1\right)} + \log z2 \]
      6. lift-+.f64N/A

        \[\leadsto \log \color{blue}{\left(z0 + z1\right)} + \log z2 \]
      7. +-commutativeN/A

        \[\leadsto \log \color{blue}{\left(z1 + z0\right)} + \log z2 \]
      8. lower-+.f64N/A

        \[\leadsto \log \color{blue}{\left(z1 + z0\right)} + \log z2 \]
      9. lower-unsound-log.f6449.4%

        \[\leadsto \log \left(z1 + z0\right) + \color{blue}{\log z2} \]
    3. Applied rewrites49.4%

      \[\leadsto \color{blue}{\log \left(z1 + z0\right) + \log z2} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 87.6% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;z0 + z1 \leq \frac{3366486976990959}{42081087212386988057927919063041029324402718422585390875986247224549857234376646576909332290220707609815863750849425741704155458001470430905022518165215046799641789369027556785533310063074581738170346013886251008}:\\ \;\;\;\;-\log \left(\frac{\frac{1}{z1 + z0}}{z2}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(z1 + z0\right) + \log z2\\ \end{array} \]
(FPCore (z0 z1 z2)
  :precision binary64
  (if (<=
     (+ z0 z1)
     3366486976990959/42081087212386988057927919063041029324402718422585390875986247224549857234376646576909332290220707609815863750849425741704155458001470430905022518165215046799641789369027556785533310063074581738170346013886251008)
  (- (log (/ (/ 1 (+ z1 z0)) z2)))
  (+ (log (+ z1 z0)) (log z2))))
double code(double z0, double z1, double z2) {
	double tmp;
	if ((z0 + z1) <= 8e-197) {
		tmp = -log(((1.0 / (z1 + z0)) / z2));
	} else {
		tmp = log((z1 + z0)) + log(z2);
	}
	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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    real(8) :: tmp
    if ((z0 + z1) <= 8d-197) then
        tmp = -log(((1.0d0 / (z1 + z0)) / z2))
    else
        tmp = log((z1 + z0)) + log(z2)
    end if
    code = tmp
end function
public static double code(double z0, double z1, double z2) {
	double tmp;
	if ((z0 + z1) <= 8e-197) {
		tmp = -Math.log(((1.0 / (z1 + z0)) / z2));
	} else {
		tmp = Math.log((z1 + z0)) + Math.log(z2);
	}
	return tmp;
}
def code(z0, z1, z2):
	tmp = 0
	if (z0 + z1) <= 8e-197:
		tmp = -math.log(((1.0 / (z1 + z0)) / z2))
	else:
		tmp = math.log((z1 + z0)) + math.log(z2)
	return tmp
function code(z0, z1, z2)
	tmp = 0.0
	if (Float64(z0 + z1) <= 8e-197)
		tmp = Float64(-log(Float64(Float64(1.0 / Float64(z1 + z0)) / z2)));
	else
		tmp = Float64(log(Float64(z1 + z0)) + log(z2));
	end
	return tmp
end
function tmp_2 = code(z0, z1, z2)
	tmp = 0.0;
	if ((z0 + z1) <= 8e-197)
		tmp = -log(((1.0 / (z1 + z0)) / z2));
	else
		tmp = log((z1 + z0)) + log(z2);
	end
	tmp_2 = tmp;
end
code[z0_, z1_, z2_] := If[LessEqual[N[(z0 + z1), $MachinePrecision], 3366486976990959/42081087212386988057927919063041029324402718422585390875986247224549857234376646576909332290220707609815863750849425741704155458001470430905022518165215046799641789369027556785533310063074581738170346013886251008], (-N[Log[N[(N[(1 / N[(z1 + z0), $MachinePrecision]), $MachinePrecision] / z2), $MachinePrecision]], $MachinePrecision]), N[(N[Log[N[(z1 + z0), $MachinePrecision]], $MachinePrecision] + N[Log[z2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;z0 + z1 \leq \frac{3366486976990959}{42081087212386988057927919063041029324402718422585390875986247224549857234376646576909332290220707609815863750849425741704155458001470430905022518165215046799641789369027556785533310063074581738170346013886251008}:\\
\;\;\;\;-\log \left(\frac{\frac{1}{z1 + z0}}{z2}\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(z1 + z0\right) + \log z2\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 z0 z1) < 7.9999999999999999e-197

    1. Initial program 76.2%

      \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
      3. lift-+.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(z0 + z1\right)} \cdot z2\right) \]
      4. add-flipN/A

        \[\leadsto \log \left(\color{blue}{\left(z0 - \left(\mathsf{neg}\left(z1\right)\right)\right)} \cdot z2\right) \]
      5. sub-negate-revN/A

        \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)\right)\right)} \cdot z2\right) \]
      6. distribute-lft-neg-outN/A

        \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot z2\right)\right)} \]
      7. distribute-rgt-neg-inN/A

        \[\leadsto \log \color{blue}{\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot \left(\mathsf{neg}\left(z2\right)\right)\right)} \]
      8. log-prodN/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      9. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
      10. lower-unsound-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      11. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z1\right)\right) + \left(\mathsf{neg}\left(z0\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      12. +-commutativeN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) + \left(\mathsf{neg}\left(z1\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      13. sub-flipN/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      14. lower--.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      15. lower-neg.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(-z0\right)} - z1\right) + \log \left(\mathsf{neg}\left(z2\right)\right) \]
      16. lower-unsound-log.f64N/A

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \color{blue}{\log \left(\mathsf{neg}\left(z2\right)\right)} \]
      17. lower-neg.f6449.7%

        \[\leadsto \log \left(\left(-z0\right) - z1\right) + \log \color{blue}{\left(-z2\right)} \]
    3. Applied rewrites49.7%

      \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
    4. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\log \left(-z2\right) + \log \left(\left(-z0\right) - z1\right)} \]
      3. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(-z2\right)} + \log \left(\left(-z0\right) - z1\right) \]
      4. lift-log.f64N/A

        \[\leadsto \log \left(-z2\right) + \color{blue}{\log \left(\left(-z0\right) - z1\right)} \]
      5. sum-logN/A

        \[\leadsto \color{blue}{\log \left(\left(-z2\right) \cdot \left(\left(-z0\right) - z1\right)\right)} \]
      6. lift-neg.f64N/A

        \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(z2\right)\right)} \cdot \left(\left(-z0\right) - z1\right)\right) \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(z2 \cdot \left(\left(-z0\right) - z1\right)\right)\right)} \]
      8. distribute-rgt-neg-outN/A

        \[\leadsto \log \color{blue}{\left(z2 \cdot \left(\mathsf{neg}\left(\left(\left(-z0\right) - z1\right)\right)\right)\right)} \]
      9. lift--.f64N/A

        \[\leadsto \log \left(z2 \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(-z0\right) - z1\right)}\right)\right)\right) \]
      10. sub-negate-revN/A

        \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 - \left(-z0\right)\right)}\right) \]
      11. lift-neg.f64N/A

        \[\leadsto \log \left(z2 \cdot \left(z1 - \color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right) \]
      12. add-flipN/A

        \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
      13. lift-+.f64N/A

        \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
      14. sum-logN/A

        \[\leadsto \color{blue}{\log z2 + \log \left(z1 + z0\right)} \]
      15. lift-log.f64N/A

        \[\leadsto \color{blue}{\log z2} + \log \left(z1 + z0\right) \]
      16. lift-log.f64N/A

        \[\leadsto \log z2 + \color{blue}{\log \left(z1 + z0\right)} \]
      17. +-commutativeN/A

        \[\leadsto \color{blue}{\log \left(z1 + z0\right) + \log z2} \]
      18. sum-to-multN/A

        \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
      19. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
      20. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right)} \cdot \log \left(z1 + z0\right) \]
      21. lower-unsound-/.f6449.3%

        \[\leadsto \left(1 + \color{blue}{\frac{\log z2}{\log \left(z1 + z0\right)}}\right) \cdot \log \left(z1 + z0\right) \]
    5. Applied rewrites49.3%

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
    6. Applied rewrites77.2%

      \[\leadsto \color{blue}{-\log \left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
    7. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto -\log \color{blue}{\left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
      2. lift-/.f64N/A

        \[\leadsto -\log \left(\frac{\color{blue}{\frac{\frac{1}{2}}{z2}}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right) \]
      3. associate-/l/N/A

        \[\leadsto -\log \color{blue}{\left(\frac{\frac{1}{2}}{z2 \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)}\right)} \]
      4. *-commutativeN/A

        \[\leadsto -\log \left(\frac{\frac{1}{2}}{\color{blue}{\left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \cdot z2}}\right) \]
      5. associate-/r*N/A

        \[\leadsto -\log \color{blue}{\left(\frac{\frac{\frac{1}{2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}{z2}\right)} \]
      6. lift-*.f64N/A

        \[\leadsto -\log \left(\frac{\frac{\frac{1}{2}}{\color{blue}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}{z2}\right) \]
      7. associate-/l/N/A

        \[\leadsto -\log \left(\frac{\color{blue}{\frac{\frac{\frac{1}{2}}{\frac{1}{2}}}{z1 + z0}}}{z2}\right) \]
      8. metadata-evalN/A

        \[\leadsto -\log \left(\frac{\frac{\color{blue}{1}}{z1 + z0}}{z2}\right) \]
      9. lower-/.f64N/A

        \[\leadsto -\log \color{blue}{\left(\frac{\frac{1}{z1 + z0}}{z2}\right)} \]
      10. lower-/.f6477.2%

        \[\leadsto -\log \left(\frac{\color{blue}{\frac{1}{z1 + z0}}}{z2}\right) \]
    8. Applied rewrites77.2%

      \[\leadsto -\log \color{blue}{\left(\frac{\frac{1}{z1 + z0}}{z2}\right)} \]

    if 7.9999999999999999e-197 < (+.f64 z0 z1)

    1. Initial program 76.2%

      \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
      3. log-prodN/A

        \[\leadsto \color{blue}{\log \left(z0 + z1\right) + \log z2} \]
      4. lower-unsound-+.f64N/A

        \[\leadsto \color{blue}{\log \left(z0 + z1\right) + \log z2} \]
      5. lower-unsound-log.f64N/A

        \[\leadsto \color{blue}{\log \left(z0 + z1\right)} + \log z2 \]
      6. lift-+.f64N/A

        \[\leadsto \log \color{blue}{\left(z0 + z1\right)} + \log z2 \]
      7. +-commutativeN/A

        \[\leadsto \log \color{blue}{\left(z1 + z0\right)} + \log z2 \]
      8. lower-+.f64N/A

        \[\leadsto \log \color{blue}{\left(z1 + z0\right)} + \log z2 \]
      9. lower-unsound-log.f6449.4%

        \[\leadsto \log \left(z1 + z0\right) + \color{blue}{\log z2} \]
    3. Applied rewrites49.4%

      \[\leadsto \color{blue}{\log \left(z1 + z0\right) + \log z2} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 77.2% accurate, 0.9× speedup?

\[-\log \left(\frac{\frac{1}{z1 + z0}}{z2}\right) \]
(FPCore (z0 z1 z2)
  :precision binary64
  (- (log (/ (/ 1 (+ z1 z0)) z2))))
double code(double z0, double z1, double z2) {
	return -log(((1.0 / (z1 + z0)) / z2));
}
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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    code = -log(((1.0d0 / (z1 + z0)) / z2))
end function
public static double code(double z0, double z1, double z2) {
	return -Math.log(((1.0 / (z1 + z0)) / z2));
}
def code(z0, z1, z2):
	return -math.log(((1.0 / (z1 + z0)) / z2))
function code(z0, z1, z2)
	return Float64(-log(Float64(Float64(1.0 / Float64(z1 + z0)) / z2)))
end
function tmp = code(z0, z1, z2)
	tmp = -log(((1.0 / (z1 + z0)) / z2));
end
code[z0_, z1_, z2_] := (-N[Log[N[(N[(1 / N[(z1 + z0), $MachinePrecision]), $MachinePrecision] / z2), $MachinePrecision]], $MachinePrecision])
-\log \left(\frac{\frac{1}{z1 + z0}}{z2}\right)
Derivation
  1. Initial program 76.2%

    \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
  2. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
    3. lift-+.f64N/A

      \[\leadsto \log \left(\color{blue}{\left(z0 + z1\right)} \cdot z2\right) \]
    4. add-flipN/A

      \[\leadsto \log \left(\color{blue}{\left(z0 - \left(\mathsf{neg}\left(z1\right)\right)\right)} \cdot z2\right) \]
    5. sub-negate-revN/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)\right)\right)} \cdot z2\right) \]
    6. distribute-lft-neg-outN/A

      \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot z2\right)\right)} \]
    7. distribute-rgt-neg-inN/A

      \[\leadsto \log \color{blue}{\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot \left(\mathsf{neg}\left(z2\right)\right)\right)} \]
    8. log-prodN/A

      \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
    9. lower-unsound-+.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
    10. lower-unsound-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    11. sub-flipN/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z1\right)\right) + \left(\mathsf{neg}\left(z0\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    12. +-commutativeN/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) + \left(\mathsf{neg}\left(z1\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    13. sub-flipN/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    14. lower--.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    15. lower-neg.f64N/A

      \[\leadsto \log \left(\color{blue}{\left(-z0\right)} - z1\right) + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    16. lower-unsound-log.f64N/A

      \[\leadsto \log \left(\left(-z0\right) - z1\right) + \color{blue}{\log \left(\mathsf{neg}\left(z2\right)\right)} \]
    17. lower-neg.f6449.7%

      \[\leadsto \log \left(\left(-z0\right) - z1\right) + \log \color{blue}{\left(-z2\right)} \]
  3. Applied rewrites49.7%

    \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
  4. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\log \left(-z2\right) + \log \left(\left(-z0\right) - z1\right)} \]
    3. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(-z2\right)} + \log \left(\left(-z0\right) - z1\right) \]
    4. lift-log.f64N/A

      \[\leadsto \log \left(-z2\right) + \color{blue}{\log \left(\left(-z0\right) - z1\right)} \]
    5. sum-logN/A

      \[\leadsto \color{blue}{\log \left(\left(-z2\right) \cdot \left(\left(-z0\right) - z1\right)\right)} \]
    6. lift-neg.f64N/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(z2\right)\right)} \cdot \left(\left(-z0\right) - z1\right)\right) \]
    7. distribute-lft-neg-outN/A

      \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(z2 \cdot \left(\left(-z0\right) - z1\right)\right)\right)} \]
    8. distribute-rgt-neg-outN/A

      \[\leadsto \log \color{blue}{\left(z2 \cdot \left(\mathsf{neg}\left(\left(\left(-z0\right) - z1\right)\right)\right)\right)} \]
    9. lift--.f64N/A

      \[\leadsto \log \left(z2 \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(-z0\right) - z1\right)}\right)\right)\right) \]
    10. sub-negate-revN/A

      \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 - \left(-z0\right)\right)}\right) \]
    11. lift-neg.f64N/A

      \[\leadsto \log \left(z2 \cdot \left(z1 - \color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right) \]
    12. add-flipN/A

      \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
    13. lift-+.f64N/A

      \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
    14. sum-logN/A

      \[\leadsto \color{blue}{\log z2 + \log \left(z1 + z0\right)} \]
    15. lift-log.f64N/A

      \[\leadsto \color{blue}{\log z2} + \log \left(z1 + z0\right) \]
    16. lift-log.f64N/A

      \[\leadsto \log z2 + \color{blue}{\log \left(z1 + z0\right)} \]
    17. +-commutativeN/A

      \[\leadsto \color{blue}{\log \left(z1 + z0\right) + \log z2} \]
    18. sum-to-multN/A

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
    19. lower-unsound-*.f64N/A

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
    20. lower-unsound-+.f64N/A

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right)} \cdot \log \left(z1 + z0\right) \]
    21. lower-unsound-/.f6449.3%

      \[\leadsto \left(1 + \color{blue}{\frac{\log z2}{\log \left(z1 + z0\right)}}\right) \cdot \log \left(z1 + z0\right) \]
  5. Applied rewrites49.3%

    \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
  6. Applied rewrites77.2%

    \[\leadsto \color{blue}{-\log \left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
  7. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto -\log \color{blue}{\left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto -\log \left(\frac{\color{blue}{\frac{\frac{1}{2}}{z2}}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right) \]
    3. associate-/l/N/A

      \[\leadsto -\log \color{blue}{\left(\frac{\frac{1}{2}}{z2 \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)}\right)} \]
    4. *-commutativeN/A

      \[\leadsto -\log \left(\frac{\frac{1}{2}}{\color{blue}{\left(\frac{1}{2} \cdot \left(z1 + z0\right)\right) \cdot z2}}\right) \]
    5. associate-/r*N/A

      \[\leadsto -\log \color{blue}{\left(\frac{\frac{\frac{1}{2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}{z2}\right)} \]
    6. lift-*.f64N/A

      \[\leadsto -\log \left(\frac{\frac{\frac{1}{2}}{\color{blue}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}{z2}\right) \]
    7. associate-/l/N/A

      \[\leadsto -\log \left(\frac{\color{blue}{\frac{\frac{\frac{1}{2}}{\frac{1}{2}}}{z1 + z0}}}{z2}\right) \]
    8. metadata-evalN/A

      \[\leadsto -\log \left(\frac{\frac{\color{blue}{1}}{z1 + z0}}{z2}\right) \]
    9. lower-/.f64N/A

      \[\leadsto -\log \color{blue}{\left(\frac{\frac{1}{z1 + z0}}{z2}\right)} \]
    10. lower-/.f6477.2%

      \[\leadsto -\log \left(\frac{\color{blue}{\frac{1}{z1 + z0}}}{z2}\right) \]
  8. Applied rewrites77.2%

    \[\leadsto -\log \color{blue}{\left(\frac{\frac{1}{z1 + z0}}{z2}\right)} \]
  9. Add Preprocessing

Alternative 5: 76.2% accurate, 0.9× speedup?

\[-\log \left(\frac{1}{\left(z1 + z0\right) \cdot z2}\right) \]
(FPCore (z0 z1 z2)
  :precision binary64
  (- (log (/ 1 (* (+ z1 z0) z2)))))
double code(double z0, double z1, double z2) {
	return -log((1.0 / ((z1 + z0) * z2)));
}
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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    code = -log((1.0d0 / ((z1 + z0) * z2)))
end function
public static double code(double z0, double z1, double z2) {
	return -Math.log((1.0 / ((z1 + z0) * z2)));
}
def code(z0, z1, z2):
	return -math.log((1.0 / ((z1 + z0) * z2)))
function code(z0, z1, z2)
	return Float64(-log(Float64(1.0 / Float64(Float64(z1 + z0) * z2))))
end
function tmp = code(z0, z1, z2)
	tmp = -log((1.0 / ((z1 + z0) * z2)));
end
code[z0_, z1_, z2_] := (-N[Log[N[(1 / N[(N[(z1 + z0), $MachinePrecision] * z2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])
-\log \left(\frac{1}{\left(z1 + z0\right) \cdot z2}\right)
Derivation
  1. Initial program 76.2%

    \[\log \left(\left(z0 + z1\right) \cdot z2\right) \]
  2. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(z0 + z1\right) \cdot z2\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(z0 + z1\right) \cdot z2\right)} \]
    3. lift-+.f64N/A

      \[\leadsto \log \left(\color{blue}{\left(z0 + z1\right)} \cdot z2\right) \]
    4. add-flipN/A

      \[\leadsto \log \left(\color{blue}{\left(z0 - \left(\mathsf{neg}\left(z1\right)\right)\right)} \cdot z2\right) \]
    5. sub-negate-revN/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)\right)\right)} \cdot z2\right) \]
    6. distribute-lft-neg-outN/A

      \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot z2\right)\right)} \]
    7. distribute-rgt-neg-inN/A

      \[\leadsto \log \color{blue}{\left(\left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) \cdot \left(\mathsf{neg}\left(z2\right)\right)\right)} \]
    8. log-prodN/A

      \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
    9. lower-unsound-+.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right) + \log \left(\mathsf{neg}\left(z2\right)\right)} \]
    10. lower-unsound-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(\mathsf{neg}\left(z1\right)\right) - z0\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    11. sub-flipN/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z1\right)\right) + \left(\mathsf{neg}\left(z0\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    12. +-commutativeN/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) + \left(\mathsf{neg}\left(z1\right)\right)\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    13. sub-flipN/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    14. lower--.f64N/A

      \[\leadsto \log \color{blue}{\left(\left(\mathsf{neg}\left(z0\right)\right) - z1\right)} + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    15. lower-neg.f64N/A

      \[\leadsto \log \left(\color{blue}{\left(-z0\right)} - z1\right) + \log \left(\mathsf{neg}\left(z2\right)\right) \]
    16. lower-unsound-log.f64N/A

      \[\leadsto \log \left(\left(-z0\right) - z1\right) + \color{blue}{\log \left(\mathsf{neg}\left(z2\right)\right)} \]
    17. lower-neg.f6449.7%

      \[\leadsto \log \left(\left(-z0\right) - z1\right) + \log \color{blue}{\left(-z2\right)} \]
  3. Applied rewrites49.7%

    \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
  4. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\log \left(\left(-z0\right) - z1\right) + \log \left(-z2\right)} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\log \left(-z2\right) + \log \left(\left(-z0\right) - z1\right)} \]
    3. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(-z2\right)} + \log \left(\left(-z0\right) - z1\right) \]
    4. lift-log.f64N/A

      \[\leadsto \log \left(-z2\right) + \color{blue}{\log \left(\left(-z0\right) - z1\right)} \]
    5. sum-logN/A

      \[\leadsto \color{blue}{\log \left(\left(-z2\right) \cdot \left(\left(-z0\right) - z1\right)\right)} \]
    6. lift-neg.f64N/A

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{neg}\left(z2\right)\right)} \cdot \left(\left(-z0\right) - z1\right)\right) \]
    7. distribute-lft-neg-outN/A

      \[\leadsto \log \color{blue}{\left(\mathsf{neg}\left(z2 \cdot \left(\left(-z0\right) - z1\right)\right)\right)} \]
    8. distribute-rgt-neg-outN/A

      \[\leadsto \log \color{blue}{\left(z2 \cdot \left(\mathsf{neg}\left(\left(\left(-z0\right) - z1\right)\right)\right)\right)} \]
    9. lift--.f64N/A

      \[\leadsto \log \left(z2 \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(-z0\right) - z1\right)}\right)\right)\right) \]
    10. sub-negate-revN/A

      \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 - \left(-z0\right)\right)}\right) \]
    11. lift-neg.f64N/A

      \[\leadsto \log \left(z2 \cdot \left(z1 - \color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right)\right) \]
    12. add-flipN/A

      \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
    13. lift-+.f64N/A

      \[\leadsto \log \left(z2 \cdot \color{blue}{\left(z1 + z0\right)}\right) \]
    14. sum-logN/A

      \[\leadsto \color{blue}{\log z2 + \log \left(z1 + z0\right)} \]
    15. lift-log.f64N/A

      \[\leadsto \color{blue}{\log z2} + \log \left(z1 + z0\right) \]
    16. lift-log.f64N/A

      \[\leadsto \log z2 + \color{blue}{\log \left(z1 + z0\right)} \]
    17. +-commutativeN/A

      \[\leadsto \color{blue}{\log \left(z1 + z0\right) + \log z2} \]
    18. sum-to-multN/A

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
    19. lower-unsound-*.f64N/A

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
    20. lower-unsound-+.f64N/A

      \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right)} \cdot \log \left(z1 + z0\right) \]
    21. lower-unsound-/.f6449.3%

      \[\leadsto \left(1 + \color{blue}{\frac{\log z2}{\log \left(z1 + z0\right)}}\right) \cdot \log \left(z1 + z0\right) \]
  5. Applied rewrites49.3%

    \[\leadsto \color{blue}{\left(1 + \frac{\log z2}{\log \left(z1 + z0\right)}\right) \cdot \log \left(z1 + z0\right)} \]
  6. Applied rewrites77.2%

    \[\leadsto \color{blue}{-\log \left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
  7. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto -\log \color{blue}{\left(\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
    2. mult-flipN/A

      \[\leadsto -\log \color{blue}{\left(\frac{\frac{1}{2}}{z2} \cdot \frac{1}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)} \]
    3. lift-/.f64N/A

      \[\leadsto -\log \left(\color{blue}{\frac{\frac{1}{2}}{z2}} \cdot \frac{1}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right) \]
    4. mult-flipN/A

      \[\leadsto -\log \left(\color{blue}{\left(\frac{1}{2} \cdot \frac{1}{z2}\right)} \cdot \frac{1}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right) \]
    5. associate-*l*N/A

      \[\leadsto -\log \color{blue}{\left(\frac{1}{2} \cdot \left(\frac{1}{z2} \cdot \frac{1}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)\right)} \]
    6. metadata-evalN/A

      \[\leadsto -\log \left(\color{blue}{{2}^{-1}} \cdot \left(\frac{1}{z2} \cdot \frac{1}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)\right) \]
    7. inv-powN/A

      \[\leadsto -\log \left({2}^{-1} \cdot \left(\color{blue}{{z2}^{-1}} \cdot \frac{1}{\frac{1}{2} \cdot \left(z1 + z0\right)}\right)\right) \]
    8. inv-powN/A

      \[\leadsto -\log \left({2}^{-1} \cdot \left({z2}^{-1} \cdot \color{blue}{{\left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)}^{-1}}\right)\right) \]
    9. pow-prod-downN/A

      \[\leadsto -\log \left({2}^{-1} \cdot \color{blue}{{\left(z2 \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)\right)}^{-1}}\right) \]
    10. pow-prod-downN/A

      \[\leadsto -\log \color{blue}{\left({\left(2 \cdot \left(z2 \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)\right)\right)}^{-1}\right)} \]
    11. metadata-evalN/A

      \[\leadsto -\log \left({\left(\color{blue}{\frac{1}{\frac{1}{2}}} \cdot \left(z2 \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)\right)\right)}^{-1}\right) \]
    12. associate-/r/N/A

      \[\leadsto -\log \left({\color{blue}{\left(\frac{1}{\frac{\frac{1}{2}}{z2 \cdot \left(\frac{1}{2} \cdot \left(z1 + z0\right)\right)}}\right)}}^{-1}\right) \]
    13. associate-/l/N/A

      \[\leadsto -\log \left({\left(\frac{1}{\color{blue}{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}\right)}^{-1}\right) \]
    14. lift-/.f64N/A

      \[\leadsto -\log \left({\left(\frac{1}{\frac{\color{blue}{\frac{\frac{1}{2}}{z2}}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}\right)}^{-1}\right) \]
    15. lift-/.f64N/A

      \[\leadsto -\log \left({\left(\frac{1}{\color{blue}{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}\right)}^{-1}\right) \]
    16. inv-powN/A

      \[\leadsto -\log \color{blue}{\left(\frac{1}{\frac{1}{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}\right)} \]
    17. lower-/.f64N/A

      \[\leadsto -\log \color{blue}{\left(\frac{1}{\frac{1}{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}\right)} \]
    18. lift-/.f64N/A

      \[\leadsto -\log \left(\frac{1}{\frac{1}{\color{blue}{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}}\right) \]
    19. lift-*.f64N/A

      \[\leadsto -\log \left(\frac{1}{\frac{1}{\frac{\frac{\frac{1}{2}}{z2}}{\color{blue}{\frac{1}{2} \cdot \left(z1 + z0\right)}}}}\right) \]
    20. associate-/r*N/A

      \[\leadsto -\log \left(\frac{1}{\frac{1}{\color{blue}{\frac{\frac{\frac{\frac{1}{2}}{z2}}{\frac{1}{2}}}{z1 + z0}}}}\right) \]
  8. Applied rewrites75.8%

    \[\leadsto -\log \color{blue}{\left(\frac{1}{\left(z1 + z0\right) \cdot z2}\right)} \]
  9. Add Preprocessing

Reproduce

?
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0 z1 z2)
  :name "(log (* (+ z0 z1) z2))"
  :precision binary64
  (log (* (+ z0 z1) z2)))