?

Average Error: 39.8 → 0.4
Time: 16.7s
Precision: binary64
Cost: 61188

?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{t_0}}{\frac{\frac{x}{t_0}}{t_0}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.8
Target40.3
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;x < 1 \land x > -1:\\ \;\;\;\;\frac{e^{x} - 1}{\log \left(e^{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if x < -9.2000000000000003e-4

    1. Initial program 0.0

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

    if -9.2000000000000003e-4 < x

    1. Initial program 59.8

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

      \[\leadsto \frac{\color{blue}{0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + \left(0.041666666666666664 \cdot {x}^{4} + x\right)\right)}}{x} \]
    3. Simplified0.5

      \[\leadsto \frac{\color{blue}{0.5 \cdot {x}^{2} + \left(\left(x + 0.16666666666666666 \cdot {x}^{3}\right) + 0.041666666666666664 \cdot {x}^{4}\right)}}{x} \]
      Proof

      [Start]0.5

      \[ \frac{0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + \left(0.041666666666666664 \cdot {x}^{4} + x\right)\right)}{x} \]

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

      \[ \frac{\color{blue}{0.5 \cdot {x}^{2} + \left(\left(0.041666666666666664 \cdot {x}^{4} + x\right) + 0.16666666666666666 \cdot {x}^{3}\right)}}{x} \]

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

      \[ \frac{0.5 \cdot {x}^{2} + \color{blue}{\left(0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + x\right)\right)}}{x} \]

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

      \[ \frac{0.5 \cdot {x}^{2} + \color{blue}{\left(0.041666666666666664 \cdot {x}^{4} + \left(x + 0.16666666666666666 \cdot {x}^{3}\right)\right)}}{x} \]

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

      \[ \frac{0.5 \cdot {x}^{2} + \color{blue}{\left(\left(x + 0.16666666666666666 \cdot {x}^{3}\right) + 0.041666666666666664 \cdot {x}^{4}\right)}}{x} \]
    4. Applied egg-rr0.7

      \[\leadsto \color{blue}{\frac{1}{0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + \left(x + 0.5 \cdot {x}^{2}\right)\right)} \cdot \frac{x}{\frac{x}{\left(0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + \left(x + 0.5 \cdot {x}^{2}\right)\right)\right) \cdot \frac{0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + \left(x + 0.5 \cdot {x}^{2}\right)\right)}{x}}}} \]
    5. Applied egg-rr0.5

      \[\leadsto \color{blue}{\frac{\frac{1}{x + \left(0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + \frac{{x}^{2}}{2}\right)\right)}}{\frac{\frac{x}{x + \left(0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + \frac{{x}^{2}}{2}\right)\right)}}{x + \left(0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + \frac{{x}^{2}}{2}\right)\right)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Alternatives

Alternative 1
Error0.4
Cost47876
\[\begin{array}{l} t_0 := x + \left(0.16666666666666666 \cdot {x}^{3} + \left(0.041666666666666664 \cdot {x}^{4} + \frac{{x}^{2}}{2}\right)\right)\\ \mathbf{if}\;x \leq -0.002:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{t_0}}{\frac{-0.5 \cdot x + \left(1 + 0.08333333333333333 \cdot {x}^{2}\right)}{t_0}}\\ \end{array} \]
Alternative 2
Error0.3
Cost13892
\[\begin{array}{l} \mathbf{if}\;x \leq -0.00092:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x + \left(0.16666666666666666 \cdot {x}^{2} + \left(1 + 0.041666666666666664 \cdot {x}^{3}\right)\right)\\ \end{array} \]
Alternative 3
Error0.4
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq -0.00014:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5 + \left(1 + 0.16666666666666666 \cdot {x}^{2}\right)\\ \end{array} \]
Alternative 4
Error0.5
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq -5.6 \cdot 10^{-6}:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x + 1\\ \end{array} \]
Alternative 5
Error21.2
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023073 
(FPCore (x)
  :name "Kahan's exp quotient"
  :precision binary64

  :herbie-target
  (if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))

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