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

Percentage Accurate: 99.9% → 99.9%
Time: 17.3s
Alternatives: 9
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 9 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.9% accurate, 0.5× speedup?

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

\\
\mathsf{fma}\left(y, \left(1 - z\right) + \log z, x \cdot 0.5\right)
\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-define99.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. Add Preprocessing
  5. Final simplification99.9%

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

Alternative 2: 85.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+146} \lor \neg \left(y \leq 7.5 \cdot 10^{+40}\right):\\
\;\;\;\;y \cdot \left(\left(1 + \log z\right) - z\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 y < -5.20000000000000028e146 or 7.4999999999999996e40 < 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. distribute-lft-in99.7%

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

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

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

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

    if -5.20000000000000028e146 < y < 7.4999999999999996e40

    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-define99.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. Add Preprocessing
    5. Taylor expanded in z around inf 88.2%

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

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

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

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

Alternative 3: 98.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 1.3 \cdot 10^{-6}:\\ \;\;\;\;x \cdot 0.5 + y \cdot \left(1 + \log z\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.3e-6)
   (+ (* x 0.5) (* y (+ 1.0 (log z))))
   (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= 1.3e-6) {
		tmp = (x * 0.5) + (y * (1.0 + log(z)));
	} else {
		tmp = fma(y, -z, (x * 0.5));
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= 1.3e-6)
		tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 + log(z))));
	else
		tmp = fma(y, Float64(-z), Float64(x * 0.5));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, 1.3e-6], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.3 \cdot 10^{-6}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 + \log z\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.30000000000000005e-6

    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 99.7%

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

    if 1.30000000000000005e-6 < 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-define100.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. Add Preprocessing
    5. Taylor expanded in z around inf 97.7%

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

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

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

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

Alternative 4: 75.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.5 \cdot 10^{+276}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;y + y \cdot \log z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 3.49999999999999981e276

    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-define99.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. Add Preprocessing
    5. Taylor expanded in z around inf 80.3%

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

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

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

    if 3.49999999999999981e276 < y

    1. Initial program 99.4%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-lft-in99.7%

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

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

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

      \[\leadsto \color{blue}{y + y \cdot \log z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.7%

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

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. Add Preprocessing
  3. Final simplification99.9%

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

Alternative 6: 75.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.35 \cdot 10^{+275}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y + y \cdot \log z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 1.35e+275) (- (* x 0.5) (* y z)) (+ y (* y (log z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.35e+275) {
		tmp = (x * 0.5) - (y * z);
	} else {
		tmp = y + (y * log(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 (y <= 1.35d+275) then
        tmp = (x * 0.5d0) - (y * z)
    else
        tmp = y + (y * log(z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.35e+275) {
		tmp = (x * 0.5) - (y * z);
	} else {
		tmp = y + (y * Math.log(z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 1.35e+275:
		tmp = (x * 0.5) - (y * z)
	else:
		tmp = y + (y * math.log(z))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 1.35e+275)
		tmp = Float64(Float64(x * 0.5) - Float64(y * z));
	else
		tmp = Float64(y + Float64(y * log(z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 1.35e+275)
		tmp = (x * 0.5) - (y * z);
	else
		tmp = y + (y * log(z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 1.35e+275], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+275}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\

\mathbf{else}:\\
\;\;\;\;y + y \cdot \log z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.35000000000000008e275

    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 80.3%

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

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

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

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right) \cdot z} \]
    6. Step-by-step derivation
      1. fma-define80.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, \left(-y\right) \cdot z\right)} \]
      2. distribute-lft-neg-out80.3%

        \[\leadsto \mathsf{fma}\left(x, 0.5, \color{blue}{-y \cdot z}\right) \]
      3. add-sqr-sqrt37.1%

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

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

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

        \[\leadsto \mathsf{fma}\left(x, 0.5, -\color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \cdot z\right) \]
      7. add-sqr-sqrt46.4%

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

        \[\leadsto \color{blue}{x \cdot 0.5 - \left(-y\right) \cdot z} \]
      9. add-sqr-sqrt26.8%

        \[\leadsto x \cdot 0.5 - \color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \cdot z \]
      10. sqrt-unprod57.9%

        \[\leadsto x \cdot 0.5 - \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}} \cdot z \]
      11. sqr-neg57.9%

        \[\leadsto x \cdot 0.5 - \sqrt{\color{blue}{y \cdot y}} \cdot z \]
      12. sqrt-unprod37.1%

        \[\leadsto x \cdot 0.5 - \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot z \]
      13. add-sqr-sqrt80.3%

        \[\leadsto x \cdot 0.5 - \color{blue}{y} \cdot z \]
    7. Applied egg-rr80.3%

      \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]

    if 1.35000000000000008e275 < y

    1. Initial program 99.4%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-lft-in99.7%

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

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

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

      \[\leadsto \color{blue}{y + y \cdot \log z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.35 \cdot 10^{+275}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y + y \cdot \log z\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 57.9% accurate, 5.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 350000000 \lor \neg \left(z \leq 2.85 \cdot 10^{+61}\right) \land z \leq 5.6 \cdot 10^{+128}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z 350000000.0) (and (not (<= z 2.85e+61)) (<= z 5.6e+128)))
   (* x 0.5)
   (* y (- z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= 350000000.0) || (!(z <= 2.85e+61) && (z <= 5.6e+128))) {
		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 <= 350000000.0d0) .or. (.not. (z <= 2.85d+61)) .and. (z <= 5.6d+128)) 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 <= 350000000.0) || (!(z <= 2.85e+61) && (z <= 5.6e+128))) {
		tmp = x * 0.5;
	} else {
		tmp = y * -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= 350000000.0) or (not (z <= 2.85e+61) and (z <= 5.6e+128)):
		tmp = x * 0.5
	else:
		tmp = y * -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= 350000000.0) || (!(z <= 2.85e+61) && (z <= 5.6e+128)))
		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 <= 350000000.0) || (~((z <= 2.85e+61)) && (z <= 5.6e+128)))
		tmp = x * 0.5;
	else
		tmp = y * -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, 350000000.0], And[N[Not[LessEqual[z, 2.85e+61]], $MachinePrecision], LessEqual[z, 5.6e+128]]], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 350000000 \lor \neg \left(z \leq 2.85 \cdot 10^{+61}\right) \land z \leq 5.6 \cdot 10^{+128}:\\
\;\;\;\;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.5e8 or 2.85000000000000011e61 < z < 5.59999999999999965e128

    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 x around inf 60.9%

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

    if 3.5e8 < z < 2.85000000000000011e61 or 5.59999999999999965e128 < z

    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 98.4%

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

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

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

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

      \[\leadsto \color{blue}{z \cdot \left(-1 \cdot y + 0.5 \cdot \frac{x}{z}\right)} \]
    7. Step-by-step derivation
      1. +-commutative98.3%

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

        \[\leadsto z \cdot \left(0.5 \cdot \frac{x}{z} + \color{blue}{\left(-y\right)}\right) \]
      3. unsub-neg98.3%

        \[\leadsto z \cdot \color{blue}{\left(0.5 \cdot \frac{x}{z} - y\right)} \]
      4. associate-*r/98.3%

        \[\leadsto z \cdot \left(\color{blue}{\frac{0.5 \cdot x}{z}} - y\right) \]
    8. Simplified98.3%

      \[\leadsto \color{blue}{z \cdot \left(\frac{0.5 \cdot x}{z} - y\right)} \]
    9. Taylor expanded in x around 0 77.6%

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

        \[\leadsto z \cdot \color{blue}{\left(-y\right)} \]
    11. Simplified77.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 350000000 \lor \neg \left(z \leq 2.85 \cdot 10^{+61}\right) \land z \leq 5.6 \cdot 10^{+128}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 75.4% 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. Add Preprocessing
  3. Taylor expanded in z around inf 78.8%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, \left(-y\right) \cdot z\right)} \]
    2. distribute-lft-neg-out78.8%

      \[\leadsto \mathsf{fma}\left(x, 0.5, \color{blue}{-y \cdot z}\right) \]
    3. add-sqr-sqrt36.5%

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

      \[\leadsto \mathsf{fma}\left(x, 0.5, -\color{blue}{\sqrt{y \cdot y}} \cdot z\right) \]
    5. sqr-neg57.0%

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

      \[\leadsto \mathsf{fma}\left(x, 0.5, -\color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \cdot z\right) \]
    7. add-sqr-sqrt45.5%

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

      \[\leadsto \color{blue}{x \cdot 0.5 - \left(-y\right) \cdot z} \]
    9. add-sqr-sqrt26.3%

      \[\leadsto x \cdot 0.5 - \color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \cdot z \]
    10. sqrt-unprod57.0%

      \[\leadsto x \cdot 0.5 - \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}} \cdot z \]
    11. sqr-neg57.0%

      \[\leadsto x \cdot 0.5 - \sqrt{\color{blue}{y \cdot y}} \cdot z \]
    12. sqrt-unprod36.5%

      \[\leadsto x \cdot 0.5 - \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot z \]
    13. add-sqr-sqrt78.8%

      \[\leadsto x \cdot 0.5 - \color{blue}{y} \cdot z \]
  7. Applied egg-rr78.8%

    \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
  8. Final simplification78.8%

    \[\leadsto x \cdot 0.5 - y \cdot z \]
  9. Add Preprocessing

Alternative 9: 41.1% 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. Add Preprocessing
  3. Taylor expanded in x around inf 46.5%

    \[\leadsto \color{blue}{0.5 \cdot x} \]
  4. Final simplification46.5%

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

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 2024055 
(FPCore (x y z)
  :name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
  :precision binary64

  :alt
  (- (+ y (* 0.5 x)) (* y (- z (log z))))

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