
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
float code(float x) {
return 0.5f * log1pf(((2.0f * x) / (1.0f - x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * x) / Float32(Float32(1.0) - x)))) end
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
float code(float x) {
return 0.5f * log1pf(((2.0f * x) / (1.0f - x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * x) / Float32(Float32(1.0) - x)))) end
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
(FPCore (x) :precision binary32 (* (copysign 1.0 x) (* 0.5 (log1p (/ (+ (fabs x) (fabs x)) (- 1.0 (fabs x)))))))
float code(float x) {
return copysignf(1.0f, x) * (0.5f * log1pf(((fabsf(x) + fabsf(x)) / (1.0f - fabsf(x)))));
}
function code(x) return Float32(copysign(Float32(1.0), x) * Float32(Float32(0.5) * log1p(Float32(Float32(abs(x) + abs(x)) / Float32(Float32(1.0) - abs(x)))))) end
\mathsf{copysign}\left(1, x\right) \cdot \left(0.5 \cdot \mathsf{log1p}\left(\frac{\left|x\right| + \left|x\right|}{1 - \left|x\right|}\right)\right)
Initial program 99.8%
lift-*.f32N/A
count-2-revN/A
lower-+.f3299.8%
Applied rewrites99.8%
(FPCore (x)
:precision binary32
(*
(copysign 1.0 x)
(if (<= (fabs x) 0.004000000189989805)
(fabs x)
(* (log (fma (/ -2.0 (- (fabs x) 1.0)) (fabs x) 1.0)) 0.5))))float code(float x) {
float tmp;
if (fabsf(x) <= 0.004000000189989805f) {
tmp = fabsf(x);
} else {
tmp = logf(fmaf((-2.0f / (fabsf(x) - 1.0f)), fabsf(x), 1.0f)) * 0.5f;
}
return copysignf(1.0f, x) * tmp;
}
function code(x) tmp = Float32(0.0) if (abs(x) <= Float32(0.004000000189989805)) tmp = abs(x); else tmp = Float32(log(fma(Float32(Float32(-2.0) / Float32(abs(x) - Float32(1.0))), abs(x), Float32(1.0))) * Float32(0.5)); end return Float32(copysign(Float32(1.0), x) * tmp) end
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.004000000189989805:\\
\;\;\;\;\left|x\right|\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(\frac{-2}{\left|x\right| - 1}, \left|x\right|, 1\right)\right) \cdot 0.5\\
\end{array}
if x < 0.00400000019Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites97.0%
if 0.00400000019 < x Initial program 99.8%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3299.8%
lift-log1p.f32N/A
lower-log.f32N/A
+-commutativeN/A
metadata-evalN/A
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f32N/A
frac-2negN/A
lower-/.f32N/A
metadata-evalN/A
lift--.f32N/A
sub-negate-revN/A
lower--.f3223.6%
Applied rewrites23.6%
(FPCore (x)
:precision binary32
(*
(copysign 1.0 x)
(if (<= (fabs x) 0.004000000189989805)
(fabs x)
(* (log (fma -2.0 (/ (fabs x) (- (fabs x) 1.0)) 1.0)) 0.5))))float code(float x) {
float tmp;
if (fabsf(x) <= 0.004000000189989805f) {
tmp = fabsf(x);
} else {
tmp = logf(fmaf(-2.0f, (fabsf(x) / (fabsf(x) - 1.0f)), 1.0f)) * 0.5f;
}
return copysignf(1.0f, x) * tmp;
}
function code(x) tmp = Float32(0.0) if (abs(x) <= Float32(0.004000000189989805)) tmp = abs(x); else tmp = Float32(log(fma(Float32(-2.0), Float32(abs(x) / Float32(abs(x) - Float32(1.0))), Float32(1.0))) * Float32(0.5)); end return Float32(copysign(Float32(1.0), x) * tmp) end
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.004000000189989805:\\
\;\;\;\;\left|x\right|\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(-2, \frac{\left|x\right|}{\left|x\right| - 1}, 1\right)\right) \cdot 0.5\\
\end{array}
if x < 0.00400000019Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites97.0%
if 0.00400000019 < x Initial program 99.8%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3299.8%
lift-log1p.f32N/A
lower-log.f32N/A
+-commutativeN/A
metadata-evalN/A
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f32N/A
frac-2negN/A
lower-/.f32N/A
metadata-evalN/A
lift--.f32N/A
sub-negate-revN/A
lower--.f3223.6%
Applied rewrites23.6%
lift-fma.f32N/A
lift-/.f32N/A
lift--.f32N/A
lift--.f32N/A
associate-*l/N/A
associate-/l*N/A
lower-fma.f32N/A
lower-/.f3223.6%
Applied rewrites23.6%
(FPCore (x)
:precision binary32
(*
(copysign 1.0 x)
(if (<= (fabs x) 0.004999999888241291)
(fabs x)
(log (sqrt (fma (/ -2.0 (- (fabs x) 1.0)) (fabs x) 1.0))))))float code(float x) {
float tmp;
if (fabsf(x) <= 0.004999999888241291f) {
tmp = fabsf(x);
} else {
tmp = logf(sqrtf(fmaf((-2.0f / (fabsf(x) - 1.0f)), fabsf(x), 1.0f)));
}
return copysignf(1.0f, x) * tmp;
}
function code(x) tmp = Float32(0.0) if (abs(x) <= Float32(0.004999999888241291)) tmp = abs(x); else tmp = log(sqrt(fma(Float32(Float32(-2.0) / Float32(abs(x) - Float32(1.0))), abs(x), Float32(1.0)))); end return Float32(copysign(Float32(1.0), x) * tmp) end
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.004999999888241291:\\
\;\;\;\;\left|x\right|\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{\mathsf{fma}\left(\frac{-2}{\left|x\right| - 1}, \left|x\right|, 1\right)}\right)\\
\end{array}
if x < 0.00499999989Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites97.0%
if 0.00499999989 < x Initial program 99.8%
lift-*.f32N/A
lift-log1p.f32N/A
log-pow-revN/A
lower-log.f32N/A
unpow1/2N/A
lower-sqrt.f32N/A
+-commutativeN/A
metadata-evalN/A
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f32N/A
frac-2negN/A
lower-/.f32N/A
metadata-evalN/A
lift--.f32N/A
sub-negate-revN/A
lower--.f3222.8%
Applied rewrites22.8%
(FPCore (x) :precision binary32 x)
float code(float x) {
return x;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(4) function code(x)
use fmin_fmax_functions
real(4), intent (in) :: x
code = x
end function
function code(x) return x end
function tmp = code(x) tmp = x; end
x
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites97.0%
herbie shell --seed 2025183
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))