?

Average Accuracy: 9.0% → 97.2%
Time: 7.2s
Precision: binary64
Cost: 576

?

\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
\[\frac{x}{1 + x \cdot \left(x \cdot 0.3333333333333333\right)} \]
(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)}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 9.0%

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

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

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

    [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}} \]
  4. Taylor expanded in x around 0 97.2%

    \[\leadsto \frac{\color{blue}{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}}{2 + x \cdot x} \]
  5. Simplified97.2%

    \[\leadsto \frac{\color{blue}{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}}{2 + x \cdot x} \]
    Proof

    [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} \]
  6. Applied egg-rr97.2%

    \[\leadsto \color{blue}{-\frac{x \cdot \mathsf{fma}\left(0.3333333333333333, x \cdot x, 2\right)}{-2 - x \cdot x}} \]
    Proof

    [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} \]
  7. Simplified97.2%

    \[\leadsto \color{blue}{\frac{x}{\frac{-2 - x \cdot x}{-2 - x \cdot \left(x \cdot 0.3333333333333333\right)}}} \]
    Proof

    [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)}} \]
  8. Taylor expanded in x around 0 97.2%

    \[\leadsto \frac{x}{\color{blue}{1 + 0.3333333333333333 \cdot {x}^{2}}} \]
  9. Simplified97.2%

    \[\leadsto \frac{x}{\color{blue}{1 + x \cdot \left(0.3333333333333333 \cdot x\right)}} \]
    Proof

    [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)}} \]
  10. Final simplification97.2%

    \[\leadsto \frac{x}{1 + x \cdot \left(x \cdot 0.3333333333333333\right)} \]

Alternatives

Alternative 1
Accuracy5.0%
Cost64
\[1 \]
Alternative 2
Accuracy96.7%
Cost64
\[x \]

Error

Reproduce?

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