?

Average Accuracy: 35.1% → 98.9%
Time: 5.2s
Precision: binary64
Cost: 6916

?

\[\frac{e^{x}}{e^{x} - 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.00155:\\ \;\;\;\;\frac{1}{1 - e^{-x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \frac{1}{x \cdot \left(1 + -0.08333333333333333 \cdot \left(x \cdot x\right)\right)}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= x -0.00155)
   (/ 1.0 (- 1.0 (exp (- x))))
   (+ 0.5 (/ 1.0 (* x (+ 1.0 (* -0.08333333333333333 (* x x))))))))
double code(double x) {
	return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
	double tmp;
	if (x <= -0.00155) {
		tmp = 1.0 / (1.0 - exp(-x));
	} else {
		tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x)))));
	}
	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 (x <= (-0.00155d0)) then
        tmp = 1.0d0 / (1.0d0 - exp(-x))
    else
        tmp = 0.5d0 + (1.0d0 / (x * (1.0d0 + ((-0.08333333333333333d0) * (x * x)))))
    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 (x <= -0.00155) {
		tmp = 1.0 / (1.0 - Math.exp(-x));
	} else {
		tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x)))));
	}
	return tmp;
}
def code(x):
	return math.exp(x) / (math.exp(x) - 1.0)
def code(x):
	tmp = 0
	if x <= -0.00155:
		tmp = 1.0 / (1.0 - math.exp(-x))
	else:
		tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x)))))
	return tmp
function code(x)
	return Float64(exp(x) / Float64(exp(x) - 1.0))
end
function code(x)
	tmp = 0.0
	if (x <= -0.00155)
		tmp = Float64(1.0 / Float64(1.0 - exp(Float64(-x))));
	else
		tmp = Float64(0.5 + Float64(1.0 / Float64(x * Float64(1.0 + Float64(-0.08333333333333333 * Float64(x * x))))));
	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 (x <= -0.00155)
		tmp = 1.0 / (1.0 - exp(-x));
	else
		tmp = 0.5 + (1.0 / (x * (1.0 + (-0.08333333333333333 * (x * x)))));
	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[x, -0.00155], N[(1.0 / N[(1.0 - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(1.0 / N[(x * N[(1.0 + N[(-0.08333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -0.00155:\\
\;\;\;\;\frac{1}{1 - e^{-x}}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original35.1%
Target35.8%
Herbie98.9%
\[\frac{1}{1 - e^{-x}} \]

Derivation?

  1. Split input into 2 regimes
  2. if x < -0.00154999999999999995

    1. Initial program 99.9%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
      Proof

      [Start]99.9

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

      expm1-def [=>]100.0

      \[ \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{e^{x}}\right)}^{-1}} \]
      Proof

      [Start]100.0

      \[ \frac{e^{x}}{\mathsf{expm1}\left(x\right)} \]

      clear-num [=>]100.0

      \[ \color{blue}{\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}}} \]

      inv-pow [=>]100.0

      \[ \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{e^{x}}\right)}^{-1}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}}} \]
      Proof

      [Start]100.0

      \[ {\left(\frac{\mathsf{expm1}\left(x\right)}{e^{x}}\right)}^{-1} \]

      unpow-1 [=>]100.0

      \[ \color{blue}{\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}}} \]
    5. Taylor expanded in x around inf 99.9%

      \[\leadsto \frac{1}{\color{blue}{\frac{e^{x} - 1}{e^{x}}}} \]
    6. Simplified99.9%

      \[\leadsto \frac{1}{\color{blue}{1 - e^{-x}}} \]
      Proof

      [Start]99.9

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

      div-sub [=>]1.8

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

      *-inverses [=>]99.9

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

      exp-neg [<=]99.9

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

    if -0.00154999999999999995 < x

    1. Initial program 3.4%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Simplified98.9%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
      Proof

      [Start]3.4

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

      expm1-def [=>]98.9

      \[ \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Taylor expanded in x around 0 98.4%

      \[\leadsto \color{blue}{0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)} \]
    4. Applied egg-rr48.6%

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

      [Start]98.4

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

      flip-+ [=>]48.7

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

      clear-num [=>]48.7

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

      swap-sqr [=>]48.7

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

      metadata-eval [=>]48.7

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

      inv-pow [=>]48.7

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

      metadata-eval [<=]48.7

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

      inv-pow [=>]48.7

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

      metadata-eval [<=]48.7

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

      pow-sqr [=>]48.6

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

      metadata-eval [=>]48.6

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

      metadata-eval [=>]48.6

      \[ 0.5 + \frac{1}{\frac{0.08333333333333333 \cdot x - \frac{1}{x}}{0.006944444444444444 \cdot \left(x \cdot x\right) - {x}^{\color{blue}{-2}}}} \]
    5. Taylor expanded in x around 0 98.4%

      \[\leadsto 0.5 + \frac{1}{\color{blue}{-0.08333333333333333 \cdot {x}^{3} + x}} \]
    6. Applied egg-rr98.4%

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

      [Start]98.4

      \[ 0.5 + \frac{1}{-0.08333333333333333 \cdot {x}^{3} + x} \]

      unpow3 [=>]98.4

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

      associate-*r* [=>]98.4

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

      distribute-lft1-in [=>]98.4

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

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

Alternatives

Alternative 1
Accuracy99.2%
Cost13120
\[\frac{1}{\frac{\mathsf{expm1}\left(x\right)}{e^{x}}} \]
Alternative 2
Accuracy99.2%
Cost12992
\[\frac{e^{x}}{\mathsf{expm1}\left(x\right)} \]
Alternative 3
Accuracy67.3%
Cost832
\[0.5 + \frac{1}{x \cdot \left(1 + -0.08333333333333333 \cdot \left(x \cdot x\right)\right)} \]
Alternative 4
Accuracy66.9%
Cost192
\[\frac{1}{x} \]

Error

Reproduce?

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

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

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