
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0))) (/ t_0 (* (* s t_1) t_1))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
float t_1 = 1.0f + t_0;
return t_0 / ((s * t_1) * t_1);
}
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, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: t_1
t_0 = exp((-abs(x) / s))
t_1 = 1.0e0 + t_0
code = t_0 / ((s * t_1) * t_1)
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) t_1 = Float32(Float32(1.0) + t_0) return Float32(t_0 / Float32(Float32(s * t_1) * t_1)) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); t_1 = single(1.0) + t_0; tmp = t_0 / ((s * t_1) * t_1); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t\_0\\
\frac{t\_0}{\left(s \cdot t\_1\right) \cdot t\_1}
\end{array}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0))) (/ t_0 (* (* s t_1) t_1))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
float t_1 = 1.0f + t_0;
return t_0 / ((s * t_1) * t_1);
}
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, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: t_1
t_0 = exp((-abs(x) / s))
t_1 = 1.0e0 + t_0
code = t_0 / ((s * t_1) * t_1)
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) t_1 = Float32(Float32(1.0) + t_0) return Float32(t_0 / Float32(Float32(s * t_1) * t_1)) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); t_1 = single(1.0) + t_0; tmp = t_0 / ((s * t_1) * t_1); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t\_0\\
\frac{t\_0}{\left(s \cdot t\_1\right) \cdot t\_1}
\end{array}
\end{array}
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s)))) (/ (/ t_0 (fma t_0 s s)) (- t_0 -1.0))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
return (t_0 / fmaf(t_0, s, s)) / (t_0 - -1.0f);
}
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) return Float32(Float32(t_0 / fma(t_0, s, s)) / Float32(t_0 - Float32(-1.0))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{\frac{t\_0}{\mathsf{fma}\left(t\_0, s, s\right)}}{t\_0 - -1}
\end{array}
\end{array}
Initial program 99.6%
lift-/.f32N/A
lift-exp.f32N/A
lift-/.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift-exp.f32N/A
lift-/.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
lift-+.f32N/A
Applied rewrites99.6%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s)))) (/ t_0 (* (fma t_0 s s) (- t_0 -1.0)))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
return t_0 / (fmaf(t_0, s, s) * (t_0 - -1.0f));
}
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) return Float32(t_0 / Float32(fma(t_0, s, s) * Float32(t_0 - Float32(-1.0)))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{t\_0}{\mathsf{fma}\left(t\_0, s, s\right) \cdot \left(t\_0 - -1\right)}
\end{array}
\end{array}
Initial program 99.6%
lift-*.f32N/A
lift-+.f32N/A
lift-exp.f32N/A
lift-/.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f32N/A
lift-neg.f32N/A
lift-fabs.f32N/A
lift-/.f32N/A
lift-exp.f3299.6
lift-+.f32N/A
Applied rewrites99.6%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s)))) (* (/ (pow (- t_0 -1.0) -2.0) s) t_0)))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
return (powf((t_0 - -1.0f), -2.0f) / s) * t_0;
}
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, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((-abs(x) / s))
code = (((t_0 - (-1.0e0)) ** (-2.0e0)) / s) * t_0
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) return Float32(Float32((Float32(t_0 - Float32(-1.0)) ^ Float32(-2.0)) / s) * t_0) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); tmp = (((t_0 - single(-1.0)) ^ single(-2.0)) / s) * t_0; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{{\left(t\_0 - -1\right)}^{-2}}{s} \cdot t\_0
\end{array}
\end{array}
Initial program 99.6%
Applied rewrites99.4%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s)))) (* (/ t_0 s) (pow (- t_0 -1.0) -2.0))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
return (t_0 / s) * powf((t_0 - -1.0f), -2.0f);
}
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, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((-abs(x) / s))
code = (t_0 / s) * ((t_0 - (-1.0e0)) ** (-2.0e0))
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) return Float32(Float32(t_0 / s) * (Float32(t_0 - Float32(-1.0)) ^ Float32(-2.0))) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); tmp = (t_0 / s) * ((t_0 - single(-1.0)) ^ single(-2.0)); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{t\_0}{s} \cdot {\left(t\_0 - -1\right)}^{-2}
\end{array}
\end{array}
Initial program 99.6%
Applied rewrites99.6%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s)))) (/ t_0 (* (fma t_0 s s) 2.0))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
return t_0 / (fmaf(t_0, s, s) * 2.0f);
}
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) return Float32(t_0 / Float32(fma(t_0, s, s) * Float32(2.0))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{t\_0}{\mathsf{fma}\left(t\_0, s, s\right) \cdot 2}
\end{array}
\end{array}
Initial program 99.6%
lift-*.f32N/A
lift-+.f32N/A
lift-exp.f32N/A
lift-/.f32N/A
lift-fabs.f32N/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f32N/A
lift-neg.f32N/A
lift-fabs.f32N/A
lift-/.f32N/A
lift-exp.f3299.6
lift-+.f32N/A
Applied rewrites99.6%
Taylor expanded in s around inf
Applied rewrites95.0%
(FPCore (x s) :precision binary32 (/ (exp (/ (- (fabs x)) s)) (* 4.0 s)))
float code(float x, float s) {
return expf((-fabsf(x) / s)) / (4.0f * s);
}
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, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
code = exp((-abs(x) / s)) / (4.0e0 * s)
end function
function code(x, s) return Float32(exp(Float32(Float32(-abs(x)) / s)) / Float32(Float32(4.0) * s)) end
function tmp = code(x, s) tmp = exp((-abs(x) / s)) / (single(4.0) * s); end
\begin{array}{l}
\\
\frac{e^{\frac{-\left|x\right|}{s}}}{4 \cdot s}
\end{array}
Initial program 99.6%
Taylor expanded in s around inf
lower-*.f3294.7
Applied rewrites94.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0)))
(if (<= (/ t_0 (* (* s t_1) t_1)) 3.999999975690116e-8)
(* (* (* (/ 0.25 (* x x)) x) x) (/ 1.0 s))
(/ (fma (* (/ x s) (/ x s)) -0.0625 0.25) s))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
float t_1 = 1.0f + t_0;
float tmp;
if ((t_0 / ((s * t_1) * t_1)) <= 3.999999975690116e-8f) {
tmp = (((0.25f / (x * x)) * x) * x) * (1.0f / s);
} else {
tmp = fmaf(((x / s) * (x / s)), -0.0625f, 0.25f) / s;
}
return tmp;
}
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) t_1 = Float32(Float32(1.0) + t_0) tmp = Float32(0.0) if (Float32(t_0 / Float32(Float32(s * t_1) * t_1)) <= Float32(3.999999975690116e-8)) tmp = Float32(Float32(Float32(Float32(Float32(0.25) / Float32(x * x)) * x) * x) * Float32(Float32(1.0) / s)); else tmp = Float32(fma(Float32(Float32(x / s) * Float32(x / s)), Float32(-0.0625), Float32(0.25)) / s); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t\_0\\
\mathbf{if}\;\frac{t\_0}{\left(s \cdot t\_1\right) \cdot t\_1} \leq 3.999999975690116 \cdot 10^{-8}:\\
\;\;\;\;\left(\left(\frac{0.25}{x \cdot x} \cdot x\right) \cdot x\right) \cdot \frac{1}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{s} \cdot \frac{x}{s}, -0.0625, 0.25\right)}{s}\\
\end{array}
\end{array}
if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 3.99999998e-8Initial program 99.6%
Taylor expanded in s around inf
lower-/.f32N/A
Applied rewrites21.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mult-flip-revN/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
mult-flip-revN/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
pow2N/A
lift-*.f328.5
Applied rewrites8.5%
Taylor expanded in x around 0
pow2N/A
lift-/.f32N/A
lift-*.f328.0
Applied rewrites8.0%
lift-/.f32N/A
mult-flipN/A
lower-*.f32N/A
Applied rewrites35.0%
if 3.99999998e-8 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) Initial program 99.6%
Taylor expanded in s around inf
lower-/.f32N/A
Applied rewrites21.2%
lift--.f32N/A
lift-*.f32N/A
lift-/.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
sub-flipN/A
Applied rewrites22.1%
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
lower-/.f3226.1
Applied rewrites26.1%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0)))
(if (<= (/ t_0 (* (* s t_1) t_1)) 3.999999975690116e-8)
(/ (* (* (/ 0.25 (* x x)) x) x) s)
(/ (fma (* (/ x s) (/ x s)) -0.0625 0.25) s))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
float t_1 = 1.0f + t_0;
float tmp;
if ((t_0 / ((s * t_1) * t_1)) <= 3.999999975690116e-8f) {
tmp = (((0.25f / (x * x)) * x) * x) / s;
} else {
tmp = fmaf(((x / s) * (x / s)), -0.0625f, 0.25f) / s;
}
return tmp;
}
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) t_1 = Float32(Float32(1.0) + t_0) tmp = Float32(0.0) if (Float32(t_0 / Float32(Float32(s * t_1) * t_1)) <= Float32(3.999999975690116e-8)) tmp = Float32(Float32(Float32(Float32(Float32(0.25) / Float32(x * x)) * x) * x) / s); else tmp = Float32(fma(Float32(Float32(x / s) * Float32(x / s)), Float32(-0.0625), Float32(0.25)) / s); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t\_0\\
\mathbf{if}\;\frac{t\_0}{\left(s \cdot t\_1\right) \cdot t\_1} \leq 3.999999975690116 \cdot 10^{-8}:\\
\;\;\;\;\frac{\left(\frac{0.25}{x \cdot x} \cdot x\right) \cdot x}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{s} \cdot \frac{x}{s}, -0.0625, 0.25\right)}{s}\\
\end{array}
\end{array}
if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 3.99999998e-8Initial program 99.6%
Taylor expanded in s around inf
lower-/.f32N/A
Applied rewrites21.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mult-flip-revN/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
mult-flip-revN/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
pow2N/A
lift-*.f328.5
Applied rewrites8.5%
Taylor expanded in x around 0
pow2N/A
lift-/.f32N/A
lift-*.f328.0
Applied rewrites8.0%
*-commutative8.0
+-commutative8.0
distribute-lft1-in8.0
+-commutative8.0
metadata-eval8.0
sub-flip8.0
Applied rewrites35.1%
if 3.99999998e-8 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) Initial program 99.6%
Taylor expanded in s around inf
lower-/.f32N/A
Applied rewrites21.2%
lift--.f32N/A
lift-*.f32N/A
lift-/.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
sub-flipN/A
Applied rewrites22.1%
lift-*.f32N/A
lift-*.f32N/A
lift-/.f32N/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
lower-/.f3226.1
Applied rewrites26.1%
(FPCore (x s) :precision binary32 (if (<= x 3.5000000675466936e-9) (/ 0.25 s) (/ (* (* (/ 0.25 (* x x)) x) x) s)))
float code(float x, float s) {
float tmp;
if (x <= 3.5000000675466936e-9f) {
tmp = 0.25f / s;
} else {
tmp = (((0.25f / (x * x)) * x) * x) / s;
}
return tmp;
}
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, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 3.5000000675466936e-9) then
tmp = 0.25e0 / s
else
tmp = (((0.25e0 / (x * x)) * x) * x) / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(3.5000000675466936e-9)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(Float32(Float32(0.25) / Float32(x * x)) * x) * x) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(3.5000000675466936e-9)) tmp = single(0.25) / s; else tmp = (((single(0.25) / (x * x)) * x) * x) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.5000000675466936 \cdot 10^{-9}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{0.25}{x \cdot x} \cdot x\right) \cdot x}{s}\\
\end{array}
\end{array}
if x < 3.50000007e-9Initial program 99.6%
Taylor expanded in s around inf
lower-/.f3226.4
Applied rewrites26.4%
if 3.50000007e-9 < x Initial program 99.6%
Taylor expanded in s around inf
lower-/.f32N/A
Applied rewrites21.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mult-flip-revN/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
mult-flip-revN/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
pow2N/A
lift-*.f328.5
Applied rewrites8.5%
Taylor expanded in x around 0
pow2N/A
lift-/.f32N/A
lift-*.f328.0
Applied rewrites8.0%
*-commutative8.0
+-commutative8.0
distribute-lft1-in8.0
+-commutative8.0
metadata-eval8.0
sub-flip8.0
Applied rewrites35.1%
(FPCore (x s) :precision binary32 (/ 0.25 s))
float code(float x, float s) {
return 0.25f / s;
}
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, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.25e0 / s
end function
function code(x, s) return Float32(Float32(0.25) / s) end
function tmp = code(x, s) tmp = single(0.25) / s; end
\begin{array}{l}
\\
\frac{0.25}{s}
\end{array}
Initial program 99.6%
Taylor expanded in s around inf
lower-/.f3226.4
Applied rewrites26.4%
herbie shell --seed 2025129
(FPCore (x s)
:name "Logistic distribution"
:precision binary32
:pre (and (<= 0.0 s) (<= s 1.0651631))
(/ (exp (/ (- (fabs x)) s)) (* (* s (+ 1.0 (exp (/ (- (fabs x)) s)))) (+ 1.0 (exp (/ (- (fabs x)) s))))))