?

Average Error: 39.45% → 0.49%
Time: 16.2s
Precision: binary64
Cost: 13513

?

\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{-8} \lor \neg \left(y \leq 5 \cdot 10^{-77}\right):\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t)
 :precision binary64
 (if (or (<= y -7.2e-8) (not (<= y 5e-77)))
   (- x (/ (log1p (* y (expm1 z))) t))
   (- x (* (expm1 z) (/ y t)))))
double code(double x, double y, double z, double t) {
	return x - (log(((1.0 - y) + (y * exp(z)))) / t);
}
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -7.2e-8) || !(y <= 5e-77)) {
		tmp = x - (log1p((y * expm1(z))) / t);
	} else {
		tmp = x - (expm1(z) * (y / t));
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return x - (Math.log(((1.0 - y) + (y * Math.exp(z)))) / t);
}
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -7.2e-8) || !(y <= 5e-77)) {
		tmp = x - (Math.log1p((y * Math.expm1(z))) / t);
	} else {
		tmp = x - (Math.expm1(z) * (y / t));
	}
	return tmp;
}
def code(x, y, z, t):
	return x - (math.log(((1.0 - y) + (y * math.exp(z)))) / t)
def code(x, y, z, t):
	tmp = 0
	if (y <= -7.2e-8) or not (y <= 5e-77):
		tmp = x - (math.log1p((y * math.expm1(z))) / t)
	else:
		tmp = x - (math.expm1(z) * (y / t))
	return tmp
function code(x, y, z, t)
	return Float64(x - Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t))
end
function code(x, y, z, t)
	tmp = 0.0
	if ((y <= -7.2e-8) || !(y <= 5e-77))
		tmp = Float64(x - Float64(log1p(Float64(y * expm1(z))) / t));
	else
		tmp = Float64(x - Float64(expm1(z) * Float64(y / t)));
	end
	return tmp
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]
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.2e-8], N[Not[LessEqual[y, 5e-77]], $MachinePrecision]], N[(x - N[(N[Log[1 + N[(y * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(Exp[z] - 1), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-8} \lor \neg \left(y \leq 5 \cdot 10^{-77}\right):\\
\;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.45%
Target25.39%
Herbie0.49%
\[\begin{array}{l} \mathbf{if}\;z < -2.8874623088207947 \cdot 10^{+119}:\\ \;\;\;\;\left(x - \frac{\frac{-0.5}{y \cdot t}}{z \cdot z}\right) - \frac{-0.5}{y \cdot t} \cdot \frac{\frac{2}{z}}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\log \left(1 + z \cdot y\right)}{t}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if y < -7.19999999999999962e-8 or 4.99999999999999963e-77 < y

    1. Initial program 62.68

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Simplified0.72

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

      [Start]62.68

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

      *-lft-identity [<=]62.68

      \[ \color{blue}{1 \cdot \left(x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\right)} \]

      distribute-lft-out-- [<=]62.68

      \[ \color{blue}{1 \cdot x - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}} \]

      *-lft-identity [=>]62.68

      \[ \color{blue}{x} - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]

      *-commutative [<=]62.68

      \[ x - \color{blue}{\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \cdot 1} \]

      *-rgt-identity [=>]62.68

      \[ x - \color{blue}{\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}} \]

    if -7.19999999999999962e-8 < y < 4.99999999999999963e-77

    1. Initial program 17.33

      \[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
    2. Simplified2.11

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

      [Start]17.33

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

      *-lft-identity [<=]17.33

      \[ \color{blue}{1 \cdot \left(x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\right)} \]

      distribute-lft-out-- [<=]17.33

      \[ \color{blue}{1 \cdot x - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}} \]

      *-lft-identity [=>]17.33

      \[ \color{blue}{x} - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]

      *-commutative [<=]17.33

      \[ x - \color{blue}{\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \cdot 1} \]

      *-rgt-identity [=>]17.33

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

      \[\leadsto x - \color{blue}{\frac{\left(e^{z} - 1\right) \cdot y}{t}} \]
    4. Simplified0.31

      \[\leadsto x - \color{blue}{\frac{\mathsf{expm1}\left(z\right)}{\frac{t}{y}}} \]
      Proof

      [Start]7.86

      \[ x - \frac{\left(e^{z} - 1\right) \cdot y}{t} \]

      associate-/l* [=>]7.9

      \[ x - \color{blue}{\frac{e^{z} - 1}{\frac{t}{y}}} \]

      expm1-def [=>]0.31

      \[ x - \frac{\color{blue}{\mathsf{expm1}\left(z\right)}}{\frac{t}{y}} \]
    5. Taylor expanded in z around inf 7.86

      \[\leadsto x - \color{blue}{\frac{\left(e^{z} - 1\right) \cdot y}{t}} \]
    6. Simplified0.27

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

      [Start]7.86

      \[ x - \frac{\left(e^{z} - 1\right) \cdot y}{t} \]

      *-commutative [=>]7.86

      \[ x - \frac{\color{blue}{y \cdot \left(e^{z} - 1\right)}}{t} \]

      expm1-def [=>]2.17

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

      associate-*l/ [<=]0.27

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{-8} \lor \neg \left(y \leq 5 \cdot 10^{-77}\right):\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \end{array} \]

Alternatives

Alternative 1
Error10.95%
Cost7232
\[x - \frac{1}{\frac{t}{y \cdot \mathsf{expm1}\left(z\right)} + t \cdot 0.5} \]
Alternative 2
Error13.73%
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{+155}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\ \end{array} \]
Alternative 3
Error19.1%
Cost1088
\[x - \frac{y}{0.25 \cdot \left(z \cdot t\right) + \left(\frac{t}{z} + t \cdot -0.5\right)} \]
Alternative 4
Error19.12%
Cost960
\[x - \frac{y}{t \cdot \left(-0.5 + \left(z \cdot 0.25 + \frac{1}{z}\right)\right)} \]
Alternative 5
Error19.22%
Cost832
\[x - \frac{y}{0.25 \cdot \left(z \cdot t\right) + \frac{t}{z}} \]
Alternative 6
Error22.18%
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -0.0024:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{y}{t}\\ \end{array} \]
Alternative 7
Error18.86%
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -310:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 8
Error29.04%
Cost64
\[x \]

Error

Reproduce?

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

  :herbie-target
  (if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))

  (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))