| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 13504 |
\[\left(x + {x}^{3} \cdot -0.3333333333333333\right) + {x}^{5} \cdot 0.13333333333333333
\]
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))
(FPCore (x) :precision binary64 (+ (+ x (* (pow x 3.0) -0.3333333333333333)) (+ (* (pow x 5.0) 0.13333333333333333) (* (pow x 7.0) -0.05396825396825397))))
double code(double x) {
return (exp(x) - exp(-x)) / (exp(x) + exp(-x));
}
double code(double x) {
return (x + (pow(x, 3.0) * -0.3333333333333333)) + ((pow(x, 5.0) * 0.13333333333333333) + (pow(x, 7.0) * -0.05396825396825397));
}
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
code = (x + ((x ** 3.0d0) * (-0.3333333333333333d0))) + (((x ** 5.0d0) * 0.13333333333333333d0) + ((x ** 7.0d0) * (-0.05396825396825397d0)))
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) {
return (x + (Math.pow(x, 3.0) * -0.3333333333333333)) + ((Math.pow(x, 5.0) * 0.13333333333333333) + (Math.pow(x, 7.0) * -0.05396825396825397));
}
def code(x): return (math.exp(x) - math.exp(-x)) / (math.exp(x) + math.exp(-x))
def code(x): return (x + (math.pow(x, 3.0) * -0.3333333333333333)) + ((math.pow(x, 5.0) * 0.13333333333333333) + (math.pow(x, 7.0) * -0.05396825396825397))
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / Float64(exp(x) + exp(Float64(-x)))) end
function code(x) return Float64(Float64(x + Float64((x ^ 3.0) * -0.3333333333333333)) + Float64(Float64((x ^ 5.0) * 0.13333333333333333) + Float64((x ^ 7.0) * -0.05396825396825397))) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / (exp(x) + exp(-x)); end
function tmp = code(x) tmp = (x + ((x ^ 3.0) * -0.3333333333333333)) + (((x ^ 5.0) * 0.13333333333333333) + ((x ^ 7.0) * -0.05396825396825397)); 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_] := N[(N[(x + N[(N[Power[x, 3.0], $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, 5.0], $MachinePrecision] * 0.13333333333333333), $MachinePrecision] + N[(N[Power[x, 7.0], $MachinePrecision] * -0.05396825396825397), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\left(x + {x}^{3} \cdot -0.3333333333333333\right) + \left({x}^{5} \cdot 0.13333333333333333 + {x}^{7} \cdot -0.05396825396825397\right)
Results
Initial program 58.2
Taylor expanded in x around 0 1.9
Simplified1.9
[Start]1.9 | \[ -0.05396825396825397 \cdot {x}^{7} + \left(-0.3333333333333333 \cdot {x}^{3} + \left(0.13333333333333333 \cdot {x}^{5} + x\right)\right)
\] |
|---|---|
rational_best.json-simplify-1 [=>]1.9 | \[ -0.05396825396825397 \cdot {x}^{7} + \left(-0.3333333333333333 \cdot {x}^{3} + \color{blue}{\left(x + 0.13333333333333333 \cdot {x}^{5}\right)}\right)
\] |
rational_best.json-simplify-43 [=>]1.9 | \[ -0.05396825396825397 \cdot {x}^{7} + \color{blue}{\left(0.13333333333333333 \cdot {x}^{5} + \left(x + -0.3333333333333333 \cdot {x}^{3}\right)\right)}
\] |
rational_best.json-simplify-1 [<=]1.9 | \[ -0.05396825396825397 \cdot {x}^{7} + \left(0.13333333333333333 \cdot {x}^{5} + \color{blue}{\left(-0.3333333333333333 \cdot {x}^{3} + x\right)}\right)
\] |
rational_best.json-simplify-43 [=>]1.9 | \[ \color{blue}{\left(-0.3333333333333333 \cdot {x}^{3} + x\right) + \left(0.13333333333333333 \cdot {x}^{5} + -0.05396825396825397 \cdot {x}^{7}\right)}
\] |
rational_best.json-simplify-1 [=>]1.9 | \[ \color{blue}{\left(x + -0.3333333333333333 \cdot {x}^{3}\right)} + \left(0.13333333333333333 \cdot {x}^{5} + -0.05396825396825397 \cdot {x}^{7}\right)
\] |
rational_best.json-simplify-2 [=>]1.9 | \[ \left(x + \color{blue}{{x}^{3} \cdot -0.3333333333333333}\right) + \left(0.13333333333333333 \cdot {x}^{5} + -0.05396825396825397 \cdot {x}^{7}\right)
\] |
rational_best.json-simplify-2 [=>]1.9 | \[ \left(x + {x}^{3} \cdot -0.3333333333333333\right) + \left(\color{blue}{{x}^{5} \cdot 0.13333333333333333} + -0.05396825396825397 \cdot {x}^{7}\right)
\] |
rational_best.json-simplify-2 [=>]1.9 | \[ \left(x + {x}^{3} \cdot -0.3333333333333333\right) + \left({x}^{5} \cdot 0.13333333333333333 + \color{blue}{{x}^{7} \cdot -0.05396825396825397}\right)
\] |
Final simplification1.9
| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 13504 |
| Alternative 2 | |
|---|---|
| Error | 2.0 |
| Cost | 6784 |
| Alternative 3 | |
|---|---|
| Error | 2.2 |
| Cost | 64 |
herbie shell --seed 2023088
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))