Rust f64::atanh

?

Percentage Accurate: 100.0% → 100.0%
Time: 3.9s
Precision: binary64
Cost: 8000

?

\[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
\[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\frac{1 - \left(x \cdot x\right) \cdot \left(x \cdot x\right)}{x \cdot x + 1}} \cdot \left(x + 1\right)\right) \]
(FPCore (x) :precision binary64 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
(FPCore (x)
 :precision binary64
 (*
  0.5
  (log1p
   (*
    (/ (* 2.0 x) (/ (- 1.0 (* (* x x) (* x x))) (+ (* x x) 1.0)))
    (+ x 1.0)))))
double code(double x) {
	return 0.5 * log1p(((2.0 * x) / (1.0 - x)));
}
double code(double x) {
	return 0.5 * log1p((((2.0 * x) / ((1.0 - ((x * x) * (x * x))) / ((x * x) + 1.0))) * (x + 1.0)));
}
public static double code(double x) {
	return 0.5 * Math.log1p(((2.0 * x) / (1.0 - x)));
}
public static double code(double x) {
	return 0.5 * Math.log1p((((2.0 * x) / ((1.0 - ((x * x) * (x * x))) / ((x * x) + 1.0))) * (x + 1.0)));
}
def code(x):
	return 0.5 * math.log1p(((2.0 * x) / (1.0 - x)))
def code(x):
	return 0.5 * math.log1p((((2.0 * x) / ((1.0 - ((x * x) * (x * x))) / ((x * x) + 1.0))) * (x + 1.0)))
function code(x)
	return Float64(0.5 * log1p(Float64(Float64(2.0 * x) / Float64(1.0 - x))))
end
function code(x)
	return Float64(0.5 * log1p(Float64(Float64(Float64(2.0 * x) / Float64(Float64(1.0 - Float64(Float64(x * x) * Float64(x * x))) / Float64(Float64(x * x) + 1.0))) * Float64(x + 1.0))))
end
code[x_] := N[(0.5 * N[Log[1 + N[(N[(2.0 * x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(0.5 * N[Log[1 + N[(N[(N[(2.0 * x), $MachinePrecision] / N[(N[(1.0 - N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\frac{1 - \left(x \cdot x\right) \cdot \left(x \cdot x\right)}{x \cdot x + 1}} \cdot \left(x + 1\right)\right)

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 100.0%

    \[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
  2. Applied egg-rr100.0%

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{2 \cdot x}{1 - x \cdot x} \cdot \left(x + 1\right)}\right) \]
    Step-by-step derivation

    [Start]100.0

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

    flip-- [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\color{blue}{\frac{1 \cdot 1 - x \cdot x}{1 + x}}}\right) \]

    associate-/r/ [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\color{blue}{\frac{2 \cdot x}{1 \cdot 1 - x \cdot x} \cdot \left(1 + x\right)}\right) \]

    metadata-eval [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\color{blue}{1} - x \cdot x} \cdot \left(1 + x\right)\right) \]

    +-commutative [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x \cdot x} \cdot \color{blue}{\left(x + 1\right)}\right) \]
  3. Applied egg-rr100.0%

    \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\color{blue}{\frac{1 - \left(x \cdot \left(-x\right)\right) \cdot \left(x \cdot \left(-x\right)\right)}{1 - x \cdot \left(-x\right)}}} \cdot \left(x + 1\right)\right) \]
    Step-by-step derivation

    [Start]100.0

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

    sub-neg [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\color{blue}{1 + \left(-x \cdot x\right)}} \cdot \left(x + 1\right)\right) \]

    flip-+ [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\color{blue}{\frac{1 \cdot 1 - \left(-x \cdot x\right) \cdot \left(-x \cdot x\right)}{1 - \left(-x \cdot x\right)}}} \cdot \left(x + 1\right)\right) \]

    metadata-eval [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\frac{\color{blue}{1} - \left(-x \cdot x\right) \cdot \left(-x \cdot x\right)}{1 - \left(-x \cdot x\right)}} \cdot \left(x + 1\right)\right) \]

    distribute-rgt-neg-in [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\frac{1 - \color{blue}{\left(x \cdot \left(-x\right)\right)} \cdot \left(-x \cdot x\right)}{1 - \left(-x \cdot x\right)}} \cdot \left(x + 1\right)\right) \]

    distribute-rgt-neg-in [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\frac{1 - \left(x \cdot \left(-x\right)\right) \cdot \color{blue}{\left(x \cdot \left(-x\right)\right)}}{1 - \left(-x \cdot x\right)}} \cdot \left(x + 1\right)\right) \]

    distribute-rgt-neg-in [=>]100.0

    \[ 0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{\frac{1 - \left(x \cdot \left(-x\right)\right) \cdot \left(x \cdot \left(-x\right)\right)}{1 - \color{blue}{x \cdot \left(-x\right)}}} \cdot \left(x + 1\right)\right) \]
  4. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy100.0%
Cost6976
\[0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right) \]
Alternative 2
Accuracy98.9%
Cost320
\[0.5 \cdot \left(2 \cdot x\right) \]

Error

Reproduce?

herbie shell --seed 2023160 
(FPCore (x)
  :name "Rust f64::atanh"
  :precision binary64
  (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))