Average Error: 25.7 → 0.6
Time: 20.7s
Precision: binary64
Cost: 13512
\[x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \]
\[\begin{array}{l} t_1 := x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{if}\;y \leq -7.017489851709385 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.647719248273216 \cdot 10^{-113}:\\ \;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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
 (let* ((t_1 (- x (/ (log1p (* y (expm1 z))) t))))
   (if (<= y -7.017489851709385e-155)
     t_1
     (if (<= y 7.647719248273216e-113) (- x (* y (/ (expm1 z) t))) t_1))))
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 t_1 = x - (log1p((y * expm1(z))) / t);
	double tmp;
	if (y <= -7.017489851709385e-155) {
		tmp = t_1;
	} else if (y <= 7.647719248273216e-113) {
		tmp = x - (y * (expm1(z) / t));
	} else {
		tmp = t_1;
	}
	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 t_1 = x - (Math.log1p((y * Math.expm1(z))) / t);
	double tmp;
	if (y <= -7.017489851709385e-155) {
		tmp = t_1;
	} else if (y <= 7.647719248273216e-113) {
		tmp = x - (y * (Math.expm1(z) / t));
	} else {
		tmp = t_1;
	}
	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):
	t_1 = x - (math.log1p((y * math.expm1(z))) / t)
	tmp = 0
	if y <= -7.017489851709385e-155:
		tmp = t_1
	elif y <= 7.647719248273216e-113:
		tmp = x - (y * (math.expm1(z) / t))
	else:
		tmp = t_1
	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)
	t_1 = Float64(x - Float64(log1p(Float64(y * expm1(z))) / t))
	tmp = 0.0
	if (y <= -7.017489851709385e-155)
		tmp = t_1;
	elseif (y <= 7.647719248273216e-113)
		tmp = Float64(x - Float64(y * Float64(expm1(z) / t)));
	else
		tmp = t_1;
	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_] := Block[{t$95$1 = N[(x - N[(N[Log[1 + N[(y * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.017489851709385e-155], t$95$1, If[LessEqual[y, 7.647719248273216e-113], N[(x - N[(y * N[(N[(Exp[z] - 1), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\
\mathbf{if}\;y \leq -7.017489851709385 \cdot 10^{-155}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 7.647719248273216 \cdot 10^{-113}:\\
\;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.7
Target16.0
Herbie0.6
\[\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.01748985170938503e-155 or 7.6477192482732156e-113 < y

    1. Initial program 34.5

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

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
      Proof
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (expm1.f64 z))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)))) t)): 47 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite=> sub-neg_binary64 (+.f64 (exp.f64 z) (neg.f64 1))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (+.f64 (exp.f64 z) (Rewrite=> metadata-eval -1)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= +-commutative_binary64 (+.f64 -1 (exp.f64 z))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 y -1) (*.f64 y (exp.f64 z))))) t)): 2 points increase in error, 2 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z))))))) t)): 28 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))))) t)): 68 points increase in error, 0 points decrease in error

    if -7.01748985170938503e-155 < y < 7.6477192482732156e-113

    1. Initial program 9.0

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

      \[\leadsto \color{blue}{x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}} \]
      Proof
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (expm1.f64 z))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)))) t)): 47 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite=> sub-neg_binary64 (+.f64 (exp.f64 z) (neg.f64 1))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (+.f64 (exp.f64 z) (Rewrite=> metadata-eval -1)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (*.f64 y (Rewrite<= +-commutative_binary64 (+.f64 -1 (exp.f64 z))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 y -1) (*.f64 y (exp.f64 z))))) t)): 2 points increase in error, 2 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 y)) (*.f64 y (exp.f64 z)))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log1p.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (-.f64 y (*.f64 y (exp.f64 z))))))) t)): 28 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (-.f64 y (*.f64 y (exp.f64 z)))))) t)): 0 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (log.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))))) t)): 68 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around 0 4.3

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

      \[\leadsto x - \color{blue}{y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}} \]
      Proof
      (*.f64 y (/.f64 (expm1.f64 z) t)): 0 points increase in error, 0 points decrease in error
      (*.f64 y (/.f64 (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)) t)): 28 points increase in error, 85 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 (-.f64 (exp.f64 z) 1) t) y)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (-.f64 (exp.f64 z) 1) y) t)): 9 points increase in error, 10 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.017489851709385 \cdot 10^{-155}:\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{elif}\;y \leq 7.647719248273216 \cdot 10^{-113}:\\ \;\;\;\;x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \end{array} \]

Alternatives

Alternative 1
Error9.6
Cost1348
\[\begin{array}{l} t_1 := \frac{t}{y \cdot z}\\ \mathbf{if}\;z \leq -3.15 \cdot 10^{-52}:\\ \;\;\;\;x + \frac{-1}{\left(-0.5 \cdot \frac{t}{y} + t_1\right) + t \cdot 0.5}\\ \mathbf{elif}\;z \leq 4.470581568347432 \cdot 10^{-291}:\\ \;\;\;\;x - \frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-1}{t_1 + t \cdot 0.5}\\ \end{array} \]
Alternative 2
Error19.4
Cost912
\[\begin{array}{l} \mathbf{if}\;x \leq -1.079412457530686 \cdot 10^{-185}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.032581468628282 \cdot 10^{-278}:\\ \;\;\;\;y \cdot \frac{-z}{t}\\ \mathbf{elif}\;x \leq 2.9381854069069127 \cdot 10^{-162}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.392208891132122 \cdot 10^{-122}:\\ \;\;\;\;\frac{y \cdot z}{-t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error18.2
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022291 
(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)))