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

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;x - \frac{y}{\frac{t}{\mathsf{expm1}\left(z\right)}}\\

\mathbf{else}:\\
\;\;\;\;x - \frac{t_1}{t}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.0
Target16.9
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 3 regimes
  2. if (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < -2e-200

    1. Initial program 46.2

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

      \[\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)): 49 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)): 3 points increase in error, 1 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)): 14 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)): 74 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.9

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

    if -2e-200 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < 0.0

    1. Initial program 12.6

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

      \[\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)): 49 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)): 3 points increase in error, 1 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)): 14 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)): 74 points increase in error, 0 points decrease in error
    3. Applied egg-rr1.2

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

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

      \[\leadsto x - \color{blue}{\frac{y}{\frac{t}{\mathsf{expm1}\left(z\right)}}} \]
      Proof
      (/.f64 y (/.f64 t (expm1.f64 z))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 t (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 z) 1)))): 36 points increase in error, 83 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y (-.f64 (exp.f64 z) 1)) t)): 1 points increase in error, 1 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 (exp.f64 z) 1) y)) t): 0 points increase in error, 0 points decrease in error

    if 0.0 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t)

    1. Initial program 43.6

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

      \[\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)): 49 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)): 3 points increase in error, 1 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)): 14 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)): 74 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \leq -2 \cdot 10^{-200}:\\ \;\;\;\;x - {\left(\frac{t}{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}\right)}^{-1}\\ \mathbf{elif}\;\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \leq 0:\\ \;\;\;\;x - \frac{y}{\frac{t}{\mathsf{expm1}\left(z\right)}}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost13512
\[\begin{array}{l} t_1 := x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\ \mathbf{if}\;y \leq -9.261036236562742 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.109943919668966 \cdot 10^{-100}:\\ \;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error5.3
Cost7112
\[\begin{array}{l} t_1 := x - \frac{\mathsf{log1p}\left(y \cdot z\right)}{t}\\ \mathbf{if}\;y \leq -4 \cdot 10^{+76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+34}:\\ \;\;\;\;x - \frac{y}{\frac{t}{\mathsf{expm1}\left(z\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error9.5
Cost6848
\[x - y \cdot \frac{\mathsf{expm1}\left(z\right)}{t} \]
Alternative 4
Error12.0
Cost1860
\[\begin{array}{l} \mathbf{if}\;z \leq -2.85 \cdot 10^{-12}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(\left(z \cdot z\right) \cdot \left(\frac{-0.5}{t} + z \cdot \left(\frac{-0.16666666666666666}{t} + \frac{-0.041666666666666664}{\frac{t}{z}}\right)\right) - \frac{z}{t}\right)\\ \end{array} \]
Alternative 5
Error19.0
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6425902603738736 \cdot 10^{-219}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.0513324248091432 \cdot 10^{-303}:\\ \;\;\;\;\frac{y \cdot z}{-t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error19.0
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6425902603738736 \cdot 10^{-219}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.1580460748104735 \cdot 10^{-248}:\\ \;\;\;\;-y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error12.0
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -2.85 \cdot 10^{-12}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 8
Error18.7
Cost64
\[x \]

Error

Reproduce

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