Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2

Percentage Accurate: 77.5% → 99.5%
Time: 32.4s
Alternatives: 6
Speedup: 0.5×

Specification

?
\[x \cdot \log \left(\frac{x}{y}\right) - z \]
(FPCore (x y z)
  :precision binary64
  (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
	return (x * log((x / y))) - z;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * log((x / y))) - z
end function
public static double code(double x, double y, double z) {
	return (x * Math.log((x / y))) - z;
}
def code(x, y, z):
	return (x * math.log((x / y))) - z
function code(x, y, z)
	return Float64(Float64(x * log(Float64(x / y))) - z)
end
function tmp = code(x, y, z)
	tmp = (x * log((x / y))) - z;
end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
x \cdot \log \left(\frac{x}{y}\right) - z

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

\[x \cdot \log \left(\frac{x}{y}\right) - z \]
(FPCore (x y z)
  :precision binary64
  (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
	return (x * log((x / y))) - z;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * log((x / y))) - z
end function
public static double code(double x, double y, double z) {
	return (x * Math.log((x / y))) - z;
}
def code(x, y, z):
	return (x * math.log((x / y))) - z
function code(x, y, z)
	return Float64(Float64(x * log(Float64(x / y))) - z)
end
function tmp = code(x, y, z)
	tmp = (x * log((x / y))) - z;
end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
x \cdot \log \left(\frac{x}{y}\right) - z

Alternative 1: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \mathbf{if}\;y \leq \frac{-101201126653655}{202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784}:\\ \;\;\;\;x \cdot \left(\left(\log \left(-x\right) + \log \left(\frac{-1}{y} - \frac{1}{y}\right)\right) - \log 2\right) - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (if (<=
     y
     -101201126653655/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784)
  (- (* x (- (+ (log (- x)) (log (- (/ -1 y) (/ 1 y)))) (log 2))) z)
  (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e-310) {
		tmp = (x * ((log(-x) + log(((-1.0 / y) - (1.0 / y)))) - log(2.0))) - z;
	} else {
		tmp = (x * (log(x) - log(y))) - z;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-5d-310)) then
        tmp = (x * ((log(-x) + log((((-1.0d0) / y) - (1.0d0 / y)))) - log(2.0d0))) - z
    else
        tmp = (x * (log(x) - log(y))) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e-310) {
		tmp = (x * ((Math.log(-x) + Math.log(((-1.0 / y) - (1.0 / y)))) - Math.log(2.0))) - z;
	} else {
		tmp = (x * (Math.log(x) - Math.log(y))) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -5e-310:
		tmp = (x * ((math.log(-x) + math.log(((-1.0 / y) - (1.0 / y)))) - math.log(2.0))) - z
	else:
		tmp = (x * (math.log(x) - math.log(y))) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -5e-310)
		tmp = Float64(Float64(x * Float64(Float64(log(Float64(-x)) + log(Float64(Float64(-1.0 / y) - Float64(1.0 / y)))) - log(2.0))) - z);
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -5e-310)
		tmp = (x * ((log(-x) + log(((-1.0 / y) - (1.0 / y)))) - log(2.0))) - z;
	else
		tmp = (x * (log(x) - log(y))) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -101201126653655/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784], N[(N[(x * N[(N[(N[Log[(-x)], $MachinePrecision] + N[Log[N[(N[(-1 / y), $MachinePrecision] - N[(1 / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[Log[2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;y \leq \frac{-101201126653655}{202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784}:\\
\;\;\;\;x \cdot \left(\left(\log \left(-x\right) + \log \left(\frac{-1}{y} - \frac{1}{y}\right)\right) - \log 2\right) - z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\


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

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} - z \]
      2. remove-double-divN/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{1}{\frac{1}{\frac{x}{y}}}\right)} - z \]
      3. metadata-evalN/A

        \[\leadsto x \cdot \log \left(\frac{1}{\frac{\color{blue}{\frac{2}{2}}}{\frac{x}{y}}}\right) - z \]
      4. associate-/l/N/A

        \[\leadsto x \cdot \log \left(\frac{1}{\color{blue}{\frac{2}{2 \cdot \frac{x}{y}}}}\right) - z \]
      5. div-flip-revN/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{2 \cdot \frac{x}{y}}{2}\right)} - z \]
      6. log-divN/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(2 \cdot \frac{x}{y}\right) - \log 2\right)} - z \]
      7. lower-unsound--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(2 \cdot \frac{x}{y}\right) - \log 2\right)} - z \]
      8. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(2 \cdot \frac{x}{y}\right)} - \log 2\right) - z \]
      9. lift-/.f64N/A

        \[\leadsto x \cdot \left(\log \left(2 \cdot \color{blue}{\frac{x}{y}}\right) - \log 2\right) - z \]
      10. associate-*r/N/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{2 \cdot x}{y}\right)} - \log 2\right) - z \]
      11. lower-/.f64N/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{2 \cdot x}{y}\right)} - \log 2\right) - z \]
      12. count-2-revN/A

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{x + x}}{y}\right) - \log 2\right) - z \]
      13. lower-+.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{x + x}}{y}\right) - \log 2\right) - z \]
      14. lower-unsound-log.f6477.5%

        \[\leadsto x \cdot \left(\log \left(\frac{x + x}{y}\right) - \color{blue}{\log 2}\right) - z \]
    3. Applied rewrites77.5%

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{x + x}{y}\right) - \log 2\right)} - z \]
    4. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(\frac{x + x}{y}\right)} - \log 2\right) - z \]
      2. lift-/.f64N/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{x + x}{y}\right)} - \log 2\right) - z \]
      3. lift-+.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{x + x}}{y}\right) - \log 2\right) - z \]
      4. add-flipN/A

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{x - \left(\mathsf{neg}\left(x\right)\right)}}{y}\right) - \log 2\right) - z \]
      5. lift-neg.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{x - \color{blue}{\left(-x\right)}}{y}\right) - \log 2\right) - z \]
      6. div-subN/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{x}{y} - \frac{-x}{y}\right)} - \log 2\right) - z \]
      7. frac-2negN/A

        \[\leadsto x \cdot \left(\log \left(\color{blue}{\frac{\mathsf{neg}\left(x\right)}{\mathsf{neg}\left(y\right)}} - \frac{-x}{y}\right) - \log 2\right) - z \]
      8. lift-neg.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{-x}}{\mathsf{neg}\left(y\right)} - \frac{-x}{y}\right) - \log 2\right) - z \]
      9. mult-flipN/A

        \[\leadsto x \cdot \left(\log \left(\color{blue}{\left(-x\right) \cdot \frac{1}{\mathsf{neg}\left(y\right)}} - \frac{-x}{y}\right) - \log 2\right) - z \]
      10. mult-flip-revN/A

        \[\leadsto x \cdot \left(\log \left(\left(-x\right) \cdot \frac{1}{\mathsf{neg}\left(y\right)} - \color{blue}{\left(-x\right) \cdot \frac{1}{y}}\right) - \log 2\right) - z \]
      11. distribute-lft-out--N/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(\left(-x\right) \cdot \left(\frac{1}{\mathsf{neg}\left(y\right)} - \frac{1}{y}\right)\right)} - \log 2\right) - z \]
      12. log-prodN/A

        \[\leadsto x \cdot \left(\color{blue}{\left(\log \left(-x\right) + \log \left(\frac{1}{\mathsf{neg}\left(y\right)} - \frac{1}{y}\right)\right)} - \log 2\right) - z \]
      13. lower-unsound-+.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\left(\log \left(-x\right) + \log \left(\frac{1}{\mathsf{neg}\left(y\right)} - \frac{1}{y}\right)\right)} - \log 2\right) - z \]
      14. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\left(\color{blue}{\log \left(-x\right)} + \log \left(\frac{1}{\mathsf{neg}\left(y\right)} - \frac{1}{y}\right)\right) - \log 2\right) - z \]
      15. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\left(\log \left(-x\right) + \color{blue}{\log \left(\frac{1}{\mathsf{neg}\left(y\right)} - \frac{1}{y}\right)}\right) - \log 2\right) - z \]
      16. lower--.f64N/A

        \[\leadsto x \cdot \left(\left(\log \left(-x\right) + \log \color{blue}{\left(\frac{1}{\mathsf{neg}\left(y\right)} - \frac{1}{y}\right)}\right) - \log 2\right) - z \]
      17. metadata-evalN/A

        \[\leadsto x \cdot \left(\left(\log \left(-x\right) + \log \left(\frac{\color{blue}{\mathsf{neg}\left(-1\right)}}{\mathsf{neg}\left(y\right)} - \frac{1}{y}\right)\right) - \log 2\right) - z \]
      18. frac-2neg-revN/A

        \[\leadsto x \cdot \left(\left(\log \left(-x\right) + \log \left(\color{blue}{\frac{-1}{y}} - \frac{1}{y}\right)\right) - \log 2\right) - z \]
      19. lower-/.f64N/A

        \[\leadsto x \cdot \left(\left(\log \left(-x\right) + \log \left(\color{blue}{\frac{-1}{y}} - \frac{1}{y}\right)\right) - \log 2\right) - z \]
      20. lower-/.f6448.5%

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

      \[\leadsto x \cdot \left(\color{blue}{\left(\log \left(-x\right) + \log \left(\frac{-1}{y} - \frac{1}{y}\right)\right)} - \log 2\right) - z \]

    if -4.9999999999999847e-310 < y

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} - z \]
      2. lift-/.f64N/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{x}{y}\right)} - z \]
      3. log-divN/A

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      4. lower-unsound--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      5. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log x} - \log y\right) - z \]
      6. lower-unsound-log.f6450.9%

        \[\leadsto x \cdot \left(\log x - \color{blue}{\log y}\right) - z \]
    3. Applied rewrites50.9%

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.5% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;y \leq \frac{-101201126653655}{202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784}:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (if (<=
     y
     -101201126653655/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784)
  (- (* x (- (log (- x)) (log (- y)))) z)
  (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e-310) {
		tmp = (x * (log(-x) - log(-y))) - z;
	} else {
		tmp = (x * (log(x) - log(y))) - z;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-5d-310)) then
        tmp = (x * (log(-x) - log(-y))) - z
    else
        tmp = (x * (log(x) - log(y))) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e-310) {
		tmp = (x * (Math.log(-x) - Math.log(-y))) - z;
	} else {
		tmp = (x * (Math.log(x) - Math.log(y))) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -5e-310:
		tmp = (x * (math.log(-x) - math.log(-y))) - z
	else:
		tmp = (x * (math.log(x) - math.log(y))) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -5e-310)
		tmp = Float64(Float64(x * Float64(log(Float64(-x)) - log(Float64(-y)))) - z);
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -5e-310)
		tmp = (x * (log(-x) - log(-y))) - z;
	else
		tmp = (x * (log(x) - log(y))) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -101201126653655/202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784], N[(N[(x * N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;y \leq \frac{-101201126653655}{202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784}:\\
\;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\


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

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} - z \]
      2. remove-double-divN/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{1}{\frac{1}{\frac{x}{y}}}\right)} - z \]
      3. metadata-evalN/A

        \[\leadsto x \cdot \log \left(\frac{1}{\frac{\color{blue}{\frac{2}{2}}}{\frac{x}{y}}}\right) - z \]
      4. associate-/l/N/A

        \[\leadsto x \cdot \log \left(\frac{1}{\color{blue}{\frac{2}{2 \cdot \frac{x}{y}}}}\right) - z \]
      5. div-flip-revN/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{2 \cdot \frac{x}{y}}{2}\right)} - z \]
      6. log-divN/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(2 \cdot \frac{x}{y}\right) - \log 2\right)} - z \]
      7. lower-unsound--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(2 \cdot \frac{x}{y}\right) - \log 2\right)} - z \]
      8. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(2 \cdot \frac{x}{y}\right)} - \log 2\right) - z \]
      9. lift-/.f64N/A

        \[\leadsto x \cdot \left(\log \left(2 \cdot \color{blue}{\frac{x}{y}}\right) - \log 2\right) - z \]
      10. associate-*r/N/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{2 \cdot x}{y}\right)} - \log 2\right) - z \]
      11. lower-/.f64N/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{2 \cdot x}{y}\right)} - \log 2\right) - z \]
      12. count-2-revN/A

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{x + x}}{y}\right) - \log 2\right) - z \]
      13. lower-+.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{x + x}}{y}\right) - \log 2\right) - z \]
      14. lower-unsound-log.f6477.5%

        \[\leadsto x \cdot \left(\log \left(\frac{x + x}{y}\right) - \color{blue}{\log 2}\right) - z \]
    3. Applied rewrites77.5%

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{x + x}{y}\right) - \log 2\right)} - z \]
    4. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{x + x}{y}\right) - \log 2\right)} - z \]
      2. lift-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(\frac{x + x}{y}\right)} - \log 2\right) - z \]
      3. lift-log.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{x + x}{y}\right) - \color{blue}{\log 2}\right) - z \]
      4. diff-logN/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{\frac{x + x}{y}}{2}\right)} - z \]
      5. lift-/.f64N/A

        \[\leadsto x \cdot \log \left(\frac{\color{blue}{\frac{x + x}{y}}}{2}\right) - z \]
      6. lift-+.f64N/A

        \[\leadsto x \cdot \log \left(\frac{\frac{\color{blue}{x + x}}{y}}{2}\right) - z \]
      7. div-addN/A

        \[\leadsto x \cdot \log \left(\frac{\color{blue}{\frac{x}{y} + \frac{x}{y}}}{2}\right) - z \]
      8. common-denominatorN/A

        \[\leadsto x \cdot \log \left(\frac{\color{blue}{\frac{x \cdot y + x \cdot y}{y \cdot y}}}{2}\right) - z \]
      9. associate-/l/N/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{x \cdot y + x \cdot y}{\left(y \cdot y\right) \cdot 2}\right)} - z \]
      10. log-divN/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(x \cdot y + x \cdot y\right) - \log \left(\left(y \cdot y\right) \cdot 2\right)\right)} - z \]
      11. lower-unsound--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(x \cdot y + x \cdot y\right) - \log \left(\left(y \cdot y\right) \cdot 2\right)\right)} - z \]
      12. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(x \cdot y + x \cdot y\right)} - \log \left(\left(y \cdot y\right) \cdot 2\right)\right) - z \]
      13. distribute-rgt-outN/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(y \cdot \left(x + x\right)\right)} - \log \left(\left(y \cdot y\right) \cdot 2\right)\right) - z \]
      14. lift-+.f64N/A

        \[\leadsto x \cdot \left(\log \left(y \cdot \color{blue}{\left(x + x\right)}\right) - \log \left(\left(y \cdot y\right) \cdot 2\right)\right) - z \]
      15. lower-*.f64N/A

        \[\leadsto x \cdot \left(\log \color{blue}{\left(y \cdot \left(x + x\right)\right)} - \log \left(\left(y \cdot y\right) \cdot 2\right)\right) - z \]
      16. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\log \left(y \cdot \left(x + x\right)\right) - \color{blue}{\log \left(\left(y \cdot y\right) \cdot 2\right)}\right) - z \]
      17. lower-*.f64N/A

        \[\leadsto x \cdot \left(\log \left(y \cdot \left(x + x\right)\right) - \log \color{blue}{\left(\left(y \cdot y\right) \cdot 2\right)}\right) - z \]
      18. lower-*.f6446.3%

        \[\leadsto x \cdot \left(\log \left(y \cdot \left(x + x\right)\right) - \log \left(\color{blue}{\left(y \cdot y\right)} \cdot 2\right)\right) - z \]
    5. Applied rewrites46.3%

      \[\leadsto x \cdot \color{blue}{\left(\log \left(y \cdot \left(x + x\right)\right) - \log \left(\left(y \cdot y\right) \cdot 2\right)\right)} - z \]
    6. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(y \cdot \left(x + x\right)\right) - \log \left(\left(y \cdot y\right) \cdot 2\right)\right)} - z \]
      2. lift-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(y \cdot \left(x + x\right)\right)} - \log \left(\left(y \cdot y\right) \cdot 2\right)\right) - z \]
      3. lift-log.f64N/A

        \[\leadsto x \cdot \left(\log \left(y \cdot \left(x + x\right)\right) - \color{blue}{\log \left(\left(y \cdot y\right) \cdot 2\right)}\right) - z \]
      4. diff-logN/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{y \cdot \left(x + x\right)}{\left(y \cdot y\right) \cdot 2}\right)} - z \]
      5. lift-*.f64N/A

        \[\leadsto x \cdot \log \left(\frac{y \cdot \left(x + x\right)}{\color{blue}{\left(y \cdot y\right) \cdot 2}}\right) - z \]
      6. associate-/r*N/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{\frac{y \cdot \left(x + x\right)}{y \cdot y}}{2}\right)} - z \]
      7. lift-*.f64N/A

        \[\leadsto x \cdot \log \left(\frac{\frac{\color{blue}{y \cdot \left(x + x\right)}}{y \cdot y}}{2}\right) - z \]
      8. lift-+.f64N/A

        \[\leadsto x \cdot \log \left(\frac{\frac{y \cdot \color{blue}{\left(x + x\right)}}{y \cdot y}}{2}\right) - z \]
      9. distribute-rgt-inN/A

        \[\leadsto x \cdot \log \left(\frac{\frac{\color{blue}{x \cdot y + x \cdot y}}{y \cdot y}}{2}\right) - z \]
      10. lift-*.f64N/A

        \[\leadsto x \cdot \log \left(\frac{\frac{x \cdot y + x \cdot y}{\color{blue}{y \cdot y}}}{2}\right) - z \]
      11. common-denominatorN/A

        \[\leadsto x \cdot \log \left(\frac{\color{blue}{\frac{x}{y} + \frac{x}{y}}}{2}\right) - z \]
      12. div-addN/A

        \[\leadsto x \cdot \log \left(\frac{\color{blue}{\frac{x + x}{y}}}{2}\right) - z \]
      13. lift-+.f64N/A

        \[\leadsto x \cdot \log \left(\frac{\frac{\color{blue}{x + x}}{y}}{2}\right) - z \]
      14. lift-/.f64N/A

        \[\leadsto x \cdot \log \left(\frac{\color{blue}{\frac{x + x}{y}}}{2}\right) - z \]
      15. diff-logN/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{x + x}{y}\right) - \log 2\right)} - z \]
      16. lift-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(\frac{x + x}{y}\right)} - \log 2\right) - z \]
      17. lift-log.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{x + x}{y}\right) - \color{blue}{\log 2}\right) - z \]
      18. sub-flipN/A

        \[\leadsto x \cdot \color{blue}{\left(\log \left(\frac{x + x}{y}\right) + \left(\mathsf{neg}\left(\log 2\right)\right)\right)} - z \]
      19. lift-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log \left(\frac{x + x}{y}\right)} + \left(\mathsf{neg}\left(\log 2\right)\right)\right) - z \]
      20. lift-log.f64N/A

        \[\leadsto x \cdot \left(\log \left(\frac{x + x}{y}\right) + \left(\mathsf{neg}\left(\color{blue}{\log 2}\right)\right)\right) - z \]
      21. neg-logN/A

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

      \[\leadsto x \cdot \color{blue}{\left(\log \left(-x\right) - \log \left(-y\right)\right)} - z \]

    if -4.9999999999999847e-310 < y

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} - z \]
      2. lift-/.f64N/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{x}{y}\right)} - z \]
      3. log-divN/A

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      4. lower-unsound--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      5. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log x} - \log y\right) - z \]
      6. lower-unsound-log.f6450.9%

        \[\leadsto x \cdot \left(\log x - \color{blue}{\log y}\right) - z \]
    3. Applied rewrites50.9%

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 91.1% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;x \leq \frac{-6876220841419621}{11090678776483259438313656736572334813745748301503266300681918322458485231222502492159897624416558312389564843845614287315896631296}:\\ \;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right) - z\\ \mathbf{elif}\;x \leq \frac{2946648669762235}{2678771517965668302371062622650004526403512029263834018609375970925877627812340306232995947039239645318986682293882867062967863214230785108996144393674643700983641943706057746355268651265592785469488545538261618745895485316849691889791385986519265728642799119421635541915107457913156096709301417017344}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (if (<=
     x
     -6876220841419621/11090678776483259438313656736572334813745748301503266300681918322458485231222502492159897624416558312389564843845614287315896631296)
  (- (* (- x) (log (/ y x))) z)
  (if (<=
       x
       2946648669762235/2678771517965668302371062622650004526403512029263834018609375970925877627812340306232995947039239645318986682293882867062967863214230785108996144393674643700983641943706057746355268651265592785469488545538261618745895485316849691889791385986519265728642799119421635541915107457913156096709301417017344)
    (- z)
    (- (* x (- (log x) (log y))) z))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -6.2e-115) {
		tmp = (-x * log((y / x))) - z;
	} else if (x <= 1.1e-285) {
		tmp = -z;
	} else {
		tmp = (x * (log(x) - log(y))) - z;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-6.2d-115)) then
        tmp = (-x * log((y / x))) - z
    else if (x <= 1.1d-285) then
        tmp = -z
    else
        tmp = (x * (log(x) - log(y))) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -6.2e-115) {
		tmp = (-x * Math.log((y / x))) - z;
	} else if (x <= 1.1e-285) {
		tmp = -z;
	} else {
		tmp = (x * (Math.log(x) - Math.log(y))) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -6.2e-115:
		tmp = (-x * math.log((y / x))) - z
	elif x <= 1.1e-285:
		tmp = -z
	else:
		tmp = (x * (math.log(x) - math.log(y))) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -6.2e-115)
		tmp = Float64(Float64(Float64(-x) * log(Float64(y / x))) - z);
	elseif (x <= 1.1e-285)
		tmp = Float64(-z);
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -6.2e-115)
		tmp = (-x * log((y / x))) - z;
	elseif (x <= 1.1e-285)
		tmp = -z;
	else
		tmp = (x * (log(x) - log(y))) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -6876220841419621/11090678776483259438313656736572334813745748301503266300681918322458485231222502492159897624416558312389564843845614287315896631296], N[(N[((-x) * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[x, 2946648669762235/2678771517965668302371062622650004526403512029263834018609375970925877627812340306232995947039239645318986682293882867062967863214230785108996144393674643700983641943706057746355268651265592785469488545538261618745895485316849691889791385986519265728642799119421635541915107457913156096709301417017344], (-z), N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;x \leq \frac{-6876220841419621}{11090678776483259438313656736572334813745748301503266300681918322458485231222502492159897624416558312389564843845614287315896631296}:\\
\;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right) - z\\

\mathbf{elif}\;x \leq \frac{2946648669762235}{2678771517965668302371062622650004526403512029263834018609375970925877627812340306232995947039239645318986682293882867062967863214230785108996144393674643700983641943706057746355268651265592785469488545538261618745895485316849691889791385986519265728642799119421635541915107457913156096709301417017344}:\\
\;\;\;\;-z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.2000000000000001e-115

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. remove-double-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot \log \left(\frac{x}{y}\right)\right)\right)\right)\right)} - z \]
      2. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{x \cdot \log \left(\frac{x}{y}\right)}\right)\right)\right)\right) - z \]
      3. distribute-rgt-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{x \cdot \left(\mathsf{neg}\left(\log \left(\frac{x}{y}\right)\right)\right)}\right)\right) - z \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(\log \left(\frac{x}{y}\right)\right)\right)} - z \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(\log \left(\frac{x}{y}\right)\right)\right)} - z \]
      6. lower-neg.f64N/A

        \[\leadsto \color{blue}{\left(-x\right)} \cdot \left(\mathsf{neg}\left(\log \left(\frac{x}{y}\right)\right)\right) - z \]
      7. lift-log.f64N/A

        \[\leadsto \left(-x\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\log \left(\frac{x}{y}\right)}\right)\right) - z \]
      8. neg-logN/A

        \[\leadsto \left(-x\right) \cdot \color{blue}{\log \left(\frac{1}{\frac{x}{y}}\right)} - z \]
      9. lower-log.f64N/A

        \[\leadsto \left(-x\right) \cdot \color{blue}{\log \left(\frac{1}{\frac{x}{y}}\right)} - z \]
      10. lift-/.f64N/A

        \[\leadsto \left(-x\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{x}{y}}}\right) - z \]
      11. div-flip-revN/A

        \[\leadsto \left(-x\right) \cdot \log \color{blue}{\left(\frac{y}{x}\right)} - z \]
      12. lower-/.f6477.4%

        \[\leadsto \left(-x\right) \cdot \log \color{blue}{\left(\frac{y}{x}\right)} - z \]
    3. Applied rewrites77.4%

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

    if -6.2000000000000001e-115 < x < 1.1e-285

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. lower-*.f6450.6%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{z} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      3. lower-neg.f6450.6%

        \[\leadsto -z \]
    6. Applied rewrites50.6%

      \[\leadsto -z \]

    if 1.1e-285 < x

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} - z \]
      2. lift-/.f64N/A

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{x}{y}\right)} - z \]
      3. log-divN/A

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      4. lower-unsound--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
      5. lower-unsound-log.f64N/A

        \[\leadsto x \cdot \left(\color{blue}{\log x} - \log y\right) - z \]
      6. lower-unsound-log.f6450.9%

        \[\leadsto x \cdot \left(\log x - \color{blue}{\log y}\right) - z \]
    3. Applied rewrites50.9%

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 87.4% accurate, 0.3× speedup?

\[\begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;-z\\ \mathbf{elif}\;t\_0 \leq 199999999999999987850710501107292437200805744402346499063815431426464091260264678056866185148810154968737122361123243451574343874852720610604715976817337655499746028833640220821354205063248818116874396050971031981532793651016436653190982245392158996106920698373251448128152087616919197241498086962762874880:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (let* ((t_0 (- (* x (log (/ x y))) z)))
  (if (<= t_0 (- INFINITY))
    (- z)
    (if (<=
         t_0
         199999999999999987850710501107292437200805744402346499063815431426464091260264678056866185148810154968737122361123243451574343874852720610604715976817337655499746028833640220821354205063248818116874396050971031981532793651016436653190982245392158996106920698373251448128152087616919197241498086962762874880)
      t_0
      (- z)))))
double code(double x, double y, double z) {
	double t_0 = (x * log((x / y))) - z;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = -z;
	} else if (t_0 <= 2e+305) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double t_0 = (x * Math.log((x / y))) - z;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = -z;
	} else if (t_0 <= 2e+305) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x * math.log((x / y))) - z
	tmp = 0
	if t_0 <= -math.inf:
		tmp = -z
	elif t_0 <= 2e+305:
		tmp = t_0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x * log(Float64(x / y))) - z)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(-z);
	elseif (t_0 <= 2e+305)
		tmp = t_0;
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x * log((x / y))) - z;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = -z;
	elseif (t_0 <= 2e+305)
		tmp = t_0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], (-z), If[LessEqual[t$95$0, 199999999999999987850710501107292437200805744402346499063815431426464091260264678056866185148810154968737122361123243451574343874852720610604715976817337655499746028833640220821354205063248818116874396050971031981532793651016436653190982245392158996106920698373251448128152087616919197241498086962762874880], t$95$0, (-z)]]]
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right) - z\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;-z\\

\mathbf{elif}\;t\_0 \leq 199999999999999987850710501107292437200805744402346499063815431426464091260264678056866185148810154968737122361123243451574343874852720610604715976817337655499746028833640220821354205063248818116874396050971031981532793651016436653190982245392158996106920698373251448128152087616919197241498086962762874880:\\
\;\;\;\;t\_0\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) < -inf.0 or 1.9999999999999999e305 < (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z)

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. lower-*.f6450.6%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{z} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      3. lower-neg.f6450.6%

        \[\leadsto -z \]
    6. Applied rewrites50.6%

      \[\leadsto -z \]

    if -inf.0 < (-.f64 (*.f64 x (log.f64 (/.f64 x y))) z) < 1.9999999999999999e305

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 67.3% accurate, 0.9× speedup?

\[\begin{array}{l} \mathbf{if}\;z \leq \frac{-7350268983256945}{38685626227668133590597632}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq \frac{728143801304855}{6277101735386680763835789423207666416102355444464034512896}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
(FPCore (x y z)
  :precision binary64
  (if (<= z -7350268983256945/38685626227668133590597632)
  (- z)
  (if (<=
       z
       728143801304855/6277101735386680763835789423207666416102355444464034512896)
    (* x (log (/ x y)))
    (- z))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.9e-10) {
		tmp = -z;
	} else if (z <= 1.16e-43) {
		tmp = x * log((x / y));
	} else {
		tmp = -z;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-1.9d-10)) then
        tmp = -z
    else if (z <= 1.16d-43) then
        tmp = x * log((x / y))
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.9e-10) {
		tmp = -z;
	} else if (z <= 1.16e-43) {
		tmp = x * Math.log((x / y));
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.9e-10:
		tmp = -z
	elif z <= 1.16e-43:
		tmp = x * math.log((x / y))
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.9e-10)
		tmp = Float64(-z);
	elseif (z <= 1.16e-43)
		tmp = Float64(x * log(Float64(x / y)));
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.9e-10)
		tmp = -z;
	elseif (z <= 1.16e-43)
		tmp = x * log((x / y));
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -7350268983256945/38685626227668133590597632], (-z), If[LessEqual[z, 728143801304855/6277101735386680763835789423207666416102355444464034512896], N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], (-z)]]
\begin{array}{l}
\mathbf{if}\;z \leq \frac{-7350268983256945}{38685626227668133590597632}:\\
\;\;\;\;-z\\

\mathbf{elif}\;z \leq \frac{728143801304855}{6277101735386680763835789423207666416102355444464034512896}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.8999999999999999e-10 or 1.1600000000000001e-43 < z

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. lower-*.f6450.6%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{z} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      3. lower-neg.f6450.6%

        \[\leadsto -z \]
    6. Applied rewrites50.6%

      \[\leadsto -z \]

    if -1.8999999999999999e-10 < z < 1.1600000000000001e-43

    1. Initial program 77.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{x \cdot \log \left(\frac{x}{y}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto x \cdot \color{blue}{\log \left(\frac{x}{y}\right)} \]
      2. lower-log.f64N/A

        \[\leadsto x \cdot \log \left(\frac{x}{y}\right) \]
      3. lower-/.f6439.4%

        \[\leadsto x \cdot \log \left(\frac{x}{y}\right) \]
    4. Applied rewrites39.4%

      \[\leadsto \color{blue}{x \cdot \log \left(\frac{x}{y}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 50.6% accurate, 40.0× speedup?

\[-z \]
(FPCore (x y z)
  :precision binary64
  (- z))
double code(double x, double y, double z) {
	return -z;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = -z
end function
public static double code(double x, double y, double z) {
	return -z;
}
def code(x, y, z):
	return -z
function code(x, y, z)
	return Float64(-z)
end
function tmp = code(x, y, z)
	tmp = -z;
end
code[x_, y_, z_] := (-z)
-z
Derivation
  1. Initial program 77.5%

    \[x \cdot \log \left(\frac{x}{y}\right) - z \]
  2. Taylor expanded in x around 0

    \[\leadsto \color{blue}{-1 \cdot z} \]
  3. Step-by-step derivation
    1. lower-*.f6450.6%

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

    \[\leadsto \color{blue}{-1 \cdot z} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto -1 \cdot \color{blue}{z} \]
    2. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(z\right) \]
    3. lower-neg.f6450.6%

      \[\leadsto -z \]
  6. Applied rewrites50.6%

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

Reproduce

?
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y z)
  :name "Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2"
  :precision binary64
  (- (* x (log (/ x y))) z))