?

Average Error: 40.7 → 0.9
Time: 19.4s
Precision: binary64
Cost: 26308

?

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.7
Target40.3
Herbie0.9
\[\frac{1}{1 - e^{-x}} \]

Derivation?

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

    1. Initial program 1.2

      \[\frac{e^{x}}{e^{x} - 1} \]

    if 2 < (/.f64 (exp.f64 x) (-.f64 (exp.f64 x) 1))

    1. Initial program 62.9

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

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

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

      [Start]0.7

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

      rational.json-simplify-41 [=>]0.7

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

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

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

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

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

      rational.json-simplify-41 [=>]0.7

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

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

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

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

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

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

Alternatives

Alternative 1
Error1.6
Cost6592
\[\frac{e^{x}}{x} \]
Alternative 2
Error12.9
Cost2500
\[\begin{array}{l} t_0 := \left(-0.5 - x \cdot 0.08333333333333333\right) - \frac{1}{x}\\ \mathbf{if}\;x \leq -7.2 \cdot 10^{+16}:\\ \;\;\;\;\left(\left(0 - \left(-1 - \frac{1}{x \cdot 0.08333333333333333 + \left(\frac{1}{x} + 0.5\right)}\right)\right) - 1\right) \cdot \left(t_0 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \left(0.5 + x \cdot 0.08333333333333333\right)\\ \end{array} \]
Alternative 3
Error12.8
Cost2372
\[\begin{array}{l} t_0 := \left(-0.5 - x \cdot 0.08333333333333333\right) - \frac{1}{x}\\ \mathbf{if}\;x \leq -1.05 \cdot 10^{+17}:\\ \;\;\;\;\left(\left(-1 + \frac{1}{x \cdot 0.08333333333333333 + \left(\frac{1}{x} + 0.5\right)}\right) + 1\right) \cdot \left(t_0 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \left(0.5 + x \cdot 0.08333333333333333\right)\\ \end{array} \]
Alternative 4
Error61.8
Cost192
\[x \cdot 0.25 \]
Alternative 5
Error21.9
Cost192
\[\frac{1}{x} \]
Alternative 6
Error61.8
Cost64
\[0.5 \]

Error

Reproduce?

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

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

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