?

Average Accuracy: 9.2% → 98.4%
Time: 26.8s
Precision: binary64
Cost: 20868

?

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

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if x < 2.14999999999999991

    1. Initial program 8.8%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Taylor expanded in x around 0 8.1%

      \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + \left({x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right)}} \]
    3. Simplified8.1%

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

      [Start]8.1

      \[ \frac{e^{x} - e^{-x}}{2 + \left({x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right)} \]

      unpow2 [=>]8.1

      \[ \frac{e^{x} - e^{-x}}{2 + \left(\color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4}\right)} \]
    4. Taylor expanded in x around 0 98.5%

      \[\leadsto \frac{\color{blue}{2 \cdot x + \left(0.3333333333333333 \cdot {x}^{3} + 0.016666666666666666 \cdot {x}^{5}\right)}}{2 + \left(x \cdot x + 0.08333333333333333 \cdot {x}^{4}\right)} \]

    if 2.14999999999999991 < x

    1. Initial program 38.7%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Taylor expanded in x around 0 4.3%

      \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{2 + {x}^{2}}} \]
    3. Simplified4.3%

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

      [Start]4.3

      \[ \frac{e^{x} - e^{-x}}{2 + {x}^{2}} \]

      unpow2 [=>]4.3

      \[ \frac{e^{x} - e^{-x}}{2 + \color{blue}{x \cdot x}} \]
    4. Applied egg-rr92.1%

      \[\leadsto \color{blue}{1} \]
      Proof

      [Start]4.3

      \[ \frac{e^{x} - e^{-x}}{2 + x \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.15:\\ \;\;\;\;\frac{x \cdot 2 + \left(0.3333333333333333 \cdot {x}^{3} + 0.016666666666666666 \cdot {x}^{5}\right)}{2 + \left(x \cdot x + 0.08333333333333333 \cdot {x}^{4}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.3%
Cost13636
\[\begin{array}{l} \mathbf{if}\;x \leq 1.25:\\ \;\;\;\;{x}^{3} \cdot -0.3333333333333333 + \left(x + {x}^{5} \cdot 0.13333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 2
Accuracy98.3%
Cost13636
\[\begin{array}{l} \mathbf{if}\;x \leq 1.25:\\ \;\;\;\;x + \left({x}^{3} \cdot -0.3333333333333333 + {x}^{5} \cdot 0.13333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 3
Accuracy98.2%
Cost1092
\[\begin{array}{l} \mathbf{if}\;x \leq 1.6:\\ \;\;\;\;\frac{x \cdot \left(2 + 0.3333333333333333 \cdot \left(x \cdot x\right)\right)}{2 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Accuracy97.7%
Cost708
\[\begin{array}{l} \mathbf{if}\;x \leq 1.25:\\ \;\;\;\;\frac{x + x}{2 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Accuracy7.9%
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 6
Accuracy97.6%
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Accuracy5.1%
Cost64
\[-1 \]

Error

Reproduce?

herbie shell --seed 2023138 
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))