Average Error: 58.5 → 0.0
Time: 6.4s
Precision: binary64
Cost: 13440
\[\frac{1}{2} \cdot \log \left(\frac{1 + x}{1 - x}\right) \]
\[0.5 \cdot \left(\mathsf{log1p}\left(x\right) \cdot 2 - \mathsf{log1p}\left(x \cdot \left(-x\right)\right)\right) \]
(FPCore (x) :precision binary64 (* (/ 1.0 2.0) (log (/ (+ 1.0 x) (- 1.0 x)))))
(FPCore (x)
 :precision binary64
 (* 0.5 (- (* (log1p x) 2.0) (log1p (* x (- x))))))
double code(double x) {
	return (1.0 / 2.0) * log(((1.0 + x) / (1.0 - x)));
}
double code(double x) {
	return 0.5 * ((log1p(x) * 2.0) - log1p((x * -x)));
}
public static double code(double x) {
	return (1.0 / 2.0) * Math.log(((1.0 + x) / (1.0 - x)));
}
public static double code(double x) {
	return 0.5 * ((Math.log1p(x) * 2.0) - Math.log1p((x * -x)));
}
def code(x):
	return (1.0 / 2.0) * math.log(((1.0 + x) / (1.0 - x)))
def code(x):
	return 0.5 * ((math.log1p(x) * 2.0) - math.log1p((x * -x)))
function code(x)
	return Float64(Float64(1.0 / 2.0) * log(Float64(Float64(1.0 + x) / Float64(1.0 - x))))
end
function code(x)
	return Float64(0.5 * Float64(Float64(log1p(x) * 2.0) - log1p(Float64(x * Float64(-x)))))
end
code[x_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[Log[N[(N[(1.0 + x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(0.5 * N[(N[(N[Log[1 + x], $MachinePrecision] * 2.0), $MachinePrecision] - N[Log[1 + N[(x * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{2} \cdot \log \left(\frac{1 + x}{1 - x}\right)
0.5 \cdot \left(\mathsf{log1p}\left(x\right) \cdot 2 - \mathsf{log1p}\left(x \cdot \left(-x\right)\right)\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 58.5

    \[\frac{1}{2} \cdot \log \left(\frac{1 + x}{1 - x}\right) \]
  2. Simplified58.5

    \[\leadsto \color{blue}{0.5 \cdot \log \left(\frac{1 + x}{1 - x}\right)} \]
    Proof
    (*.f64 1/2 (log.f64 (/.f64 (+.f64 1 x) (-.f64 1 x)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (Rewrite<= metadata-eval (/.f64 1 2)) (log.f64 (/.f64 (+.f64 1 x) (-.f64 1 x)))): 0 points increase in error, 2 points decrease in error
  3. Applied egg-rr58.5

    \[\leadsto 0.5 \cdot \color{blue}{\left(-\log \left(\frac{1 - x}{1 + x}\right)\right)} \]
  4. Applied egg-rr0.5

    \[\leadsto 0.5 \cdot \left(-\color{blue}{\left(\log \left(1 - x \cdot x\right) - \left(\mathsf{log1p}\left(x\right) + \mathsf{log1p}\left(x\right)\right)\right)}\right) \]
  5. Simplified0.0

    \[\leadsto 0.5 \cdot \left(-\color{blue}{\left(\mathsf{log1p}\left(x \cdot \left(-x\right)\right) + -2 \cdot \mathsf{log1p}\left(x\right)\right)}\right) \]
    Proof
    (*.f64 1/2 (neg.f64 (+.f64 (log1p.f64 (*.f64 x (neg.f64 x))) (*.f64 -2 (log1p.f64 x))))): 0 points increase in error, 0 points decrease in error
    (*.f64 1/2 (neg.f64 (+.f64 (log1p.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 x x)))) (*.f64 -2 (log1p.f64 x))))): 0 points increase in error, 0 points decrease in error
    (*.f64 1/2 (neg.f64 (+.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (*.f64 x x))))) (*.f64 -2 (log1p.f64 x))))): 0 points increase in error, 0 points decrease in error
    (*.f64 1/2 (neg.f64 (+.f64 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (*.f64 x x)))) (*.f64 -2 (log1p.f64 x))))): 0 points increase in error, 0 points decrease in error
    (*.f64 1/2 (neg.f64 (+.f64 (log.f64 (-.f64 1 (*.f64 x x))) (*.f64 (Rewrite<= metadata-eval (neg.f64 2)) (log1p.f64 x))))): 0 points increase in error, 0 points decrease in error
    (*.f64 1/2 (neg.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (log.f64 (-.f64 1 (*.f64 x x))) (*.f64 2 (log1p.f64 x)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 1/2 (neg.f64 (-.f64 (log.f64 (-.f64 1 (*.f64 x x))) (Rewrite<= count-2_binary64 (+.f64 (log1p.f64 x) (log1p.f64 x)))))): 0 points increase in error, 0 points decrease in error
  6. Final simplification0.0

    \[\leadsto 0.5 \cdot \left(\mathsf{log1p}\left(x\right) \cdot 2 - \mathsf{log1p}\left(x \cdot \left(-x\right)\right)\right) \]

Alternatives

Alternative 1
Error0.0
Cost13184
\[0.5 \cdot \left(\mathsf{log1p}\left(x\right) - \mathsf{log1p}\left(-x\right)\right) \]
Alternative 2
Error0.4
Cost7040
\[0.5 \cdot \left(x \cdot 2 + 0.6666666666666666 \cdot {x}^{3}\right) \]
Alternative 3
Error0.7
Cost320
\[0.5 \cdot \left(x \cdot 2\right) \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x)
  :name "Hyperbolic arc-(co)tangent"
  :precision binary64
  (* (/ 1.0 2.0) (log (/ (+ 1.0 x) (- 1.0 x)))))