| Alternative 1 | |
|---|---|
| Accuracy | 5.0% |
| Cost | 64 |
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))
(FPCore (x) :precision binary64 (/ x (+ 1.0 (* x (* x 0.3333333333333333)))))
double code(double x) {
return (exp(x) - exp(-x)) / (exp(x) + exp(-x));
}
double code(double x) {
return x / (1.0 + (x * (x * 0.3333333333333333)));
}
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 / (1.0d0 + (x * (x * 0.3333333333333333d0)))
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 / (1.0 + (x * (x * 0.3333333333333333)));
}
def code(x): return (math.exp(x) - math.exp(-x)) / (math.exp(x) + math.exp(-x))
def code(x): return x / (1.0 + (x * (x * 0.3333333333333333)))
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / Float64(exp(x) + exp(Float64(-x)))) end
function code(x) return Float64(x / Float64(1.0 + Float64(x * Float64(x * 0.3333333333333333)))) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / (exp(x) + exp(-x)); end
function tmp = code(x) tmp = x / (1.0 + (x * (x * 0.3333333333333333))); 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[(x / N[(1.0 + N[(x * N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{x}{1 + x \cdot \left(x \cdot 0.3333333333333333\right)}
Results
Initial program 9.0%
Taylor expanded in x around 0 7.9%
Simplified7.9%
[Start]7.9 | \[ \frac{e^{x} - e^{-x}}{2 + {x}^{2}}
\] |
|---|---|
unpow2 [=>]7.9 | \[ \frac{e^{x} - e^{-x}}{2 + \color{blue}{x \cdot x}}
\] |
Taylor expanded in x around 0 97.2%
Simplified97.2%
[Start]97.2 | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{2 + x \cdot x}
\] |
|---|---|
unpow3 [=>]97.2 | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)}}{2 + x \cdot x}
\] |
unpow2 [<=]97.2 | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot \left(\color{blue}{{x}^{2}} \cdot x\right)}{2 + x \cdot x}
\] |
associate-*r* [=>]97.2 | \[ \frac{2 \cdot x + \color{blue}{\left(0.3333333333333333 \cdot {x}^{2}\right) \cdot x}}{2 + x \cdot x}
\] |
distribute-rgt-out [=>]97.2 | \[ \frac{\color{blue}{x \cdot \left(2 + 0.3333333333333333 \cdot {x}^{2}\right)}}{2 + x \cdot x}
\] |
+-commutative [<=]97.2 | \[ \frac{x \cdot \color{blue}{\left(0.3333333333333333 \cdot {x}^{2} + 2\right)}}{2 + x \cdot x}
\] |
fma-def [=>]97.2 | \[ \frac{x \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {x}^{2}, 2\right)}}{2 + x \cdot x}
\] |
unpow2 [=>]97.2 | \[ \frac{x \cdot \mathsf{fma}\left(0.3333333333333333, \color{blue}{x \cdot x}, 2\right)}{2 + x \cdot x}
\] |
Applied egg-rr97.2%
[Start]97.2 | \[ \frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{2 + x \cdot x}
\] |
|---|---|
frac-2neg [=>]97.2 | \[ \color{blue}{\frac{-x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{-\left(2 + x \cdot x\right)}}
\] |
distribute-frac-neg [=>]97.2 | \[ \color{blue}{-\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{-\left(2 + x \cdot x\right)}}
\] |
neg-sub0 [=>]97.2 | \[ -\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{\color{blue}{0 - \left(2 + x \cdot x\right)}}
\] |
metadata-eval [<=]97.2 | \[ -\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{\color{blue}{\log 1} - \left(2 + x \cdot x\right)}
\] |
associate--r+ [=>]97.2 | \[ -\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{\color{blue}{\left(\log 1 - 2\right) - x \cdot x}}
\] |
metadata-eval [=>]97.2 | \[ -\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{\left(\color{blue}{0} - 2\right) - x \cdot x}
\] |
metadata-eval [=>]97.2 | \[ -\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{\color{blue}{-2} - x \cdot x}
\] |
Simplified97.2%
[Start]97.2 | \[ -\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{-2 - x \cdot x}
\] |
|---|---|
distribute-neg-frac [=>]97.2 | \[ \color{blue}{\frac{-x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{-2 - x \cdot x}}
\] |
distribute-rgt-neg-out [<=]97.2 | \[ \frac{\color{blue}{x \cdot \left(-\mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)\right)}}{-2 - x \cdot x}
\] |
associate-/l* [=>]97.2 | \[ \color{blue}{\frac{x}{\frac{-2 - x \cdot x}{-\mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}}}
\] |
neg-sub0 [=>]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{\color{blue}{0 - \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}}}
\] |
fma-udef [=>]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{0 - \color{blue}{\left(0.3333333333333333 \cdot \left(x \cdot x\right) + 2\right)}}}
\] |
unpow2 [<=]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{0 - \left(0.3333333333333333 \cdot \color{blue}{{x}^{2}} + 2\right)}}
\] |
*-commutative [=>]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{0 - \left(\color{blue}{{x}^{2} \cdot 0.3333333333333333} + 2\right)}}
\] |
unpow2 [=>]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{0 - \left(\color{blue}{\left(x \cdot x\right)} \cdot 0.3333333333333333 + 2\right)}}
\] |
associate-*r* [<=]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{0 - \left(\color{blue}{x \cdot \left(x \cdot 0.3333333333333333\right)} + 2\right)}}
\] |
+-commutative [=>]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{0 - \color{blue}{\left(2 + x \cdot \left(x \cdot 0.3333333333333333\right)\right)}}}
\] |
associate--r+ [=>]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{\color{blue}{\left(0 - 2\right) - x \cdot \left(x \cdot 0.3333333333333333\right)}}}
\] |
metadata-eval [=>]97.2 | \[ \frac{x}{\frac{-2 - x \cdot x}{\color{blue}{-2} - x \cdot \left(x \cdot 0.3333333333333333\right)}}
\] |
Taylor expanded in x around 0 97.2%
Simplified97.2%
[Start]97.2 | \[ \frac{x}{1 + 0.3333333333333333 \cdot {x}^{2}}
\] |
|---|---|
*-commutative [=>]97.2 | \[ \frac{x}{1 + \color{blue}{{x}^{2} \cdot 0.3333333333333333}}
\] |
unpow2 [=>]97.2 | \[ \frac{x}{1 + \color{blue}{\left(x \cdot x\right)} \cdot 0.3333333333333333}
\] |
associate-*r* [<=]97.2 | \[ \frac{x}{1 + \color{blue}{x \cdot \left(x \cdot 0.3333333333333333\right)}}
\] |
*-commutative [=>]97.2 | \[ \frac{x}{1 + x \cdot \color{blue}{\left(0.3333333333333333 \cdot x\right)}}
\] |
Final simplification97.2%
| Alternative 1 | |
|---|---|
| Accuracy | 5.0% |
| Cost | 64 |
| Alternative 2 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 64 |
herbie shell --seed 2023141
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))