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

Percentage Accurate: 99.9% → 99.9%
Time: 14.2s
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. Add Preprocessing

Alternative 2: 85.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot 0.5 \leq -4 \cdot 10^{-129}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{elif}\;x \cdot 0.5 \leq 10^{-70}:\\ \;\;\;\;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 (<= (* x 0.5) -4e-129)
   (- (* x 0.5) (* y z))
   (if (<= (* x 0.5) 1e-70)
     (* y (- (+ 1.0 (log z)) z))
     (fma y (- z) (* x 0.5)))))
double code(double x, double y, double z) {
	double tmp;
	if ((x * 0.5) <= -4e-129) {
		tmp = (x * 0.5) - (y * z);
	} else if ((x * 0.5) <= 1e-70) {
		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 (Float64(x * 0.5) <= -4e-129)
		tmp = Float64(Float64(x * 0.5) - Float64(y * z));
	elseif (Float64(x * 0.5) <= 1e-70)
		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[LessEqual[N[(x * 0.5), $MachinePrecision], -4e-129], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * 0.5), $MachinePrecision], 1e-70], 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}\;x \cdot 0.5 \leq -4 \cdot 10^{-129}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\

\mathbf{elif}\;x \cdot 0.5 \leq 10^{-70}:\\
\;\;\;\;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 3 regimes
  2. if (*.f64 x #s(literal 1/2 binary64)) < -3.9999999999999997e-129

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right) \cdot z} \]
    6. Step-by-step derivation
      1. distribute-lft-neg-out81.4%

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

        \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
      3. add-sqr-sqrt42.4%

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

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

        \[\leadsto x \cdot 0.5 - \sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}} \cdot z \]
      6. sqrt-unprod28.7%

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

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

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

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

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

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

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

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

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

    if -3.9999999999999997e-129 < (*.f64 x #s(literal 1/2 binary64)) < 9.99999999999999996e-71

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{y \cdot \left(\left(1 + \log z\right) - z\right)}{x} - 0.5\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-neg68.1%

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

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

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

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

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

    if 9.99999999999999996e-71 < (*.f64 x #s(literal 1/2 binary64))

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot 0.5 \leq -4 \cdot 10^{-129}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \mathbf{elif}\;x \cdot 0.5 \leq 10^{-70}:\\ \;\;\;\;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: 75.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 2.4 \cdot 10^{-219}:\\ \;\;\;\;x \cdot \left(0.5 - z \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-54}:\\ \;\;\;\;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 2.4e-219)
   (* x (- 0.5 (* z (/ y x))))
   (if (<= z 3.9e-54) (* y (+ 1.0 (log z))) (fma y (- z) (* x 0.5)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= 2.4e-219) {
		tmp = x * (0.5 - (z * (y / x)));
	} else if (z <= 3.9e-54) {
		tmp = 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 <= 2.4e-219)
		tmp = Float64(x * Float64(0.5 - Float64(z * Float64(y / x))));
	elseif (z <= 3.9e-54)
		tmp = 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, 2.4e-219], N[(x * N[(0.5 - N[(z * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.9e-54], N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.4 \cdot 10^{-219}:\\
\;\;\;\;x \cdot \left(0.5 - z \cdot \frac{y}{x}\right)\\

\mathbf{elif}\;z \leq 3.9 \cdot 10^{-54}:\\
\;\;\;\;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 3 regimes
  2. if z < 2.40000000000000014e-219

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

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
      3. add-sqr-sqrt38.9%

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

        \[\leadsto x \cdot 0.5 - \color{blue}{\sqrt{y \cdot y}} \cdot z \]
      5. sqr-neg60.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot 0.5 - z \cdot y} \]
    8. Taylor expanded in x around inf 65.3%

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

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

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

        \[\leadsto x \cdot \left(0.5 + \left(-\color{blue}{z \cdot \frac{y}{x}}\right)\right) \]
      4. distribute-rgt-neg-in65.8%

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

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

    if 2.40000000000000014e-219 < z < 3.9e-54

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

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

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

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

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

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

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

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

    if 3.9e-54 < 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 94.3%

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

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

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

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.2 \cdot 10^{-219}:\\
\;\;\;\;x \cdot \left(0.5 - z \cdot \frac{y}{x}\right)\\

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

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


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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
      3. add-sqr-sqrt38.9%

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

        \[\leadsto x \cdot 0.5 - \color{blue}{\sqrt{y \cdot y}} \cdot z \]
      5. sqr-neg60.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot 0.5 - z \cdot y} \]
    8. Taylor expanded in x around inf 65.3%

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

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

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

        \[\leadsto x \cdot \left(0.5 + \left(-\color{blue}{z \cdot \frac{y}{x}}\right)\right) \]
      4. distribute-rgt-neg-in65.8%

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

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

    if 4.20000000000000001e-219 < z < 5.1000000000000001e-54

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

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

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

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

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

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

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

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

    if 5.1000000000000001e-54 < z

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
      3. add-sqr-sqrt42.0%

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

        \[\leadsto x \cdot 0.5 - \color{blue}{\sqrt{y \cdot y}} \cdot z \]
      5. sqr-neg56.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot 0.5 - z \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 4.2 \cdot 10^{-219}:\\ \;\;\;\;x \cdot \left(0.5 - z \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{-54}:\\ \;\;\;\;y \cdot \left(1 + \log z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 2.35 \cdot 10^{-5}:\\ \;\;\;\;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 2.35e-5)
   (+ (* 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 <= 2.35e-5) {
		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 <= 2.35e-5)
		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, 2.35e-5], 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 2.35 \cdot 10^{-5}:\\
\;\;\;\;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 < 2.34999999999999986e-5

    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 0 99.4%

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

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

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

    if 2.34999999999999986e-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-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 98.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 2.35 \cdot 10^{-5}:\\ \;\;\;\;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 6: 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. Add Preprocessing

Alternative 7: 60.6% accurate, 12.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 2.1 \cdot 10^{+24}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= z 2.1e+24) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= 2.1e+24) {
		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 <= 2.1d+24) 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 <= 2.1e+24) {
		tmp = x * 0.5;
	} else {
		tmp = y * -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= 2.1e+24:
		tmp = x * 0.5
	else:
		tmp = y * -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= 2.1e+24)
		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 <= 2.1e+24)
		tmp = x * 0.5;
	else
		tmp = y * -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, 2.1e+24], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.1 \cdot 10^{+24}:\\
\;\;\;\;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 < 2.1000000000000001e24

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

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

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

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

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

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

    if 2.1000000000000001e24 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 75.3% 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 73.5%

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

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

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

    \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right) \cdot z} \]
  6. Step-by-step derivation
    1. distribute-lft-neg-out73.5%

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

      \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
    3. add-sqr-sqrt35.5%

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

      \[\leadsto x \cdot 0.5 - \color{blue}{\sqrt{y \cdot y}} \cdot z \]
    5. sqr-neg52.1%

      \[\leadsto x \cdot 0.5 - \sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}} \cdot z \]
    6. sqrt-unprod20.2%

      \[\leadsto x \cdot 0.5 - \color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \cdot z \]
    7. add-sqr-sqrt41.6%

      \[\leadsto x \cdot 0.5 - \color{blue}{\left(-y\right)} \cdot z \]
    8. *-commutative41.6%

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

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

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

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

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

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

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

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

Alternative 9: 40.4% 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 z around inf 73.5%

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

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

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

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

    \[\leadsto \color{blue}{0.5 \cdot x} \]
  7. Final simplification42.7%

    \[\leadsto x \cdot 0.5 \]
  8. 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)));
}
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 2024133 
(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)))))