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

Percentage Accurate: 99.9% → 99.7%
Time: 12.8s
Alternatives: 12
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)));
}
real(8) function code(x, y, z)
    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 12 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)));
}
real(8) function code(x, y, z)
    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: 99.7% accurate, 1.0× speedup?

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

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

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Step-by-step derivation
    1. +-commutative99.9%

      \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
    2. fma-def99.9%

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

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

      \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
    2. +-commutative99.9%

      \[\leadsto \color{blue}{x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)} \]
    3. distribute-lft-in99.9%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
    4. associate-+r+99.9%

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

    \[\leadsto \color{blue}{\left(x \cdot 0.5 + y \cdot \left(1 - z\right)\right) + y \cdot \log z} \]
  6. Final simplification99.9%

    \[\leadsto \left(x \cdot 0.5 + y \cdot \left(1 - z\right)\right) + y \cdot \log z \]

Alternative 2: 85.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-49} \lor \neg \left(x \cdot 0.5 \leq 10^{-24}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x 1/2) < -4.9999999999999999e-49 or 9.99999999999999924e-25 < (*.f64 x 1/2)

    1. Initial program 99.9%

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

      \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. associate-*r*88.6%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
      2. neg-mul-188.6%

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

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

    if -4.9999999999999999e-49 < (*.f64 x 1/2) < 9.99999999999999924e-25

    1. Initial program 99.8%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
      2. fma-def99.8%

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

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

        \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
      2. +-commutative99.8%

        \[\leadsto \color{blue}{x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)} \]
      3. distribute-lft-in99.8%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
      4. associate-+r+99.8%

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

      \[\leadsto \color{blue}{\left(x \cdot 0.5 + y \cdot \left(1 - z\right)\right) + y \cdot \log z} \]
    6. Taylor expanded in y around inf 95.2%

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

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

Alternative 3: 85.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-49} \lor \neg \left(x \cdot 0.5 \leq 10^{-24}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x 1/2) < -4.9999999999999999e-49 or 9.99999999999999924e-25 < (*.f64 x 1/2)

    1. Initial program 99.9%

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

      \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. associate-*r*88.6%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
      2. neg-mul-188.6%

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

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

    if -4.9999999999999999e-49 < (*.f64 x 1/2) < 9.99999999999999924e-25

    1. Initial program 99.8%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. sub-neg99.8%

        \[\leadsto x \cdot 0.5 + y \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} + \log z\right) \]
      2. associate-+l+99.8%

        \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(1 + \left(\left(-z\right) + \log z\right)\right)} \]
      3. distribute-rgt-in99.8%

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

        \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + \left(\left(-z\right) + \log z\right) \cdot y\right) \]
      5. associate-+r+99.8%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) + \left(\left(-z\right) + \log z\right) \cdot y} \]
      6. neg-sub099.8%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \left(\color{blue}{\left(0 - z\right)} + \log z\right) \cdot y \]
      7. associate-+l-99.8%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(0 - \left(z - \log z\right)\right)} \cdot y \]
      8. neg-sub099.8%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right)\right)} \cdot y \]
      9. distribute-lft-neg-out99.8%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right) \cdot y\right)} \]
      10. unsub-neg99.8%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) - \left(z - \log z\right) \cdot y} \]
      11. fma-def99.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right)} - \left(z - \log z\right) \cdot y \]
      12. *-commutative99.8%

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

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

      \[\leadsto \color{blue}{y - y \cdot \left(z - \log z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-49} \lor \neg \left(x \cdot 0.5 \leq 10^{-24}\right):\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y + y \cdot \left(\log z - z\right)\\ \end{array} \]

Alternative 4: 98.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.15 \cdot 10^{-5}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(\log z + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 1.15e-5

    1. Initial program 99.8%

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

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

    if 1.15e-5 < z

    1. Initial program 100.0%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
      2. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(1 - z\right) + \log z, x \cdot 0.5\right)} \]
    3. Simplified100.0%

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

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{-1 \cdot z}, x \cdot 0.5\right) \]
    5. Step-by-step derivation
      1. mul-1-neg98.9%

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

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

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

Alternative 5: 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)));
}
real(8) function code(x, y, z)
    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}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Final simplification99.9%

    \[\leadsto x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]

Alternative 6: 74.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 7.5 \cdot 10^{-201}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\

\mathbf{elif}\;z \leq 5.2 \cdot 10^{-10}:\\
\;\;\;\;y \cdot \left(\log z + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < 7.49999999999999987e-201

    1. Initial program 99.8%

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

      \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. associate-*r*58.5%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
      2. neg-mul-158.5%

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

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

    if 7.49999999999999987e-201 < z < 5.19999999999999962e-10

    1. Initial program 99.7%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. sub-neg99.7%

        \[\leadsto x \cdot 0.5 + y \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} + \log z\right) \]
      2. associate-+l+99.7%

        \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(1 + \left(\left(-z\right) + \log z\right)\right)} \]
      3. distribute-rgt-in99.7%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(1 \cdot y + \left(\left(-z\right) + \log z\right) \cdot y\right)} \]
      4. *-lft-identity99.7%

        \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + \left(\left(-z\right) + \log z\right) \cdot y\right) \]
      5. associate-+r+99.7%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) + \left(\left(-z\right) + \log z\right) \cdot y} \]
      6. neg-sub099.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \left(\color{blue}{\left(0 - z\right)} + \log z\right) \cdot y \]
      7. associate-+l-99.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(0 - \left(z - \log z\right)\right)} \cdot y \]
      8. neg-sub099.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right)\right)} \cdot y \]
      9. distribute-lft-neg-out99.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right) \cdot y\right)} \]
      10. unsub-neg99.7%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) - \left(z - \log z\right) \cdot y} \]
      11. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right)} - \left(z - \log z\right) \cdot y \]
      12. *-commutative99.7%

        \[\leadsto \mathsf{fma}\left(x, 0.5, y\right) - \color{blue}{y \cdot \left(z - \log z\right)} \]
    3. Simplified99.7%

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

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

      \[\leadsto \color{blue}{y - -1 \cdot \left(y \cdot \log z\right)} \]
    6. Step-by-step derivation
      1. associate-*r*60.8%

        \[\leadsto y - \color{blue}{\left(-1 \cdot y\right) \cdot \log z} \]
      2. neg-mul-160.8%

        \[\leadsto y - \color{blue}{\left(-y\right)} \cdot \log z \]
      3. cancel-sign-sub60.8%

        \[\leadsto \color{blue}{y + y \cdot \log z} \]
    7. Simplified60.8%

      \[\leadsto \color{blue}{y + y \cdot \log z} \]
    8. Step-by-step derivation
      1. *-un-lft-identity60.8%

        \[\leadsto \color{blue}{1 \cdot y} + y \cdot \log z \]
      2. *-commutative60.8%

        \[\leadsto 1 \cdot y + \color{blue}{\log z \cdot y} \]
      3. distribute-rgt-in60.8%

        \[\leadsto \color{blue}{y \cdot \left(1 + \log z\right)} \]
      4. *-commutative60.8%

        \[\leadsto \color{blue}{\left(1 + \log z\right) \cdot y} \]
    9. Applied egg-rr60.8%

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

    if 5.19999999999999962e-10 < z

    1. Initial program 100.0%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
      2. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(1 - z\right) + \log z, x \cdot 0.5\right)} \]
    3. Simplified100.0%

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

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{-1 \cdot z}, x \cdot 0.5\right) \]
    5. Step-by-step derivation
      1. mul-1-neg98.9%

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

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{-z}, x \cdot 0.5\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification79.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 7.5 \cdot 10^{-201}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{-10}:\\ \;\;\;\;y \cdot \left(\log z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\ \end{array} \]

Alternative 7: 74.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 4.6 \cdot 10^{-201} \lor \neg \left(z \leq 2.3 \cdot 10^{-9}\right):\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(\log z + 1\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z 4.6e-201) (not (<= z 2.3e-9)))
   (- (* x 0.5) (* y z))
   (* y (+ (log z) 1.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= 4.6e-201) || !(z <= 2.3e-9)) {
		tmp = (x * 0.5) - (y * z);
	} else {
		tmp = y * (log(z) + 1.0);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= 4.6d-201) .or. (.not. (z <= 2.3d-9))) then
        tmp = (x * 0.5d0) - (y * z)
    else
        tmp = y * (log(z) + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= 4.6e-201) || !(z <= 2.3e-9)) {
		tmp = (x * 0.5) - (y * z);
	} else {
		tmp = y * (Math.log(z) + 1.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= 4.6e-201) or not (z <= 2.3e-9):
		tmp = (x * 0.5) - (y * z)
	else:
		tmp = y * (math.log(z) + 1.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= 4.6e-201) || !(z <= 2.3e-9))
		tmp = Float64(Float64(x * 0.5) - Float64(y * z));
	else
		tmp = Float64(y * Float64(log(z) + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= 4.6e-201) || ~((z <= 2.3e-9)))
		tmp = (x * 0.5) - (y * z);
	else
		tmp = y * (log(z) + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, 4.6e-201], N[Not[LessEqual[z, 2.3e-9]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[Log[z], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.6 \cdot 10^{-201} \lor \neg \left(z \leq 2.3 \cdot 10^{-9}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(\log z + 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 4.59999999999999971e-201 or 2.2999999999999999e-9 < z

    1. Initial program 99.9%

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

      \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    3. Step-by-step derivation
      1. associate-*r*87.5%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
      2. neg-mul-187.5%

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

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

    if 4.59999999999999971e-201 < z < 2.2999999999999999e-9

    1. Initial program 99.7%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. sub-neg99.7%

        \[\leadsto x \cdot 0.5 + y \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} + \log z\right) \]
      2. associate-+l+99.7%

        \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(1 + \left(\left(-z\right) + \log z\right)\right)} \]
      3. distribute-rgt-in99.7%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(1 \cdot y + \left(\left(-z\right) + \log z\right) \cdot y\right)} \]
      4. *-lft-identity99.7%

        \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + \left(\left(-z\right) + \log z\right) \cdot y\right) \]
      5. associate-+r+99.7%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) + \left(\left(-z\right) + \log z\right) \cdot y} \]
      6. neg-sub099.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \left(\color{blue}{\left(0 - z\right)} + \log z\right) \cdot y \]
      7. associate-+l-99.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(0 - \left(z - \log z\right)\right)} \cdot y \]
      8. neg-sub099.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right)\right)} \cdot y \]
      9. distribute-lft-neg-out99.7%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right) \cdot y\right)} \]
      10. unsub-neg99.7%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) - \left(z - \log z\right) \cdot y} \]
      11. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right)} - \left(z - \log z\right) \cdot y \]
      12. *-commutative99.7%

        \[\leadsto \mathsf{fma}\left(x, 0.5, y\right) - \color{blue}{y \cdot \left(z - \log z\right)} \]
    3. Simplified99.7%

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

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

      \[\leadsto \color{blue}{y - -1 \cdot \left(y \cdot \log z\right)} \]
    6. Step-by-step derivation
      1. associate-*r*60.8%

        \[\leadsto y - \color{blue}{\left(-1 \cdot y\right) \cdot \log z} \]
      2. neg-mul-160.8%

        \[\leadsto y - \color{blue}{\left(-y\right)} \cdot \log z \]
      3. cancel-sign-sub60.8%

        \[\leadsto \color{blue}{y + y \cdot \log z} \]
    7. Simplified60.8%

      \[\leadsto \color{blue}{y + y \cdot \log z} \]
    8. Step-by-step derivation
      1. *-un-lft-identity60.8%

        \[\leadsto \color{blue}{1 \cdot y} + y \cdot \log z \]
      2. *-commutative60.8%

        \[\leadsto 1 \cdot y + \color{blue}{\log z \cdot y} \]
      3. distribute-rgt-in60.8%

        \[\leadsto \color{blue}{y \cdot \left(1 + \log z\right)} \]
      4. *-commutative60.8%

        \[\leadsto \color{blue}{\left(1 + \log z\right) \cdot y} \]
    9. Applied egg-rr60.8%

      \[\leadsto \color{blue}{\left(1 + \log z\right) \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 4.6 \cdot 10^{-201} \lor \neg \left(z \leq 2.3 \cdot 10^{-9}\right):\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(\log z + 1\right)\\ \end{array} \]

Alternative 8: 60.4% accurate, 15.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 430000:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z 430000.0) (* x 0.5) (- y (* y z))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= 430000.0) {
		tmp = x * 0.5;
	} else {
		tmp = y - (y * z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= 430000.0d0) then
        tmp = x * 0.5d0
    else
        tmp = y - (y * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= 430000.0) {
		tmp = x * 0.5;
	} else {
		tmp = y - (y * z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= 430000.0:
		tmp = x * 0.5
	else:
		tmp = y - (y * z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= 430000.0)
		tmp = Float64(x * 0.5);
	else
		tmp = Float64(y - Float64(y * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= 430000.0)
		tmp = x * 0.5;
	else
		tmp = y - (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, 430000.0], N[(x * 0.5), $MachinePrecision], N[(y - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 430000:\\
\;\;\;\;x \cdot 0.5\\

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


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

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{0.5 \cdot x} \]

    if 4.3e5 < z

    1. Initial program 100.0%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. sub-neg100.0%

        \[\leadsto x \cdot 0.5 + y \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} + \log z\right) \]
      2. associate-+l+100.0%

        \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(1 + \left(\left(-z\right) + \log z\right)\right)} \]
      3. distribute-rgt-in100.0%

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

        \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + \left(\left(-z\right) + \log z\right) \cdot y\right) \]
      5. associate-+r+100.0%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) + \left(\left(-z\right) + \log z\right) \cdot y} \]
      6. neg-sub0100.0%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \left(\color{blue}{\left(0 - z\right)} + \log z\right) \cdot y \]
      7. associate-+l-100.0%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(0 - \left(z - \log z\right)\right)} \cdot y \]
      8. neg-sub0100.0%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right)\right)} \cdot y \]
      9. distribute-lft-neg-out100.0%

        \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right) \cdot y\right)} \]
      10. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) - \left(z - \log z\right) \cdot y} \]
      11. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right)} - \left(z - \log z\right) \cdot y \]
      12. *-commutative100.0%

        \[\leadsto \mathsf{fma}\left(x, 0.5, y\right) - \color{blue}{y \cdot \left(z - \log z\right)} \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{y - y \cdot \left(z - \log z\right)} \]
    5. Taylor expanded in z around inf 79.4%

      \[\leadsto y - \color{blue}{y \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 430000:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot z\\ \end{array} \]

Alternative 9: 74.8% accurate, 15.9× speedup?

\[\begin{array}{l} \\ x \cdot 0.5 - y \cdot z \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);
}
real(8) function code(x, y, z)
    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 * 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 z
\end{array}
Derivation
  1. Initial program 99.9%

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

    \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
  3. Step-by-step derivation
    1. associate-*r*74.4%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
    2. neg-mul-174.4%

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

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

    \[\leadsto x \cdot 0.5 - y \cdot z \]

Alternative 10: 60.4% accurate, 18.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 350000:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= z 350000.0) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= 350000.0) {
		tmp = x * 0.5;
	} else {
		tmp = y * -z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= 350000.0d0) then
        tmp = x * 0.5d0
    else
        tmp = y * -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= 350000.0) {
		tmp = x * 0.5;
	} else {
		tmp = y * -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= 350000.0:
		tmp = x * 0.5
	else:
		tmp = y * -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= 350000.0)
		tmp = Float64(x * 0.5);
	else
		tmp = Float64(y * Float64(-z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= 350000.0)
		tmp = x * 0.5;
	else
		tmp = y * -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, 350000.0], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 350000:\\
\;\;\;\;x \cdot 0.5\\

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


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

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{0.5 \cdot x} \]

    if 3.5e5 < z

    1. Initial program 100.0%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
      2. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(1 - z\right) + \log z, x \cdot 0.5\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(1 - z\right) + \log z, x \cdot 0.5\right)} \]
    4. Step-by-step derivation
      1. fma-udef100.0%

        \[\leadsto \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5} \]
      2. +-commutative100.0%

        \[\leadsto \color{blue}{x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)} \]
      3. distribute-lft-in100.0%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
      4. associate-+r+100.0%

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

      \[\leadsto \color{blue}{\left(x \cdot 0.5 + y \cdot \left(1 - z\right)\right) + y \cdot \log z} \]
    6. Taylor expanded in z around inf 79.4%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    7. Step-by-step derivation
      1. mul-1-neg79.4%

        \[\leadsto \color{blue}{-y \cdot z} \]
      2. distribute-rgt-neg-in79.4%

        \[\leadsto \color{blue}{y \cdot \left(-z\right)} \]
    8. Simplified79.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 350000:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]

Alternative 11: 39.9% accurate, 37.0× speedup?

\[\begin{array}{l} \\ x \cdot 0.5 \end{array} \]
(FPCore (x y z) :precision binary64 (* x 0.5))
double code(double x, double y, double z) {
	return x * 0.5;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * 0.5d0
end function
public static double code(double x, double y, double z) {
	return x * 0.5;
}
def code(x, y, z):
	return x * 0.5
function code(x, y, z)
	return Float64(x * 0.5)
end
function tmp = code(x, y, z)
	tmp = x * 0.5;
end
code[x_, y_, z_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}

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

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

    \[\leadsto \color{blue}{0.5 \cdot x} \]
  3. Final simplification35.4%

    \[\leadsto x \cdot 0.5 \]

Alternative 12: 1.8% accurate, 111.0× speedup?

\[\begin{array}{l} \\ y \end{array} \]
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
	return y;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = y
end function
public static double code(double x, double y, double z) {
	return y;
}
def code(x, y, z):
	return y
function code(x, y, z)
	return y
end
function tmp = code(x, y, z)
	tmp = y;
end
code[x_, y_, z_] := y
\begin{array}{l}

\\
y
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Step-by-step derivation
    1. sub-neg99.9%

      \[\leadsto x \cdot 0.5 + y \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} + \log z\right) \]
    2. associate-+l+99.9%

      \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(1 + \left(\left(-z\right) + \log z\right)\right)} \]
    3. distribute-rgt-in99.9%

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

      \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + \left(\left(-z\right) + \log z\right) \cdot y\right) \]
    5. associate-+r+99.9%

      \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) + \left(\left(-z\right) + \log z\right) \cdot y} \]
    6. neg-sub099.9%

      \[\leadsto \left(x \cdot 0.5 + y\right) + \left(\color{blue}{\left(0 - z\right)} + \log z\right) \cdot y \]
    7. associate-+l-99.9%

      \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(0 - \left(z - \log z\right)\right)} \cdot y \]
    8. neg-sub099.9%

      \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right)\right)} \cdot y \]
    9. distribute-lft-neg-out99.9%

      \[\leadsto \left(x \cdot 0.5 + y\right) + \color{blue}{\left(-\left(z - \log z\right) \cdot y\right)} \]
    10. unsub-neg99.9%

      \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) - \left(z - \log z\right) \cdot y} \]
    11. fma-def99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right)} - \left(z - \log z\right) \cdot y \]
    12. *-commutative99.9%

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

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

    \[\leadsto \color{blue}{y - y \cdot \left(z - \log z\right)} \]
  5. Taylor expanded in z around inf 40.2%

    \[\leadsto y - \color{blue}{y \cdot z} \]
  6. Taylor expanded in z around 0 1.7%

    \[\leadsto \color{blue}{y} \]
  7. Final simplification1.7%

    \[\leadsto y \]

Developer target: 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)));
}
real(8) function code(x, y, z)
    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 2023287 
(FPCore (x y z)
  :name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
  :precision binary64

  :herbie-target
  (- (+ y (* 0.5 x)) (* y (- z (log z))))

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