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

Percentage Accurate: 60.9% → 98.6%
Time: 14.8s
Alternatives: 8
Speedup: 11.3×

Specification

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

\\
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\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 8 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: 60.9% accurate, 1.0× speedup?

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

\\
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\end{array}

Alternative 1: 98.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x - \frac{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}{t} \end{array} \]
(FPCore (x y z t) :precision binary64 (- x (/ (log1p (* (expm1 z) y)) t)))
double code(double x, double y, double z, double t) {
	return x - (log1p((expm1(z) * y)) / t);
}
public static double code(double x, double y, double z, double t) {
	return x - (Math.log1p((Math.expm1(z) * y)) / t);
}
def code(x, y, z, t):
	return x - (math.log1p((math.expm1(z) * y)) / t)
function code(x, y, z, t)
	return Float64(x - Float64(log1p(Float64(expm1(z) * y)) / t))
end
code[x_, y_, z_, t_] := N[(x - N[(N[Log[1 + N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x - \frac{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}{t}
\end{array}
Derivation
  1. Initial program 54.5%

    \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
  2. Add Preprocessing
  3. Taylor expanded in z around inf

    \[\leadsto x - \frac{\color{blue}{\log \left(\left(1 + y \cdot e^{z}\right) - y\right)}}{t} \]
  4. Step-by-step derivation
    1. associate--l+N/A

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

      \[\leadsto x - \frac{\log \left(1 + \left(y \cdot e^{z} - \color{blue}{y \cdot 1}\right)\right)}{t} \]
    3. distribute-lft-out--N/A

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

      \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(y \cdot \left(e^{z} - 1\right)\right)}}{t} \]
    5. *-commutativeN/A

      \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
    6. lower-*.f64N/A

      \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
    7. lower-expm1.f6498.1

      \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(z\right)} \cdot y\right)}{t} \]
  5. Applied rewrites98.1%

    \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}}{t} \]
  6. Add Preprocessing

Alternative 2: 88.9% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{+148} \lor \neg \left(y \leq 1.36 \cdot 10^{+139}\right):\\
\;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(z, y, 1\right)\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;x - \frac{\mathsf{expm1}\left(z\right)}{t} \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.7999999999999995e148 or 1.36000000000000004e139 < y

    1. Initial program 22.1%

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0

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

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

        \[\leadsto x - \frac{\log \left(\color{blue}{z \cdot y} + 1\right)}{t} \]
      3. lower-fma.f6474.4

        \[\leadsto x - \frac{\log \color{blue}{\left(\mathsf{fma}\left(z, y, 1\right)\right)}}{t} \]
    5. Applied rewrites74.4%

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

    if -8.7999999999999995e148 < y < 1.36000000000000004e139

    1. Initial program 61.2%

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

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

        \[\leadsto x - \color{blue}{y \cdot \frac{e^{z} - 1}{t}} \]
      2. div-subN/A

        \[\leadsto x - y \cdot \color{blue}{\left(\frac{e^{z}}{t} - \frac{1}{t}\right)} \]
      3. *-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{e^{z}}{t} - \frac{1}{t}\right) \cdot y} \]
      4. lower-*.f64N/A

        \[\leadsto x - \color{blue}{\left(\frac{e^{z}}{t} - \frac{1}{t}\right) \cdot y} \]
      5. div-subN/A

        \[\leadsto x - \color{blue}{\frac{e^{z} - 1}{t}} \cdot y \]
      6. lower-/.f64N/A

        \[\leadsto x - \color{blue}{\frac{e^{z} - 1}{t}} \cdot y \]
      7. lower-expm1.f6494.6

        \[\leadsto x - \frac{\color{blue}{\mathsf{expm1}\left(z\right)}}{t} \cdot y \]
    5. Applied rewrites94.6%

      \[\leadsto x - \color{blue}{\frac{\mathsf{expm1}\left(z\right)}{t} \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.8 \cdot 10^{+148} \lor \neg \left(y \leq 1.36 \cdot 10^{+139}\right):\\ \;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(z, y, 1\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{expm1}\left(z\right)}{t} \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+50}:\\
\;\;\;\;x - \frac{\log 1}{t}\\

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


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

    1. Initial program 72.4%

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto x - \frac{\log \color{blue}{1}}{t} \]
    4. Step-by-step derivation
      1. Applied rewrites55.8%

        \[\leadsto x - \frac{\log \color{blue}{1}}{t} \]

      if -3.79999999999999987e50 < z

      1. Initial program 49.0%

        \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
      2. Add Preprocessing
      3. Taylor expanded in z around inf

        \[\leadsto x - \frac{\color{blue}{\log \left(\left(1 + y \cdot e^{z}\right) - y\right)}}{t} \]
      4. Step-by-step derivation
        1. associate--l+N/A

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

          \[\leadsto x - \frac{\log \left(1 + \left(y \cdot e^{z} - \color{blue}{y \cdot 1}\right)\right)}{t} \]
        3. distribute-lft-out--N/A

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

          \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(y \cdot \left(e^{z} - 1\right)\right)}}{t} \]
        5. *-commutativeN/A

          \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
        6. lower-*.f64N/A

          \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
        7. lower-expm1.f6497.5

          \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(z\right)} \cdot y\right)}{t} \]
      5. Applied rewrites97.5%

        \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}}{t} \]
      6. Taylor expanded in z around 0

        \[\leadsto \color{blue}{x + -1 \cdot \frac{y \cdot z}{t}} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot z}{t} + x} \]
        2. mul-1-negN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{y \cdot z}{t}\right)\right)} + x \]
        3. associate-/l*N/A

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{-y}, \frac{z}{t}, x\right) \]
        7. lower-/.f6488.5

          \[\leadsto \mathsf{fma}\left(-y, \color{blue}{\frac{z}{t}}, x\right) \]
      8. Applied rewrites88.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-y, \frac{z}{t}, x\right)} \]
    5. Recombined 2 regimes into one program.
    6. Add Preprocessing

    Alternative 4: 86.2% accurate, 1.9× speedup?

    \[\begin{array}{l} \\ x - \frac{\mathsf{expm1}\left(z\right)}{t} \cdot y \end{array} \]
    (FPCore (x y z t) :precision binary64 (- x (* (/ (expm1 z) t) y)))
    double code(double x, double y, double z, double t) {
    	return x - ((expm1(z) / t) * y);
    }
    
    public static double code(double x, double y, double z, double t) {
    	return x - ((Math.expm1(z) / t) * y);
    }
    
    def code(x, y, z, t):
    	return x - ((math.expm1(z) / t) * y)
    
    function code(x, y, z, t)
    	return Float64(x - Float64(Float64(expm1(z) / t) * y))
    end
    
    code[x_, y_, z_, t_] := N[(x - N[(N[(N[(Exp[z] - 1), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    x - \frac{\mathsf{expm1}\left(z\right)}{t} \cdot y
    \end{array}
    
    Derivation
    1. Initial program 54.5%

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

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

        \[\leadsto x - \color{blue}{y \cdot \frac{e^{z} - 1}{t}} \]
      2. div-subN/A

        \[\leadsto x - y \cdot \color{blue}{\left(\frac{e^{z}}{t} - \frac{1}{t}\right)} \]
      3. *-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{e^{z}}{t} - \frac{1}{t}\right) \cdot y} \]
      4. lower-*.f64N/A

        \[\leadsto x - \color{blue}{\left(\frac{e^{z}}{t} - \frac{1}{t}\right) \cdot y} \]
      5. div-subN/A

        \[\leadsto x - \color{blue}{\frac{e^{z} - 1}{t}} \cdot y \]
      6. lower-/.f64N/A

        \[\leadsto x - \color{blue}{\frac{e^{z} - 1}{t}} \cdot y \]
      7. lower-expm1.f6487.4

        \[\leadsto x - \frac{\color{blue}{\mathsf{expm1}\left(z\right)}}{t} \cdot y \]
    5. Applied rewrites87.4%

      \[\leadsto x - \color{blue}{\frac{\mathsf{expm1}\left(z\right)}{t} \cdot y} \]
    6. Add Preprocessing

    Alternative 5: 74.5% accurate, 11.3× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(-y, \frac{z}{t}, x\right) \end{array} \]
    (FPCore (x y z t) :precision binary64 (fma (- y) (/ z t) x))
    double code(double x, double y, double z, double t) {
    	return fma(-y, (z / t), x);
    }
    
    function code(x, y, z, t)
    	return fma(Float64(-y), Float64(z / t), x)
    end
    
    code[x_, y_, z_, t_] := N[((-y) * N[(z / t), $MachinePrecision] + x), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(-y, \frac{z}{t}, x\right)
    \end{array}
    
    Derivation
    1. Initial program 54.5%

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto x - \frac{\color{blue}{\log \left(\left(1 + y \cdot e^{z}\right) - y\right)}}{t} \]
    4. Step-by-step derivation
      1. associate--l+N/A

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

        \[\leadsto x - \frac{\log \left(1 + \left(y \cdot e^{z} - \color{blue}{y \cdot 1}\right)\right)}{t} \]
      3. distribute-lft-out--N/A

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

        \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(y \cdot \left(e^{z} - 1\right)\right)}}{t} \]
      5. *-commutativeN/A

        \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
      6. lower-*.f64N/A

        \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
      7. lower-expm1.f6498.1

        \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(z\right)} \cdot y\right)}{t} \]
    5. Applied rewrites98.1%

      \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}}{t} \]
    6. Taylor expanded in z around 0

      \[\leadsto \color{blue}{x + -1 \cdot \frac{y \cdot z}{t}} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot z}{t} + x} \]
      2. mul-1-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{y \cdot z}{t}\right)\right)} + x \]
      3. associate-/l*N/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{-y}, \frac{z}{t}, x\right) \]
      7. lower-/.f6474.6

        \[\leadsto \mathsf{fma}\left(-y, \color{blue}{\frac{z}{t}}, x\right) \]
    8. Applied rewrites74.6%

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

    Alternative 6: 72.3% accurate, 11.3× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(\frac{-y}{t}, z, x\right) \end{array} \]
    (FPCore (x y z t) :precision binary64 (fma (/ (- y) t) z x))
    double code(double x, double y, double z, double t) {
    	return fma((-y / t), z, x);
    }
    
    function code(x, y, z, t)
    	return fma(Float64(Float64(-y) / t), z, x)
    end
    
    code[x_, y_, z_, t_] := N[(N[((-y) / t), $MachinePrecision] * z + x), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(\frac{-y}{t}, z, x\right)
    \end{array}
    
    Derivation
    1. Initial program 54.5%

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{2} \cdot \frac{z \cdot \left(y + -1 \cdot {y}^{2}\right)}{t} - \frac{y}{t}, z, x\right)} \]
    5. Applied rewrites62.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\left(y - y \cdot y\right) \cdot z}{t} \cdot -0.5 - \frac{y}{t}, z, x\right)} \]
    6. Taylor expanded in z around 0

      \[\leadsto \mathsf{fma}\left(-1 \cdot \frac{y}{t}, z, x\right) \]
    7. Step-by-step derivation
      1. Applied rewrites73.4%

        \[\leadsto \mathsf{fma}\left(\frac{-y}{t}, z, x\right) \]
      2. Add Preprocessing

      Alternative 7: 15.5% accurate, 11.9× speedup?

      \[\begin{array}{l} \\ \left(-y\right) \cdot \frac{z}{t} \end{array} \]
      (FPCore (x y z t) :precision binary64 (* (- y) (/ z t)))
      double code(double x, double y, double z, double t) {
      	return -y * (z / t);
      }
      
      real(8) function code(x, y, z, t)
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          real(8), intent (in) :: t
          code = -y * (z / t)
      end function
      
      public static double code(double x, double y, double z, double t) {
      	return -y * (z / t);
      }
      
      def code(x, y, z, t):
      	return -y * (z / t)
      
      function code(x, y, z, t)
      	return Float64(Float64(-y) * Float64(z / t))
      end
      
      function tmp = code(x, y, z, t)
      	tmp = -y * (z / t);
      end
      
      code[x_, y_, z_, t_] := N[((-y) * N[(z / t), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \left(-y\right) \cdot \frac{z}{t}
      \end{array}
      
      Derivation
      1. Initial program 54.5%

        \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
      2. Add Preprocessing
      3. Taylor expanded in z around inf

        \[\leadsto x - \frac{\color{blue}{\log \left(\left(1 + y \cdot e^{z}\right) - y\right)}}{t} \]
      4. Step-by-step derivation
        1. associate--l+N/A

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

          \[\leadsto x - \frac{\log \left(1 + \left(y \cdot e^{z} - \color{blue}{y \cdot 1}\right)\right)}{t} \]
        3. distribute-lft-out--N/A

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

          \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(y \cdot \left(e^{z} - 1\right)\right)}}{t} \]
        5. *-commutativeN/A

          \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
        6. lower-*.f64N/A

          \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
        7. lower-expm1.f6498.1

          \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(z\right)} \cdot y\right)}{t} \]
      5. Applied rewrites98.1%

        \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}}{t} \]
      6. Taylor expanded in z around 0

        \[\leadsto \color{blue}{x + -1 \cdot \frac{y \cdot z}{t}} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot z}{t} + x} \]
        2. mul-1-negN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{y \cdot z}{t}\right)\right)} + x \]
        3. associate-/l*N/A

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{-y}, \frac{z}{t}, x\right) \]
        7. lower-/.f6474.6

          \[\leadsto \mathsf{fma}\left(-y, \color{blue}{\frac{z}{t}}, x\right) \]
      8. Applied rewrites74.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-y, \frac{z}{t}, x\right)} \]
      9. Taylor expanded in x around 0

        \[\leadsto -1 \cdot \color{blue}{\frac{y \cdot z}{t}} \]
      10. Step-by-step derivation
        1. Applied rewrites18.5%

          \[\leadsto \left(-y\right) \cdot \color{blue}{\frac{z}{t}} \]
        2. Add Preprocessing

        Alternative 8: 13.5% accurate, 11.9× speedup?

        \[\begin{array}{l} \\ \frac{-y}{t} \cdot z \end{array} \]
        (FPCore (x y z t) :precision binary64 (* (/ (- y) t) z))
        double code(double x, double y, double z, double t) {
        	return (-y / t) * z;
        }
        
        real(8) function code(x, y, z, t)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8), intent (in) :: t
            code = (-y / t) * z
        end function
        
        public static double code(double x, double y, double z, double t) {
        	return (-y / t) * z;
        }
        
        def code(x, y, z, t):
        	return (-y / t) * z
        
        function code(x, y, z, t)
        	return Float64(Float64(Float64(-y) / t) * z)
        end
        
        function tmp = code(x, y, z, t)
        	tmp = (-y / t) * z;
        end
        
        code[x_, y_, z_, t_] := N[(N[((-y) / t), $MachinePrecision] * z), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \frac{-y}{t} \cdot z
        \end{array}
        
        Derivation
        1. Initial program 54.5%

          \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
        2. Add Preprocessing
        3. Taylor expanded in z around inf

          \[\leadsto x - \frac{\color{blue}{\log \left(\left(1 + y \cdot e^{z}\right) - y\right)}}{t} \]
        4. Step-by-step derivation
          1. associate--l+N/A

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

            \[\leadsto x - \frac{\log \left(1 + \left(y \cdot e^{z} - \color{blue}{y \cdot 1}\right)\right)}{t} \]
          3. distribute-lft-out--N/A

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

            \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(y \cdot \left(e^{z} - 1\right)\right)}}{t} \]
          5. *-commutativeN/A

            \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
          6. lower-*.f64N/A

            \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\left(e^{z} - 1\right) \cdot y}\right)}{t} \]
          7. lower-expm1.f6498.1

            \[\leadsto x - \frac{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(z\right)} \cdot y\right)}{t} \]
        5. Applied rewrites98.1%

          \[\leadsto x - \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}}{t} \]
        6. Taylor expanded in z around 0

          \[\leadsto \color{blue}{x + -1 \cdot \frac{y \cdot z}{t}} \]
        7. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot z}{t} + x} \]
          2. mul-1-negN/A

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{y \cdot z}{t}\right)\right)} + x \]
          3. associate-/l*N/A

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{-y}, \frac{z}{t}, x\right) \]
          7. lower-/.f6474.6

            \[\leadsto \mathsf{fma}\left(-y, \color{blue}{\frac{z}{t}}, x\right) \]
        8. Applied rewrites74.6%

          \[\leadsto \color{blue}{\mathsf{fma}\left(-y, \frac{z}{t}, x\right)} \]
        9. Taylor expanded in x around 0

          \[\leadsto -1 \cdot \color{blue}{\frac{y \cdot z}{t}} \]
        10. Step-by-step derivation
          1. Applied rewrites18.5%

            \[\leadsto \left(-y\right) \cdot \color{blue}{\frac{z}{t}} \]
          2. Step-by-step derivation
            1. Applied rewrites17.5%

              \[\leadsto -\frac{y}{t} \cdot z \]
            2. Final simplification17.5%

              \[\leadsto \frac{-y}{t} \cdot z \]
            3. Add Preprocessing

            Developer Target 1: 73.9% accurate, 1.8× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{-0.5}{y \cdot t}\\ \mathbf{if}\;z < -2.8874623088207947 \cdot 10^{+119}:\\ \;\;\;\;\left(x - \frac{t\_1}{z \cdot z}\right) - t\_1 \cdot \frac{\frac{2}{z}}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + z \cdot y\right)}{t}\\ \end{array} \end{array} \]
            (FPCore (x y z t)
             :precision binary64
             (let* ((t_1 (/ (- 0.5) (* y t))))
               (if (< z -2.8874623088207947e+119)
                 (- (- x (/ t_1 (* z z))) (* t_1 (/ (/ 2.0 z) (* z z))))
                 (- x (/ (log (+ 1.0 (* z y))) t)))))
            double code(double x, double y, double z, double t) {
            	double t_1 = -0.5 / (y * t);
            	double tmp;
            	if (z < -2.8874623088207947e+119) {
            		tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z)));
            	} else {
            		tmp = x - (log((1.0 + (z * y))) / t);
            	}
            	return tmp;
            }
            
            real(8) function code(x, y, z, t)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                real(8), intent (in) :: z
                real(8), intent (in) :: t
                real(8) :: t_1
                real(8) :: tmp
                t_1 = -0.5d0 / (y * t)
                if (z < (-2.8874623088207947d+119)) then
                    tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0d0 / z) / (z * z)))
                else
                    tmp = x - (log((1.0d0 + (z * y))) / t)
                end if
                code = tmp
            end function
            
            public static double code(double x, double y, double z, double t) {
            	double t_1 = -0.5 / (y * t);
            	double tmp;
            	if (z < -2.8874623088207947e+119) {
            		tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z)));
            	} else {
            		tmp = x - (Math.log((1.0 + (z * y))) / t);
            	}
            	return tmp;
            }
            
            def code(x, y, z, t):
            	t_1 = -0.5 / (y * t)
            	tmp = 0
            	if z < -2.8874623088207947e+119:
            		tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z)))
            	else:
            		tmp = x - (math.log((1.0 + (z * y))) / t)
            	return tmp
            
            function code(x, y, z, t)
            	t_1 = Float64(Float64(-0.5) / Float64(y * t))
            	tmp = 0.0
            	if (z < -2.8874623088207947e+119)
            		tmp = Float64(Float64(x - Float64(t_1 / Float64(z * z))) - Float64(t_1 * Float64(Float64(2.0 / z) / Float64(z * z))));
            	else
            		tmp = Float64(x - Float64(log(Float64(1.0 + Float64(z * y))) / t));
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y, z, t)
            	t_1 = -0.5 / (y * t);
            	tmp = 0.0;
            	if (z < -2.8874623088207947e+119)
            		tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z)));
            	else
            		tmp = x - (log((1.0 + (z * y))) / t);
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_, z_, t_] := Block[{t$95$1 = N[((-0.5) / N[(y * t), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -2.8874623088207947e+119], N[(N[(x - N[(t$95$1 / N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t$95$1 * N[(N[(2.0 / z), $MachinePrecision] / N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[N[(1.0 + N[(z * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_1 := \frac{-0.5}{y \cdot t}\\
            \mathbf{if}\;z < -2.8874623088207947 \cdot 10^{+119}:\\
            \;\;\;\;\left(x - \frac{t\_1}{z \cdot z}\right) - t\_1 \cdot \frac{\frac{2}{z}}{z \cdot z}\\
            
            \mathbf{else}:\\
            \;\;\;\;x - \frac{\log \left(1 + z \cdot y\right)}{t}\\
            
            
            \end{array}
            \end{array}
            

            Reproduce

            ?
            herbie shell --seed 2024326 
            (FPCore (x y z t)
              :name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
              :precision binary64
            
              :alt
              (! :herbie-platform default (if (< z -288746230882079470000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (- x (/ (/ (- 1/2) (* y t)) (* z z))) (* (/ (- 1/2) (* y t)) (/ (/ 2 z) (* z z)))) (- x (/ (log (+ 1 (* z y))) t))))
            
              (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))