System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2

Percentage Accurate: 99.9% → 100.0%
Time: 4.0s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + log(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 * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z):
	return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z)
	return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z))))
end
function tmp = code(x, y, z)
	tmp = (x * 0.5) + (y * ((1.0 - z) + log(z)));
end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 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: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + log(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 * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z):
	return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z)
	return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z))))
end
function tmp = code(x, y, z)
	tmp = (x * 0.5) + (y * ((1.0 - z) + log(z)));
end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\end{array}

Alternative 1: 100.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \left(\mathsf{expm1}\left(-\log z\right) \cdot z\right) \cdot y\right) \end{array} \]
(FPCore (x y z)
 :precision binary64
 (+ (* x 0.5) (fma (log z) y (* (* (expm1 (- (log z))) z) y))))
double code(double x, double y, double z) {
	return (x * 0.5) + fma(log(z), y, ((expm1(-log(z)) * z) * y));
}
function code(x, y, z)
	return Float64(Float64(x * 0.5) + fma(log(z), y, Float64(Float64(expm1(Float64(-log(z))) * z) * y)))
end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(N[Log[z], $MachinePrecision] * y + N[(N[(N[(Exp[(-N[Log[z], $MachinePrecision])] - 1), $MachinePrecision] * z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \left(\mathsf{expm1}\left(-\log z\right) \cdot z\right) \cdot y\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

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

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

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \color{blue}{\left(1 - z\right) \cdot y}\right) \]
    10. lift--.f6499.9

      \[\leadsto x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \color{blue}{\left(1 - z\right)} \cdot y\right) \]
  4. Applied rewrites99.9%

    \[\leadsto x \cdot 0.5 + \color{blue}{\mathsf{fma}\left(\log z, y, \left(1 - z\right) \cdot y\right)} \]
  5. Taylor expanded in z around inf

    \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \color{blue}{\left(z \cdot \left(\frac{1}{z} - 1\right)\right)} \cdot y\right) \]
  6. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \left(\left(\frac{1}{z} - 1\right) \cdot \color{blue}{z}\right) \cdot y\right) \]
    3. inv-powN/A

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \left(\left({z}^{-1} - 1\right) \cdot z\right) \cdot y\right) \]
    4. pow-to-expN/A

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \left(\left(e^{\log z \cdot -1} - 1\right) \cdot z\right) \cdot y\right) \]
    5. *-commutativeN/A

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \left(\left(e^{-1 \cdot \log z} - 1\right) \cdot z\right) \cdot y\right) \]
    6. lower-expm1.f64N/A

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \left(\mathsf{expm1}\left(-1 \cdot \log z\right) \cdot z\right) \cdot y\right) \]
    7. mul-1-negN/A

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \left(\mathsf{expm1}\left(\mathsf{neg}\left(\log z\right)\right) \cdot z\right) \cdot y\right) \]
    8. lower-neg.f64N/A

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \left(\mathsf{expm1}\left(-\log z\right) \cdot z\right) \cdot y\right) \]
    9. lift-log.f64100.0

      \[\leadsto x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \left(\mathsf{expm1}\left(-\log z\right) \cdot z\right) \cdot y\right) \]
  7. Applied rewrites100.0%

    \[\leadsto x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \color{blue}{\left(\mathsf{expm1}\left(-\log z\right) \cdot z\right)} \cdot y\right) \]
  8. Add Preprocessing

Alternative 2: 61.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(\left(1 - z\right) + \log z\right)\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+95} \lor \neg \left(t\_0 \leq 2 \cdot 10^{+101}\right):\\ \;\;\;\;\left(-y\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (+ (- 1.0 z) (log z)))))
   (if (or (<= t_0 -5e+95) (not (<= t_0 2e+101))) (* (- y) z) (* 0.5 x))))
double code(double x, double y, double z) {
	double t_0 = y * ((1.0 - z) + log(z));
	double tmp;
	if ((t_0 <= -5e+95) || !(t_0 <= 2e+101)) {
		tmp = -y * z;
	} else {
		tmp = 0.5 * x;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = y * ((1.0d0 - z) + log(z))
    if ((t_0 <= (-5d+95)) .or. (.not. (t_0 <= 2d+101))) then
        tmp = -y * z
    else
        tmp = 0.5d0 * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * ((1.0 - z) + Math.log(z));
	double tmp;
	if ((t_0 <= -5e+95) || !(t_0 <= 2e+101)) {
		tmp = -y * z;
	} else {
		tmp = 0.5 * x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * ((1.0 - z) + math.log(z))
	tmp = 0
	if (t_0 <= -5e+95) or not (t_0 <= 2e+101):
		tmp = -y * z
	else:
		tmp = 0.5 * x
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(Float64(1.0 - z) + log(z)))
	tmp = 0.0
	if ((t_0 <= -5e+95) || !(t_0 <= 2e+101))
		tmp = Float64(Float64(-y) * z);
	else
		tmp = Float64(0.5 * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * ((1.0 - z) + log(z));
	tmp = 0.0;
	if ((t_0 <= -5e+95) || ~((t_0 <= 2e+101)))
		tmp = -y * z;
	else
		tmp = 0.5 * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5e+95], N[Not[LessEqual[t$95$0, 2e+101]], $MachinePrecision]], N[((-y) * z), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(\left(1 - z\right) + \log z\right)\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+95} \lor \neg \left(t\_0 \leq 2 \cdot 10^{+101}\right):\\
\;\;\;\;\left(-y\right) \cdot z\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) < -5.00000000000000025e95 or 2e101 < (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z)))

    1. Initial program 99.8%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    4. Step-by-step derivation
      1. associate-*r*N/A

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

        \[\leadsto \left(-1 \cdot y\right) \cdot \color{blue}{z} \]
      3. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(y\right)\right) \cdot z \]
      4. lower-neg.f6464.0

        \[\leadsto \left(-y\right) \cdot z \]
    5. Applied rewrites64.0%

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

    if -5.00000000000000025e95 < (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) < 2e101

    1. Initial program 99.9%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
    4. Step-by-step derivation
      1. lower-*.f6470.9

        \[\leadsto 0.5 \cdot \color{blue}{x} \]
    5. Applied rewrites70.9%

      \[\leadsto \color{blue}{0.5 \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification68.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(\left(1 - z\right) + \log z\right) \leq -5 \cdot 10^{+95} \lor \neg \left(y \cdot \left(\left(1 - z\right) + \log z\right) \leq 2 \cdot 10^{+101}\right):\\ \;\;\;\;\left(-y\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \left(1 - z\right) \cdot y\right) \end{array} \]
(FPCore (x y z)
 :precision binary64
 (+ (* x 0.5) (fma (log z) y (* (- 1.0 z) y))))
double code(double x, double y, double z) {
	return (x * 0.5) + fma(log(z), y, ((1.0 - z) * y));
}
function code(x, y, z)
	return Float64(Float64(x * 0.5) + fma(log(z), y, Float64(Float64(1.0 - z) * y)))
end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(N[Log[z], $MachinePrecision] * y + N[(N[(1.0 - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \left(1 - z\right) \cdot y\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

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

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

      \[\leadsto x \cdot \frac{1}{2} + \mathsf{fma}\left(\log z, y, \color{blue}{\left(1 - z\right) \cdot y}\right) \]
    10. lift--.f6499.9

      \[\leadsto x \cdot 0.5 + \mathsf{fma}\left(\log z, y, \color{blue}{\left(1 - z\right)} \cdot y\right) \]
  4. Applied rewrites99.9%

    \[\leadsto x \cdot 0.5 + \color{blue}{\mathsf{fma}\left(\log z, y, \left(1 - z\right) \cdot y\right)} \]
  5. Add Preprocessing

Alternative 4: 85.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -70000000 \lor \neg \left(y \leq 2.6 \cdot 10^{+92}\right):\\ \;\;\;\;\mathsf{fma}\left(\log z - z, y, y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5 + y \cdot \left(-z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -70000000.0) (not (<= y 2.6e+92)))
   (fma (- (log z) z) y y)
   (+ (* x 0.5) (* y (- z)))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -70000000.0) || !(y <= 2.6e+92)) {
		tmp = fma((log(z) - z), y, y);
	} else {
		tmp = (x * 0.5) + (y * -z);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((y <= -70000000.0) || !(y <= 2.6e+92))
		tmp = fma(Float64(log(z) - z), y, y);
	else
		tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(-z)));
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[y, -70000000.0], N[Not[LessEqual[y, 2.6e+92]], $MachinePrecision]], N[(N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] * y + y), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] + N[(y * (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -70000000 \lor \neg \left(y \leq 2.6 \cdot 10^{+92}\right):\\
\;\;\;\;\mathsf{fma}\left(\log z - z, y, y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7e7 or 2.5999999999999999e92 < y

    1. Initial program 99.8%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x \cdot \frac{1}{2} + \left(y + \left(\log z - \color{blue}{1 \cdot z}\right) \cdot y\right) \]
      13. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

        \[\leadsto x \cdot 0.5 + \left(y + \left(\color{blue}{\log z} - z\right) \cdot y\right) \]
    4. Applied rewrites99.8%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y + \left(\log z - z\right) \cdot y\right)} \]
    5. Taylor expanded in x around 0

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

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

        \[\leadsto \left(\log z - z\right) \cdot y + y \]
      3. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\log z - z, \color{blue}{y}, y\right) \]
      4. lift-log.f64N/A

        \[\leadsto \mathsf{fma}\left(\log z - z, y, y\right) \]
      5. lift--.f6489.4

        \[\leadsto \mathsf{fma}\left(\log z - z, y, y\right) \]
    7. Applied rewrites89.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log z - z, y, y\right)} \]

    if -7e7 < y < 2.5999999999999999e92

    1. Initial program 99.9%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

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

        \[\leadsto x \cdot \frac{1}{2} + y \cdot \left(\mathsf{neg}\left(z\right)\right) \]
      2. lower-neg.f6487.7

        \[\leadsto x \cdot 0.5 + y \cdot \left(-z\right) \]
    5. Applied rewrites87.7%

      \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(-z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -70000000 \lor \neg \left(y \leq 2.6 \cdot 10^{+92}\right):\\ \;\;\;\;\mathsf{fma}\left(\log z - z, y, y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5 + y \cdot \left(-z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.65 \cdot 10^{-188} \lor \neg \left(x \leq 4.4 \cdot 10^{-231}\right):\\ \;\;\;\;x \cdot 0.5 + y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -2.65e-188) (not (<= x 4.4e-231)))
   (+ (* x 0.5) (* y (- z)))
   (fma (log z) y y)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -2.65e-188) || !(x <= 4.4e-231)) {
		tmp = (x * 0.5) + (y * -z);
	} else {
		tmp = fma(log(z), y, y);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((x <= -2.65e-188) || !(x <= 4.4e-231))
		tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(-z)));
	else
		tmp = fma(log(z), y, y);
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.65e-188], N[Not[LessEqual[x, 4.4e-231]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] + N[(y * (-z)), $MachinePrecision]), $MachinePrecision], N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.65 \cdot 10^{-188} \lor \neg \left(x \leq 4.4 \cdot 10^{-231}\right):\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(-z\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.65000000000000007e-188 or 4.40000000000000018e-231 < x

    1. Initial program 99.9%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

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

        \[\leadsto x \cdot \frac{1}{2} + y \cdot \left(\mathsf{neg}\left(z\right)\right) \]
      2. lower-neg.f6483.8

        \[\leadsto x \cdot 0.5 + y \cdot \left(-z\right) \]
    5. Applied rewrites83.8%

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

    if -2.65000000000000007e-188 < x < 4.40000000000000018e-231

    1. Initial program 99.6%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x \cdot \frac{1}{2} + \left(y + \left(\log z - \color{blue}{1 \cdot z}\right) \cdot y\right) \]
      13. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

        \[\leadsto x \cdot 0.5 + \left(y + \left(\color{blue}{\log z} - z\right) \cdot y\right) \]
    4. Applied rewrites99.5%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y + \left(\log z - z\right) \cdot y\right)} \]
    5. Taylor expanded in z around 0

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

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

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

        \[\leadsto \left(y \cdot \log z + \frac{1}{2} \cdot x\right) + y \]
      4. *-commutativeN/A

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

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

        \[\leadsto \mathsf{fma}\left(\log z, y, \frac{1}{2} \cdot x\right) + y \]
      7. lift-*.f6468.0

        \[\leadsto \mathsf{fma}\left(\log z, y, 0.5 \cdot x\right) + y \]
    7. Applied rewrites68.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log z, y, 0.5 \cdot x\right) + y} \]
    8. Taylor expanded in x around 0

      \[\leadsto y + \color{blue}{y \cdot \log z} \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto y \cdot \log z + y \]
      2. *-commutativeN/A

        \[\leadsto \log z \cdot y + y \]
      3. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\log z, y, y\right) \]
      4. lift-log.f6464.9

        \[\leadsto \mathsf{fma}\left(\log z, y, y\right) \]
    10. Applied rewrites64.9%

      \[\leadsto \mathsf{fma}\left(\log z, \color{blue}{y}, y\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.65 \cdot 10^{-188} \lor \neg \left(x \leq 4.4 \cdot 10^{-231}\right):\\ \;\;\;\;x \cdot 0.5 + y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 98.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 0.62:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right) + y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z 0.62) (fma 0.5 x (fma (log z) y y)) (+ (fma (- z) y (* 0.5 x)) y)))
double code(double x, double y, double z) {
	double tmp;
	if (z <= 0.62) {
		tmp = fma(0.5, x, fma(log(z), y, y));
	} else {
		tmp = fma(-z, y, (0.5 * x)) + y;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= 0.62)
		tmp = fma(0.5, x, fma(log(z), y, y));
	else
		tmp = Float64(fma(Float64(-z), y, Float64(0.5 * x)) + y);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, 0.62], N[(0.5 * x + N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]), $MachinePrecision], N[(N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.62:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right) + y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 0.619999999999999996

    1. Initial program 99.8%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, x, y \cdot \left(\log z + 1\right)\right) \]
      3. distribute-rgt-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, x, \log z \cdot y + 1 \cdot y\right) \]
      4. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, x, \log z \cdot y + y\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, x, \mathsf{fma}\left(\log z, y, y\right)\right) \]
      6. lift-log.f6497.5

        \[\leadsto \mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right) \]
    5. Applied rewrites97.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)} \]

    if 0.619999999999999996 < z

    1. Initial program 100.0%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x \cdot \frac{1}{2} + \left(y + \left(\log z - \color{blue}{1 \cdot z}\right) \cdot y\right) \]
      13. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

        \[\leadsto x \cdot 0.5 + \left(y + \left(\color{blue}{\log z} - z\right) \cdot y\right) \]
    4. Applied rewrites100.0%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y + \left(\log z - z\right) \cdot y\right)} \]
    5. Taylor expanded in x around 0

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

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

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

        \[\leadsto \left(y \cdot \left(\log z - z\right) + \frac{1}{2} \cdot x\right) + y \]
      4. *-commutativeN/A

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

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

        \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x\right) + y \]
      7. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x\right) + y \]
      8. lift-*.f64100.0

        \[\leadsto \mathsf{fma}\left(\log z - z, y, 0.5 \cdot x\right) + y \]
    7. Applied rewrites100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log z - z, y, 0.5 \cdot x\right) + y} \]
    8. Taylor expanded in z around inf

      \[\leadsto \mathsf{fma}\left(-1 \cdot z, y, \frac{1}{2} \cdot x\right) + y \]
    9. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(z\right), y, \frac{1}{2} \cdot x\right) + y \]
      2. lower-neg.f6498.8

        \[\leadsto \mathsf{fma}\left(-z, y, 0.5 \cdot x\right) + y \]
    10. Applied rewrites98.8%

      \[\leadsto \mathsf{fma}\left(-z, y, 0.5 \cdot x\right) + y \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 0.62:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right) + y\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x, 0.5, \mathsf{fma}\left(\log z - z, y, y\right)\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma x 0.5 (fma (- (log z) z) y y)))
double code(double x, double y, double z) {
	return fma(x, 0.5, fma((log(z) - z), y, y));
}
function code(x, y, z)
	return fma(x, 0.5, fma(Float64(log(z) - z), y, y))
end
code[x_, y_, z_] := N[(x * 0.5 + N[(N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] * y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x, 0.5, \mathsf{fma}\left(\log z - z, y, y\right)\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x \cdot \frac{1}{2} + \left(y + \left(\log z - \color{blue}{1 \cdot z}\right) \cdot y\right) \]
    13. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

      \[\leadsto x \cdot 0.5 + \left(y + \left(\color{blue}{\log z} - z\right) \cdot y\right) \]
  4. Applied rewrites99.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{1}{2}, y + \left(\log z - z\right) \cdot y\right)} \]
    8. +-commutativeN/A

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

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

      \[\leadsto \mathsf{fma}\left(x, \frac{1}{2}, \mathsf{fma}\left(\color{blue}{\log z} - z, y, y\right)\right) \]
    11. lift--.f6499.9

      \[\leadsto \mathsf{fma}\left(x, 0.5, \mathsf{fma}\left(\color{blue}{\log z - z}, y, y\right)\right) \]
  6. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, \mathsf{fma}\left(\log z - z, y, y\right)\right)} \]
  7. Add Preprocessing

Alternative 8: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\log z - z, y, \mathsf{fma}\left(0.5, x, y\right)\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (- (log z) z) y (fma 0.5 x y)))
double code(double x, double y, double z) {
	return fma((log(z) - z), y, fma(0.5, x, y));
}
function code(x, y, z)
	return fma(Float64(log(z) - z), y, fma(0.5, x, y))
end
code[x_, y_, z_] := N[(N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] * y + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\log z - z, y, \mathsf{fma}\left(0.5, x, y\right)\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x \cdot \frac{1}{2} + \left(y + \left(\log z - \color{blue}{1 \cdot z}\right) \cdot y\right) \]
    13. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

      \[\leadsto x \cdot 0.5 + \left(y + \left(\color{blue}{\log z} - z\right) \cdot y\right) \]
  4. Applied rewrites99.9%

    \[\leadsto x \cdot 0.5 + \color{blue}{\left(y + \left(\log z - z\right) \cdot y\right)} \]
  5. Taylor expanded in x around 0

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

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

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

      \[\leadsto \left(y \cdot \left(\log z - z\right) + \frac{1}{2} \cdot x\right) + y \]
    4. *-commutativeN/A

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

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

      \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x\right) + y \]
    7. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x\right) + y \]
    8. lift-*.f6499.9

      \[\leadsto \mathsf{fma}\left(\log z - z, y, 0.5 \cdot x\right) + y \]
  7. Applied rewrites99.9%

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x + y\right) \]
    9. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x + y\right) \]
    10. lower-fma.f6499.9

      \[\leadsto \mathsf{fma}\left(\log z - z, y, \mathsf{fma}\left(0.5, x, y\right)\right) \]
  9. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\log z - z, y, \mathsf{fma}\left(0.5, x, y\right)\right)} \]
  10. Final simplification99.9%

    \[\leadsto \mathsf{fma}\left(\log z - z, y, \mathsf{fma}\left(0.5, x, y\right)\right) \]
  11. Add Preprocessing

Alternative 9: 75.2% accurate, 7.5× speedup?

\[\begin{array}{l} \\ x \cdot 0.5 + y \cdot \left(-z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
	return (x * 0.5) + (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 * 0.5d0) + (y * -z)
end function
public static double code(double x, double y, double z) {
	return (x * 0.5) + (y * -z);
}
def code(x, y, z):
	return (x * 0.5) + (y * -z)
function code(x, y, z)
	return Float64(Float64(x * 0.5) + Float64(y * Float64(-z)))
end
function tmp = code(x, y, z)
	tmp = (x * 0.5) + (y * -z);
end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * (-z)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.5 + y \cdot \left(-z\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in z around inf

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

      \[\leadsto x \cdot \frac{1}{2} + y \cdot \left(\mathsf{neg}\left(z\right)\right) \]
    2. lower-neg.f6477.9

      \[\leadsto x \cdot 0.5 + y \cdot \left(-z\right) \]
  5. Applied rewrites77.9%

    \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(-z\right)} \]
  6. Add Preprocessing

Alternative 10: 74.2% accurate, 8.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (- z) y (fma 0.5 x y)))
double code(double x, double y, double z) {
	return fma(-z, y, fma(0.5, x, y));
}
function code(x, y, z)
	return fma(Float64(-z), y, fma(0.5, x, y))
end
code[x_, y_, z_] := N[((-z) * y + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x \cdot \frac{1}{2} + \left(y + \left(\log z - \color{blue}{1 \cdot z}\right) \cdot y\right) \]
    13. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

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

      \[\leadsto x \cdot 0.5 + \left(y + \left(\color{blue}{\log z} - z\right) \cdot y\right) \]
  4. Applied rewrites99.9%

    \[\leadsto x \cdot 0.5 + \color{blue}{\left(y + \left(\log z - z\right) \cdot y\right)} \]
  5. Taylor expanded in x around 0

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

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

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

      \[\leadsto \left(y \cdot \left(\log z - z\right) + \frac{1}{2} \cdot x\right) + y \]
    4. *-commutativeN/A

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

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

      \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x\right) + y \]
    7. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\log z - z, y, \frac{1}{2} \cdot x\right) + y \]
    8. lift-*.f6499.9

      \[\leadsto \mathsf{fma}\left(\log z - z, y, 0.5 \cdot x\right) + y \]
  7. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\log z - z, y, 0.5 \cdot x\right) + y} \]
  8. Taylor expanded in z around inf

    \[\leadsto \mathsf{fma}\left(-1 \cdot z, y, \frac{1}{2} \cdot x\right) + y \]
  9. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(z\right), y, \frac{1}{2} \cdot x\right) + y \]
    2. lower-neg.f6476.8

      \[\leadsto \mathsf{fma}\left(-z, y, 0.5 \cdot x\right) + y \]
  10. Applied rewrites76.8%

    \[\leadsto \mathsf{fma}\left(-z, y, 0.5 \cdot x\right) + y \]
  11. Step-by-step derivation
    1. associate-+r+76.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)} + y \]
    2. *-commutative76.8

      \[\leadsto \mathsf{fma}\left(-\color{blue}{z}, y, 0.5 \cdot x\right) + y \]
    3. +-commutative76.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)} + y \]
    4. associate-+r+76.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)} + y \]
    5. lift-+.f64N/A

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

      \[\leadsto \mathsf{fma}\left(-z, y, \frac{1}{2} \cdot x\right) + y \]
    7. lift-fma.f64N/A

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

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

      \[\leadsto \mathsf{fma}\left(-z, \color{blue}{y}, \frac{1}{2} \cdot x + y\right) \]
    10. lift-fma.f6476.8

      \[\leadsto \mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right) \]
  12. Applied rewrites76.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right)} \]
  13. Add Preprocessing

Alternative 11: 40.2% accurate, 20.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot x \end{array} \]
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
	return 0.5 * x;
}
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 = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
	return 0.5 * x;
}
def code(x, y, z):
	return 0.5 * x
function code(x, y, z)
	return Float64(0.5 * x)
end
function tmp = code(x, y, z)
	tmp = 0.5 * x;
end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot x
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf

    \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
  4. Step-by-step derivation
    1. lower-*.f6445.6

      \[\leadsto 0.5 \cdot \color{blue}{x} \]
  5. Applied rewrites45.6%

    \[\leadsto \color{blue}{0.5 \cdot x} \]
  6. Final simplification45.6%

    \[\leadsto 0.5 \cdot x \]
  7. Add Preprocessing

Developer Target 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(y + 0.5 \cdot x\right) - y \cdot \left(z - \log z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ y (* 0.5 x)) (* y (- z (log z)))))
double code(double x, double y, double z) {
	return (y + (0.5 * x)) - (y * (z - log(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 = (y + (0.5d0 * x)) - (y * (z - log(z)))
end function
public static double code(double x, double y, double z) {
	return (y + (0.5 * x)) - (y * (z - Math.log(z)));
}
def code(x, y, z):
	return (y + (0.5 * x)) - (y * (z - math.log(z)))
function code(x, y, z)
	return Float64(Float64(y + Float64(0.5 * x)) - Float64(y * Float64(z - log(z))))
end
function tmp = code(x, y, z)
	tmp = (y + (0.5 * x)) - (y * (z - log(z)));
end
code[x_, y_, z_] := N[(N[(y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision] - N[(y * N[(z - N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(y + 0.5 \cdot x\right) - y \cdot \left(z - \log z\right)
\end{array}

Reproduce

?
herbie shell --seed 2025051 
(FPCore (x y z)
  :name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
  :precision binary64

  :alt
  (! :herbie-platform default (- (+ y (* 1/2 x)) (* y (- z (log z)))))

  (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))