?

Average Error: 40.8 → 0.8
Time: 7.4s
Precision: binary64
Cost: 13828

?

\[\frac{e^{x}}{e^{x} - 1} \]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0.05:\\ \;\;\;\;\frac{2}{-1 + e^{-x}} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \left({x}^{3} \cdot -0.001388888888888889 + 0.5\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= (exp x) 0.05)
   (* (/ 2.0 (+ -1.0 (exp (- x)))) -0.5)
   (+
    (+ (/ 1.0 x) (* x 0.08333333333333333))
    (+ (* (pow x 3.0) -0.001388888888888889) 0.5))))
double code(double x) {
	return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
	double tmp;
	if (exp(x) <= 0.05) {
		tmp = (2.0 / (-1.0 + exp(-x))) * -0.5;
	} else {
		tmp = ((1.0 / x) + (x * 0.08333333333333333)) + ((pow(x, 3.0) * -0.001388888888888889) + 0.5);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = exp(x) / (exp(x) - 1.0d0)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (exp(x) <= 0.05d0) then
        tmp = (2.0d0 / ((-1.0d0) + exp(-x))) * (-0.5d0)
    else
        tmp = ((1.0d0 / x) + (x * 0.08333333333333333d0)) + (((x ** 3.0d0) * (-0.001388888888888889d0)) + 0.5d0)
    end if
    code = tmp
end function
public static double code(double x) {
	return Math.exp(x) / (Math.exp(x) - 1.0);
}
public static double code(double x) {
	double tmp;
	if (Math.exp(x) <= 0.05) {
		tmp = (2.0 / (-1.0 + Math.exp(-x))) * -0.5;
	} else {
		tmp = ((1.0 / x) + (x * 0.08333333333333333)) + ((Math.pow(x, 3.0) * -0.001388888888888889) + 0.5);
	}
	return tmp;
}
def code(x):
	return math.exp(x) / (math.exp(x) - 1.0)
def code(x):
	tmp = 0
	if math.exp(x) <= 0.05:
		tmp = (2.0 / (-1.0 + math.exp(-x))) * -0.5
	else:
		tmp = ((1.0 / x) + (x * 0.08333333333333333)) + ((math.pow(x, 3.0) * -0.001388888888888889) + 0.5)
	return tmp
function code(x)
	return Float64(exp(x) / Float64(exp(x) - 1.0))
end
function code(x)
	tmp = 0.0
	if (exp(x) <= 0.05)
		tmp = Float64(Float64(2.0 / Float64(-1.0 + exp(Float64(-x)))) * -0.5);
	else
		tmp = Float64(Float64(Float64(1.0 / x) + Float64(x * 0.08333333333333333)) + Float64(Float64((x ^ 3.0) * -0.001388888888888889) + 0.5));
	end
	return tmp
end
function tmp = code(x)
	tmp = exp(x) / (exp(x) - 1.0);
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (exp(x) <= 0.05)
		tmp = (2.0 / (-1.0 + exp(-x))) * -0.5;
	else
		tmp = ((1.0 / x) + (x * 0.08333333333333333)) + (((x ^ 3.0) * -0.001388888888888889) + 0.5);
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[N[Exp[x], $MachinePrecision], 0.05], N[(N[(2.0 / N[(-1.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, 3.0], $MachinePrecision] * -0.001388888888888889), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 0.05:\\
\;\;\;\;\frac{2}{-1 + e^{-x}} \cdot -0.5\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \left({x}^{3} \cdot -0.001388888888888889 + 0.5\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.8
Target40.4
Herbie0.8
\[\frac{1}{1 - e^{-x}} \]

Derivation?

  1. Split input into 2 regimes
  2. if (exp.f64 x) < 0.050000000000000003

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Applied egg-rr0.0

      \[\leadsto \color{blue}{\frac{2}{-1 + e^{-x}} \cdot -0.5} \]

    if 0.050000000000000003 < (exp.f64 x)

    1. Initial program 61.4

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Taylor expanded in x around 0 1.1

      \[\leadsto \color{blue}{0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right)} \]
    3. Simplified1.1

      \[\leadsto \color{blue}{\left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \left({x}^{3} \cdot -0.001388888888888889 + 0.5\right)} \]
      Proof

      [Start]1.1

      \[ 0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right) \]

      rational.json-simplify-41 [<=]1.1

      \[ \color{blue}{\left(0.08333333333333333 \cdot x + \frac{1}{x}\right) + \left(0.5 + -0.001388888888888889 \cdot {x}^{3}\right)} \]

      rational.json-simplify-1 [=>]1.1

      \[ \color{blue}{\left(\frac{1}{x} + 0.08333333333333333 \cdot x\right)} + \left(0.5 + -0.001388888888888889 \cdot {x}^{3}\right) \]

      rational.json-simplify-2 [=>]1.1

      \[ \left(\frac{1}{x} + \color{blue}{x \cdot 0.08333333333333333}\right) + \left(0.5 + -0.001388888888888889 \cdot {x}^{3}\right) \]

      rational.json-simplify-1 [<=]1.1

      \[ \left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \color{blue}{\left(-0.001388888888888889 \cdot {x}^{3} + 0.5\right)} \]

      rational.json-simplify-2 [=>]1.1

      \[ \left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \left(\color{blue}{{x}^{3} \cdot -0.001388888888888889} + 0.5\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \leq 0.05:\\ \;\;\;\;\frac{2}{-1 + e^{-x}} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \left({x}^{3} \cdot -0.001388888888888889 + 0.5\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost13444
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0.05:\\ \;\;\;\;\frac{2}{-1 + e^{-x}} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \left(x \cdot 0.08333333333333333 + 0.5\right)\\ \end{array} \]
Alternative 2
Error1.7
Cost6592
\[\frac{e^{x}}{x} \]
Alternative 3
Error10.9
Cost1348
\[\begin{array}{l} t_0 := \frac{x}{\frac{\frac{x}{32}}{\frac{0.015625}{x}}}\\ \mathbf{if}\;x \leq -6:\\ \;\;\;\;t_0 + t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \left(x \cdot 0.08333333333333333 + 0.5\right)\\ \end{array} \]
Alternative 4
Error11.0
Cost836
\[\begin{array}{l} \mathbf{if}\;x \leq -6:\\ \;\;\;\;\frac{x \cdot 4}{\left(x + x\right) \cdot \left(x + x\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \left(x \cdot 0.08333333333333333 + 0.5\right)\\ \end{array} \]
Alternative 5
Error21.7
Cost320
\[\frac{32}{x \cdot 32} \]
Alternative 6
Error21.8
Cost192
\[\frac{1}{x} \]

Error

Reproduce?

herbie shell --seed 2023073 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

  :herbie-target
  (/ 1.0 (- 1.0 (exp (- x))))

  (/ (exp x) (- (exp x) 1.0)))