
(FPCore (x) :precision binary64 (atanh x))
double code(double x) {
return atanh(x);
}
def code(x): return math.atanh(x)
function code(x) return atanh(x) end
function tmp = code(x) tmp = atanh(x); end
code[x_] := N[ArcTanh[x], $MachinePrecision]
\begin{array}{l}
\\
\tanh^{-1} x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
double code(double x) {
return 0.5 * log1p(((2.0 * x) / (1.0 - x)));
}
public static double code(double 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)))
function code(x) return Float64(0.5 * log1p(Float64(Float64(2.0 * x) / Float64(1.0 - x)))) end
code[x_] := N[(0.5 * N[Log[1 + N[(N[(2.0 * x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
\end{array}
(FPCore (x) :precision binary64 (* 0.5 (log1p (* (/ (* x -2.0) (+ -1.0 (* x (* x x)))) (+ x (+ (* x x) 1.0))))))
double code(double x) {
return 0.5 * log1p((((x * -2.0) / (-1.0 + (x * (x * x)))) * (x + ((x * x) + 1.0))));
}
public static double code(double x) {
return 0.5 * Math.log1p((((x * -2.0) / (-1.0 + (x * (x * x)))) * (x + ((x * x) + 1.0))));
}
def code(x): return 0.5 * math.log1p((((x * -2.0) / (-1.0 + (x * (x * x)))) * (x + ((x * x) + 1.0))))
function code(x) return Float64(0.5 * log1p(Float64(Float64(Float64(x * -2.0) / Float64(-1.0 + Float64(x * Float64(x * x)))) * Float64(x + Float64(Float64(x * x) + 1.0))))) end
code[x_] := N[(0.5 * N[Log[1 + N[(N[(N[(x * -2.0), $MachinePrecision] / N[(-1.0 + N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x + N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{x \cdot -2}{-1 + x \cdot \left(x \cdot x\right)} \cdot \left(x + \left(x \cdot x + 1\right)\right)\right)
\end{array}
Initial program 100.0%
associate-*l/100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg2100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
*-commutative100.0%
associate-*l/100.0%
metadata-eval100.0%
distribute-lft-neg-in100.0%
flip3-+100.0%
associate-/r/100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
cube-mult100.0%
metadata-eval100.0%
*-commutative100.0%
neg-mul-1100.0%
neg-sub0100.0%
Applied egg-rr100.0%
associate-+r-100.0%
sub-neg100.0%
sub0-neg100.0%
remove-double-neg100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (* 0.5 (log1p (/ (* x 2.0) (- 1.0 x)))))
double code(double x) {
return 0.5 * log1p(((x * 2.0) / (1.0 - x)));
}
public static double code(double x) {
return 0.5 * Math.log1p(((x * 2.0) / (1.0 - x)));
}
def code(x): return 0.5 * math.log1p(((x * 2.0) / (1.0 - x)))
function code(x) return Float64(0.5 * log1p(Float64(Float64(x * 2.0) / Float64(1.0 - x)))) end
code[x_] := N[(0.5 * N[Log[1 + N[(N[(x * 2.0), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{x \cdot 2}{1 - x}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (* 0.5 (log1p (* x (/ -2.0 (+ x -1.0))))))
double code(double x) {
return 0.5 * log1p((x * (-2.0 / (x + -1.0))));
}
public static double code(double x) {
return 0.5 * Math.log1p((x * (-2.0 / (x + -1.0))));
}
def code(x): return 0.5 * math.log1p((x * (-2.0 / (x + -1.0))))
function code(x) return Float64(0.5 * log1p(Float64(x * Float64(-2.0 / Float64(x + -1.0))))) end
code[x_] := N[(0.5 * N[Log[1 + N[(x * N[(-2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(x \cdot \frac{-2}{x + -1}\right)
\end{array}
Initial program 100.0%
associate-*l/100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg2100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
(FPCore (x)
:precision binary64
(*
0.5
(*
x
(+
2.0
(*
x
(*
x
(+
0.6666666666666666
(* (* x x) (+ 0.4 (* (* x x) 0.2857142857142857))))))))))
double code(double x) {
return 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + ((x * x) * (0.4 + ((x * x) * 0.2857142857142857))))))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x * (2.0d0 + (x * (x * (0.6666666666666666d0 + ((x * x) * (0.4d0 + ((x * x) * 0.2857142857142857d0))))))))
end function
public static double code(double x) {
return 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + ((x * x) * (0.4 + ((x * x) * 0.2857142857142857))))))));
}
def code(x): return 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + ((x * x) * (0.4 + ((x * x) * 0.2857142857142857))))))))
function code(x) return Float64(0.5 * Float64(x * Float64(2.0 + Float64(x * Float64(x * Float64(0.6666666666666666 + Float64(Float64(x * x) * Float64(0.4 + Float64(Float64(x * x) * 0.2857142857142857))))))))) end
function tmp = code(x) tmp = 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + ((x * x) * (0.4 + ((x * x) * 0.2857142857142857)))))))); end
code[x_] := N[(0.5 * N[(x * N[(2.0 + N[(x * N[(x * N[(0.6666666666666666 + N[(N[(x * x), $MachinePrecision] * N[(0.4 + N[(N[(x * x), $MachinePrecision] * 0.2857142857142857), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \left(2 + x \cdot \left(x \cdot \left(0.6666666666666666 + \left(x \cdot x\right) \cdot \left(0.4 + \left(x \cdot x\right) \cdot 0.2857142857142857\right)\right)\right)\right)\right)
\end{array}
Initial program 100.0%
associate-*l/100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg2100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.5%
unpow299.5%
associate-*l*99.5%
unpow299.5%
*-commutative99.5%
unpow299.5%
Simplified99.5%
(FPCore (x) :precision binary64 (* 0.5 (* x (+ 2.0 (* x (* x (+ 0.6666666666666666 (* x (* x 0.4)))))))))
double code(double x) {
return 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + (x * (x * 0.4)))))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x * (2.0d0 + (x * (x * (0.6666666666666666d0 + (x * (x * 0.4d0)))))))
end function
public static double code(double x) {
return 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + (x * (x * 0.4)))))));
}
def code(x): return 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + (x * (x * 0.4)))))))
function code(x) return Float64(0.5 * Float64(x * Float64(2.0 + Float64(x * Float64(x * Float64(0.6666666666666666 + Float64(x * Float64(x * 0.4)))))))) end
function tmp = code(x) tmp = 0.5 * (x * (2.0 + (x * (x * (0.6666666666666666 + (x * (x * 0.4))))))); end
code[x_] := N[(0.5 * N[(x * N[(2.0 + N[(x * N[(x * N[(0.6666666666666666 + N[(x * N[(x * 0.4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \left(2 + x \cdot \left(x \cdot \left(0.6666666666666666 + x \cdot \left(x \cdot 0.4\right)\right)\right)\right)\right)
\end{array}
Initial program 100.0%
associate-*l/100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg2100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.5%
unpow299.5%
associate-*l*99.5%
*-commutative99.5%
unpow299.5%
associate-*l*99.5%
Simplified99.5%
(FPCore (x) :precision binary64 (* 0.5 (+ (* x 2.0) (* x (* (* x x) 0.6666666666666666)))))
double code(double x) {
return 0.5 * ((x * 2.0) + (x * ((x * x) * 0.6666666666666666)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * ((x * 2.0d0) + (x * ((x * x) * 0.6666666666666666d0)))
end function
public static double code(double x) {
return 0.5 * ((x * 2.0) + (x * ((x * x) * 0.6666666666666666)));
}
def code(x): return 0.5 * ((x * 2.0) + (x * ((x * x) * 0.6666666666666666)))
function code(x) return Float64(0.5 * Float64(Float64(x * 2.0) + Float64(x * Float64(Float64(x * x) * 0.6666666666666666)))) end
function tmp = code(x) tmp = 0.5 * ((x * 2.0) + (x * ((x * x) * 0.6666666666666666))); end
code[x_] := N[(0.5 * N[(N[(x * 2.0), $MachinePrecision] + N[(x * N[(N[(x * x), $MachinePrecision] * 0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot 2 + x \cdot \left(\left(x \cdot x\right) \cdot 0.6666666666666666\right)\right)
\end{array}
Initial program 100.0%
associate-*l/100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg2100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.2%
*-commutative99.2%
unpow299.2%
associate-*l*99.2%
Simplified99.2%
distribute-lft-in99.2%
associate-*r*99.2%
Applied egg-rr99.2%
(FPCore (x) :precision binary64 (* 0.5 (* x (+ 2.0 (* x (* x 0.6666666666666666))))))
double code(double x) {
return 0.5 * (x * (2.0 + (x * (x * 0.6666666666666666))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x * (2.0d0 + (x * (x * 0.6666666666666666d0))))
end function
public static double code(double x) {
return 0.5 * (x * (2.0 + (x * (x * 0.6666666666666666))));
}
def code(x): return 0.5 * (x * (2.0 + (x * (x * 0.6666666666666666))))
function code(x) return Float64(0.5 * Float64(x * Float64(2.0 + Float64(x * Float64(x * 0.6666666666666666))))) end
function tmp = code(x) tmp = 0.5 * (x * (2.0 + (x * (x * 0.6666666666666666)))); end
code[x_] := N[(0.5 * N[(x * N[(2.0 + N[(x * N[(x * 0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \left(2 + x \cdot \left(x \cdot 0.6666666666666666\right)\right)\right)
\end{array}
Initial program 100.0%
associate-*l/100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg2100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.2%
*-commutative99.2%
unpow299.2%
associate-*l*99.2%
Simplified99.2%
(FPCore (x) :precision binary64 (* 0.5 (* x 2.0)))
double code(double x) {
return 0.5 * (x * 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x * 2.0d0)
end function
public static double code(double x) {
return 0.5 * (x * 2.0);
}
def code(x): return 0.5 * (x * 2.0)
function code(x) return Float64(0.5 * Float64(x * 2.0)) end
function tmp = code(x) tmp = 0.5 * (x * 2.0); end
code[x_] := N[(0.5 * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot 2\right)
\end{array}
Initial program 100.0%
associate-*l/100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg2100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 98.8%
Final simplification98.8%
herbie shell --seed 2024107
(FPCore (x)
:name "Rust f64::atanh"
:precision binary64
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))