| Alternative 1 | |
|---|---|
| Error | 1.9 |
| Cost | 13504 |
\[x + \left({x}^{5} \cdot 0.13333333333333333 + {x}^{3} \cdot -0.3333333333333333\right)
\]
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))) (t_1 (+ (exp x) t_0)))
(if (<= (/ (- (exp x) t_0) t_1) 0.0005)
(+
(+ x (* (pow x 5.0) 0.13333333333333333))
(+
(* (pow x 3.0) -0.3333333333333333)
(* (pow x 7.0) -0.05396825396825397)))
(- (* 2.0 (/ (exp x) t_1)) 1.0))))double code(double x) {
return (exp(x) - exp(-x)) / (exp(x) + exp(-x));
}
double code(double x) {
double t_0 = exp(-x);
double t_1 = exp(x) + t_0;
double tmp;
if (((exp(x) - t_0) / t_1) <= 0.0005) {
tmp = (x + (pow(x, 5.0) * 0.13333333333333333)) + ((pow(x, 3.0) * -0.3333333333333333) + (pow(x, 7.0) * -0.05396825396825397));
} else {
tmp = (2.0 * (exp(x) / t_1)) - 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = exp(-x)
t_1 = exp(x) + t_0
if (((exp(x) - t_0) / t_1) <= 0.0005d0) then
tmp = (x + ((x ** 5.0d0) * 0.13333333333333333d0)) + (((x ** 3.0d0) * (-0.3333333333333333d0)) + ((x ** 7.0d0) * (-0.05396825396825397d0)))
else
tmp = (2.0d0 * (exp(x) / t_1)) - 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 t_0 = Math.exp(-x);
double t_1 = Math.exp(x) + t_0;
double tmp;
if (((Math.exp(x) - t_0) / t_1) <= 0.0005) {
tmp = (x + (Math.pow(x, 5.0) * 0.13333333333333333)) + ((Math.pow(x, 3.0) * -0.3333333333333333) + (Math.pow(x, 7.0) * -0.05396825396825397));
} else {
tmp = (2.0 * (Math.exp(x) / t_1)) - 1.0;
}
return tmp;
}
def code(x): return (math.exp(x) - math.exp(-x)) / (math.exp(x) + math.exp(-x))
def code(x): t_0 = math.exp(-x) t_1 = math.exp(x) + t_0 tmp = 0 if ((math.exp(x) - t_0) / t_1) <= 0.0005: tmp = (x + (math.pow(x, 5.0) * 0.13333333333333333)) + ((math.pow(x, 3.0) * -0.3333333333333333) + (math.pow(x, 7.0) * -0.05396825396825397)) else: tmp = (2.0 * (math.exp(x) / t_1)) - 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) t_0 = exp(Float64(-x)) t_1 = Float64(exp(x) + t_0) tmp = 0.0 if (Float64(Float64(exp(x) - t_0) / t_1) <= 0.0005) tmp = Float64(Float64(x + Float64((x ^ 5.0) * 0.13333333333333333)) + Float64(Float64((x ^ 3.0) * -0.3333333333333333) + Float64((x ^ 7.0) * -0.05396825396825397))); else tmp = Float64(Float64(2.0 * Float64(exp(x) / t_1)) - 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) t_0 = exp(-x); t_1 = exp(x) + t_0; tmp = 0.0; if (((exp(x) - t_0) / t_1) <= 0.0005) tmp = (x + ((x ^ 5.0) * 0.13333333333333333)) + (((x ^ 3.0) * -0.3333333333333333) + ((x ^ 7.0) * -0.05396825396825397)); else tmp = (2.0 * (exp(x) / t_1)) - 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_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[x], $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - t$95$0), $MachinePrecision] / t$95$1), $MachinePrecision], 0.0005], N[(N[(x + N[(N[Power[x, 5.0], $MachinePrecision] * 0.13333333333333333), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, 3.0], $MachinePrecision] * -0.3333333333333333), $MachinePrecision] + N[(N[Power[x, 7.0], $MachinePrecision] * -0.05396825396825397), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(N[Exp[x], $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]]]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := e^{x} + t_0\\
\mathbf{if}\;\frac{e^{x} - t_0}{t_1} \leq 0.0005:\\
\;\;\;\;\left(x + {x}^{5} \cdot 0.13333333333333333\right) + \left({x}^{3} \cdot -0.3333333333333333 + {x}^{7} \cdot -0.05396825396825397\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{e^{x}}{t_1} - 1\\
\end{array}
Results
if (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 5.0000000000000001e-4Initial program 58.6
Taylor expanded in x around 0 0.3
Simplified0.3
[Start]0.3 | \[ -0.05396825396825397 \cdot {x}^{7} + \left(-0.3333333333333333 \cdot {x}^{3} + \left(0.13333333333333333 \cdot {x}^{5} + x\right)\right)
\] |
|---|---|
rational_best-simplify-47 [=>]0.3 | \[ \color{blue}{\left(0.13333333333333333 \cdot {x}^{5} + x\right) + \left(-0.3333333333333333 \cdot {x}^{3} + -0.05396825396825397 \cdot {x}^{7}\right)}
\] |
rational_best-simplify-3 [=>]0.3 | \[ \color{blue}{\left(x + 0.13333333333333333 \cdot {x}^{5}\right)} + \left(-0.3333333333333333 \cdot {x}^{3} + -0.05396825396825397 \cdot {x}^{7}\right)
\] |
rational_best-simplify-1 [=>]0.3 | \[ \left(x + \color{blue}{{x}^{5} \cdot 0.13333333333333333}\right) + \left(-0.3333333333333333 \cdot {x}^{3} + -0.05396825396825397 \cdot {x}^{7}\right)
\] |
rational_best-simplify-1 [=>]0.3 | \[ \left(x + {x}^{5} \cdot 0.13333333333333333\right) + \left(\color{blue}{{x}^{3} \cdot -0.3333333333333333} + -0.05396825396825397 \cdot {x}^{7}\right)
\] |
rational_best-simplify-1 [=>]0.3 | \[ \left(x + {x}^{5} \cdot 0.13333333333333333\right) + \left({x}^{3} \cdot -0.3333333333333333 + \color{blue}{{x}^{7} \cdot -0.05396825396825397}\right)
\] |
if 5.0000000000000001e-4 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) Initial program 40.7
Applied egg-rr20.5
Simplified20.5
[Start]20.5 | \[ \frac{e^{x}}{e^{x} + e^{-x}} \cdot 2 - \left(1 + \frac{0}{e^{x} + e^{-x}}\right)
\] |
|---|---|
metadata-eval [<=]20.5 | \[ \frac{e^{x}}{e^{x} + e^{-x}} \cdot 2 - \left(1 + \frac{\color{blue}{0 - 0}}{e^{x} + e^{-x}}\right)
\] |
rational_best-simplify-66 [<=]20.5 | \[ \frac{e^{x}}{e^{x} + e^{-x}} \cdot 2 - \left(1 + \color{blue}{\left(\frac{0}{e^{x} + e^{-x}} - \frac{0}{e^{x} + e^{-x}}\right)}\right)
\] |
rational_best-simplify-5 [=>]20.5 | \[ \frac{e^{x}}{e^{x} + e^{-x}} \cdot 2 - \left(1 + \color{blue}{0}\right)
\] |
metadata-eval [=>]20.5 | \[ \frac{e^{x}}{e^{x} + e^{-x}} \cdot 2 - \color{blue}{1}
\] |
rational_best-simplify-1 [=>]20.5 | \[ \color{blue}{2 \cdot \frac{e^{x}}{e^{x} + e^{-x}}} - 1
\] |
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 1.9 |
| Cost | 13504 |
| Alternative 2 | |
|---|---|
| Error | 2.1 |
| Cost | 6784 |
| Alternative 3 | |
|---|---|
| Error | 2.3 |
| Cost | 64 |
herbie shell --seed 2023099
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))