
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (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);
}
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}
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}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (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);
}
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}
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}
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (let* ((t_0 (/ 1.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 = 1.0f / expf((fabsf(x) / s));
float t_1 = 1.0f + t_0;
return t_0 / ((s * t_1) * t_1);
}
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 = 1.0e0 / 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 = Float32(Float32(1.0) / exp(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 = single(1.0) / exp((abs(x) / s)); t_1 = single(1.0) + t_0; tmp = t_0 / ((s * t_1) * t_1); end
\begin{array}{l}
t_0 := \frac{1}{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}
Initial program 99.5%
Applied rewrites99.5%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (let* ((t_0 (exp (/ (fabs x) s)))) (/ 1.0 (* s (* (+ 1.0 t_0) (+ 1.0 (/ 1.0 t_0)))))))
float code(float x, float s) {
float t_0 = expf((fabsf(x) / s));
return 1.0f / (s * ((1.0f + t_0) * (1.0f + (1.0f / t_0))));
}
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 = 1.0e0 / (s * ((1.0e0 + t_0) * (1.0e0 + (1.0e0 / t_0))))
end function
function code(x, s) t_0 = exp(Float32(abs(x) / s)) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(1.0) + t_0) * Float32(Float32(1.0) + Float32(Float32(1.0) / t_0))))) end
function tmp = code(x, s) t_0 = exp((abs(x) / s)); tmp = single(1.0) / (s * ((single(1.0) + t_0) * (single(1.0) + (single(1.0) / t_0)))); end
\begin{array}{l}
t_0 := e^{\frac{\left|x\right|}{s}}\\
\frac{1}{s \cdot \left(\left(1 + t\_0\right) \cdot \left(1 + \frac{1}{t\_0}\right)\right)}
\end{array}
Initial program 99.5%
Applied rewrites99.5%
Taylor expanded in s around inf
Applied rewrites53.3%
Applied rewrites35.6%
Taylor expanded in s around 0
Applied rewrites99.5%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (let* ((t_0 (exp (/ (fabs x) s)))) (/ 1.0 (* (+ 1.0 t_0) (+ s (/ s t_0))))))
float code(float x, float s) {
float t_0 = expf((fabsf(x) / s));
return 1.0f / ((1.0f + t_0) * (s + (s / t_0)));
}
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 = 1.0e0 / ((1.0e0 + t_0) * (s + (s / t_0)))
end function
function code(x, s) t_0 = exp(Float32(abs(x) / s)) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + t_0) * Float32(s + Float32(s / t_0)))) end
function tmp = code(x, s) t_0 = exp((abs(x) / s)); tmp = single(1.0) / ((single(1.0) + t_0) * (s + (s / t_0))); end
\begin{array}{l}
t_0 := e^{\frac{\left|x\right|}{s}}\\
\frac{1}{\left(1 + t\_0\right) \cdot \left(s + \frac{s}{t\_0}\right)}
\end{array}
Initial program 99.5%
Applied rewrites99.5%
Taylor expanded in s around inf
Applied rewrites53.3%
Applied rewrites35.6%
Taylor expanded in x around 0
Applied rewrites99.5%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (let* ((t_0 (+ 2.0 (* -1.0 (/ (fabs x) s))))) (/ (exp (/ (- (fabs x)) s)) (* (* s t_0) t_0))))
float code(float x, float s) {
float t_0 = 2.0f + (-1.0f * (fabsf(x) / s));
return expf((-fabsf(x) / s)) / ((s * t_0) * t_0);
}
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 = 2.0e0 + ((-1.0e0) * (abs(x) / s))
code = exp((-abs(x) / s)) / ((s * t_0) * t_0)
end function
function code(x, s) t_0 = Float32(Float32(2.0) + Float32(Float32(-1.0) * Float32(abs(x) / s))) return Float32(exp(Float32(Float32(-abs(x)) / s)) / Float32(Float32(s * t_0) * t_0)) end
function tmp = code(x, s) t_0 = single(2.0) + (single(-1.0) * (abs(x) / s)); tmp = exp((-abs(x) / s)) / ((s * t_0) * t_0); end
\begin{array}{l}
t_0 := 2 + -1 \cdot \frac{\left|x\right|}{s}\\
\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot t\_0\right) \cdot t\_0}
\end{array}
Initial program 99.5%
Taylor expanded in s around inf
Applied rewrites96.0%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (let* ((t_0 (exp (/ (- (fabs x)) s)))) (/ t_0 (* (+ s s) (+ 1.0 t_0)))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
return t_0 / ((s + s) * (1.0f + t_0));
}
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 + s) * (1.0e0 + t_0))
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) return Float32(t_0 / Float32(Float32(s + s) * Float32(Float32(1.0) + t_0))) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); tmp = t_0 / ((s + s) * (single(1.0) + t_0)); end
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{t\_0}{\left(s + s\right) \cdot \left(1 + t\_0\right)}
\end{array}
Initial program 99.5%
Taylor expanded in s around inf
Applied rewrites94.9%
Applied rewrites94.9%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (/ 0.25 (* (pow E (/ (fabs x) s)) s)))
float code(float x, float s) {
return 0.25f / (powf(((float) M_E), (fabsf(x) / s)) * s);
}
function code(x, s) return Float32(Float32(0.25) / Float32((Float32(exp(1)) ^ Float32(abs(x) / s)) * s)) end
function tmp = code(x, s) tmp = single(0.25) / ((single(2.71828182845904523536) ^ (abs(x) / s)) * s); end
\frac{0.25}{{e}^{\left(\frac{\left|x\right|}{s}\right)} \cdot s}
Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.5%
Taylor expanded in s around inf
Applied rewrites94.6%
Applied rewrites94.6%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (/ 0.25 (* (exp (/ (fabs x) s)) s)))
float code(float x, float s) {
return 0.25f / (expf((fabsf(x) / s)) * s);
}
real(4) function code(x, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.25e0 / (exp((abs(x) / s)) * s)
end function
function code(x, s) return Float32(Float32(0.25) / Float32(exp(Float32(abs(x) / s)) * s)) end
function tmp = code(x, s) tmp = single(0.25) / (exp((abs(x) / s)) * s); end
\frac{0.25}{e^{\frac{\left|x\right|}{s}} \cdot s}
Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.5%
Taylor expanded in s around inf
Applied rewrites94.6%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (/ 0.25 (* (+ 1.0 (/ (fabs x) s)) s)))
float code(float x, float s) {
return 0.25f / ((1.0f + (fabsf(x) / s)) * s);
}
real(4) function code(x, s)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.25e0 / ((1.0e0 + (abs(x) / s)) * s)
end function
function code(x, s) return Float32(Float32(0.25) / Float32(Float32(Float32(1.0) + Float32(abs(x) / s)) * s)) end
function tmp = code(x, s) tmp = single(0.25) / ((single(1.0) + (abs(x) / s)) * s); end
\frac{0.25}{\left(1 + \frac{\left|x\right|}{s}\right) \cdot s}
Initial program 99.5%
Applied rewrites99.5%
Applied rewrites99.5%
Taylor expanded in s around inf
Applied rewrites94.6%
Taylor expanded in s around inf
Applied rewrites51.2%
(FPCore (x s) :precision binary32 :pre (and (<= 0.0 s) (<= s 1.0651631)) (/ 0.25 s))
float code(float x, float s) {
return 0.25f / s;
}
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
\frac{0.25}{s}
Initial program 99.5%
Taylor expanded in s around inf
Applied rewrites27.5%
herbie shell --seed 2026086
(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))))))