
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
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(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v); end
\begin{array}{l}
\\
\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
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(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v); end
\begin{array}{l}
\\
\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}
\end{array}
cosTheta_i\_m = (fabs.f32 cosTheta_i) cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i) NOTE: cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function. (FPCore (cosTheta_i_s cosTheta_i_m cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* cosTheta_i_s (* (/ (* (/ cosTheta_O v) cosTheta_i_m) v) (/ (exp (/ (* sinTheta_O sinTheta_i) (- v))) (* (sinh (/ 1.0 v)) 2.0)))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
assert(cosTheta_i_m < cosTheta_O && cosTheta_O < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return cosTheta_i_s * ((((cosTheta_O / v) * cosTheta_i_m) / v) * (expf(((sinTheta_O * sinTheta_i) / -v)) / (sinhf((1.0f / v)) * 2.0f)));
}
cosTheta_i\_m = private
cosTheta_i\_s = private
NOTE: cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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(costheta_i_s, costheta_i_m, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
real(4), intent (in) :: costheta_i_s
real(4), intent (in) :: costheta_i_m
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = costheta_i_s * ((((costheta_o / v) * costheta_i_m) / v) * (exp(((sintheta_o * sintheta_i) / -v)) / (sinh((1.0e0 / v)) * 2.0e0)))
end function
cosTheta_i\_m = abs(cosTheta_i) cosTheta_i\_s = copysign(1.0, cosTheta_i) cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v]) function code(cosTheta_i_s, cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(cosTheta_i_s * Float32(Float32(Float32(Float32(cosTheta_O / v) * cosTheta_i_m) / v) * Float32(exp(Float32(Float32(sinTheta_O * sinTheta_i) / Float32(-v))) / Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0))))) end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_i_s, cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v)
tmp = cosTheta_i_s * ((((cosTheta_O / v) * cosTheta_i_m) / v) * (exp(((sinTheta_O * sinTheta_i) / -v)) / (sinh((single(1.0) / v)) * single(2.0))));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
[cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_i\_s \cdot \left(\frac{\frac{cosTheta\_O}{v} \cdot cosTheta\_i\_m}{v} \cdot \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2}\right)
\end{array}
Initial program 98.7%
Taylor expanded in cosTheta_i around 0
associate-*r*N/A
distribute-neg-frac2N/A
*-commutativeN/A
distribute-neg-frac2N/A
times-fracN/A
lower-*.f32N/A
unpow2N/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
lower-/.f32N/A
Applied rewrites98.7%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
associate-*r/N/A
lower-/.f32N/A
lower-*.f32N/A
lift-/.f3298.8
Applied rewrites98.8%
Final simplification98.8%
cosTheta_i\_m = (fabs.f32 cosTheta_i) cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i) NOTE: cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function. (FPCore (cosTheta_i_s cosTheta_i_m cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* cosTheta_i_s (* (* cosTheta_O (/ cosTheta_i_m (* v v))) (/ (exp (/ (* sinTheta_O sinTheta_i) (- v))) (* (sinh (/ 1.0 v)) 2.0)))))
cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
assert(cosTheta_i_m < cosTheta_O && cosTheta_O < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return cosTheta_i_s * ((cosTheta_O * (cosTheta_i_m / (v * v))) * (expf(((sinTheta_O * sinTheta_i) / -v)) / (sinhf((1.0f / v)) * 2.0f)));
}
cosTheta_i\_m = private
cosTheta_i\_s = private
NOTE: cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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(costheta_i_s, costheta_i_m, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
real(4), intent (in) :: costheta_i_s
real(4), intent (in) :: costheta_i_m
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = costheta_i_s * ((costheta_o * (costheta_i_m / (v * v))) * (exp(((sintheta_o * sintheta_i) / -v)) / (sinh((1.0e0 / v)) * 2.0e0)))
end function
cosTheta_i\_m = abs(cosTheta_i) cosTheta_i\_s = copysign(1.0, cosTheta_i) cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v]) function code(cosTheta_i_s, cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(cosTheta_i_s * Float32(Float32(cosTheta_O * Float32(cosTheta_i_m / Float32(v * v))) * Float32(exp(Float32(Float32(sinTheta_O * sinTheta_i) / Float32(-v))) / Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0))))) end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_i_s, cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v)
tmp = cosTheta_i_s * ((cosTheta_O * (cosTheta_i_m / (v * v))) * (exp(((sinTheta_O * sinTheta_i) / -v)) / (sinh((single(1.0) / v)) * single(2.0))));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
[cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_i\_s \cdot \left(\left(cosTheta\_O \cdot \frac{cosTheta\_i\_m}{v \cdot v}\right) \cdot \frac{e^{\frac{sinTheta\_O \cdot sinTheta\_i}{-v}}}{\sinh \left(\frac{1}{v}\right) \cdot 2}\right)
\end{array}
Initial program 98.7%
Taylor expanded in cosTheta_i around 0
associate-*r*N/A
distribute-neg-frac2N/A
*-commutativeN/A
distribute-neg-frac2N/A
times-fracN/A
lower-*.f32N/A
unpow2N/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
lower-/.f32N/A
Applied rewrites98.7%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
unpow2N/A
associate-/l*N/A
lower-*.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f3298.7
Applied rewrites98.7%
Final simplification98.7%
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
NOTE: cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_i_s cosTheta_i_m cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(*
cosTheta_i_s
(*
cosTheta_O
(/
(* (/ cosTheta_i_m v) (pow (exp sinTheta_O) (/ sinTheta_i (- v))))
(* (sinh (/ 1.0 v)) (* 2.0 v))))))cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
assert(cosTheta_i_m < cosTheta_O && cosTheta_O < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return cosTheta_i_s * (cosTheta_O * (((cosTheta_i_m / v) * powf(expf(sinTheta_O), (sinTheta_i / -v))) / (sinhf((1.0f / v)) * (2.0f * v))));
}
cosTheta_i\_m = private
cosTheta_i\_s = private
NOTE: cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
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(costheta_i_s, costheta_i_m, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
real(4), intent (in) :: costheta_i_s
real(4), intent (in) :: costheta_i_m
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = costheta_i_s * (costheta_o * (((costheta_i_m / v) * (exp(sintheta_o) ** (sintheta_i / -v))) / (sinh((1.0e0 / v)) * (2.0e0 * v))))
end function
cosTheta_i\_m = abs(cosTheta_i) cosTheta_i\_s = copysign(1.0, cosTheta_i) cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v]) function code(cosTheta_i_s, cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(cosTheta_i_s * Float32(cosTheta_O * Float32(Float32(Float32(cosTheta_i_m / v) * (exp(sinTheta_O) ^ Float32(sinTheta_i / Float32(-v)))) / Float32(sinh(Float32(Float32(1.0) / v)) * Float32(Float32(2.0) * v))))) end
cosTheta_i\_m = abs(cosTheta_i);
cosTheta_i\_s = sign(cosTheta_i) * abs(1.0);
cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v = num2cell(sort([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v])){:}
function tmp = code(cosTheta_i_s, cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v)
tmp = cosTheta_i_s * (cosTheta_O * (((cosTheta_i_m / v) * (exp(sinTheta_O) ^ (sinTheta_i / -v))) / (sinh((single(1.0) / v)) * (single(2.0) * v))));
end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
[cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v])\\
\\
cosTheta\_i\_s \cdot \left(cosTheta\_O \cdot \frac{\frac{cosTheta\_i\_m}{v} \cdot {\left(e^{sinTheta\_O}\right)}^{\left(\frac{sinTheta\_i}{-v}\right)}}{\sinh \left(\frac{1}{v}\right) \cdot \left(2 \cdot v\right)}\right)
\end{array}
Initial program 98.7%
Taylor expanded in cosTheta_i around 0
associate-*r*N/A
distribute-neg-frac2N/A
*-commutativeN/A
distribute-neg-frac2N/A
times-fracN/A
lower-*.f32N/A
unpow2N/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
lower-/.f32N/A
Applied rewrites98.7%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
unpow2N/A
associate-/l*N/A
lower-*.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f3298.7
Applied rewrites98.7%
Applied rewrites98.7%
Final simplification98.7%
cosTheta_i\_m = (fabs.f32 cosTheta_i)
cosTheta_i\_s = (copysign.f32 #s(literal 1 binary32) cosTheta_i)
NOTE: cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, and v should be sorted in increasing order before calling this function.
(FPCore (cosTheta_i_s cosTheta_i_m cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(let* ((t_0 (sinh (/ 1.0 v))) (t_1 (* 2.0 t_0)))
(*
cosTheta_i_s
(fma
(fma
(fma
(/
(/
(* (* (* sinTheta_i sinTheta_i) cosTheta_i_m) cosTheta_O)
(pow v 4.0))
t_1)
0.5
(*
(/
(/
(* (* (* (pow sinTheta_i 3.0) sinTheta_O) cosTheta_i_m) cosTheta_O)
(pow v 5.0))
t_1)
-0.16666666666666666))
sinTheta_O
(/
(/ (* (* cosTheta_i_m sinTheta_i) cosTheta_O) (pow v 3.0))
(* (- 2.0) t_0)))
sinTheta_O
(/ (/ (* (/ cosTheta_O v) cosTheta_i_m) v) t_1)))))cosTheta_i\_m = fabs(cosTheta_i);
cosTheta_i\_s = copysign(1.0, cosTheta_i);
assert(cosTheta_i_m < cosTheta_O && cosTheta_O < sinTheta_i && sinTheta_i < sinTheta_O && sinTheta_O < v);
float code(float cosTheta_i_s, float cosTheta_i_m, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
float t_0 = sinhf((1.0f / v));
float t_1 = 2.0f * t_0;
return cosTheta_i_s * fmaf(fmaf(fmaf((((((sinTheta_i * sinTheta_i) * cosTheta_i_m) * cosTheta_O) / powf(v, 4.0f)) / t_1), 0.5f, ((((((powf(sinTheta_i, 3.0f) * sinTheta_O) * cosTheta_i_m) * cosTheta_O) / powf(v, 5.0f)) / t_1) * -0.16666666666666666f)), sinTheta_O, ((((cosTheta_i_m * sinTheta_i) * cosTheta_O) / powf(v, 3.0f)) / (-2.0f * t_0))), sinTheta_O, ((((cosTheta_O / v) * cosTheta_i_m) / v) / t_1));
}
cosTheta_i\_m = abs(cosTheta_i) cosTheta_i\_s = copysign(1.0, cosTheta_i) cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v = sort([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v]) function code(cosTheta_i_s, cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v) t_0 = sinh(Float32(Float32(1.0) / v)) t_1 = Float32(Float32(2.0) * t_0) return Float32(cosTheta_i_s * fma(fma(fma(Float32(Float32(Float32(Float32(Float32(sinTheta_i * sinTheta_i) * cosTheta_i_m) * cosTheta_O) / (v ^ Float32(4.0))) / t_1), Float32(0.5), Float32(Float32(Float32(Float32(Float32(Float32((sinTheta_i ^ Float32(3.0)) * sinTheta_O) * cosTheta_i_m) * cosTheta_O) / (v ^ Float32(5.0))) / t_1) * Float32(-0.16666666666666666))), sinTheta_O, Float32(Float32(Float32(Float32(cosTheta_i_m * sinTheta_i) * cosTheta_O) / (v ^ Float32(3.0))) / Float32(Float32(-Float32(2.0)) * t_0))), sinTheta_O, Float32(Float32(Float32(Float32(cosTheta_O / v) * cosTheta_i_m) / v) / t_1))) end
\begin{array}{l}
cosTheta_i\_m = \left|cosTheta\_i\right|
\\
cosTheta_i\_s = \mathsf{copysign}\left(1, cosTheta\_i\right)
\\
[cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v] = \mathsf{sort}([cosTheta_i_m, cosTheta_O, sinTheta_i, sinTheta_O, v])\\
\\
\begin{array}{l}
t_0 := \sinh \left(\frac{1}{v}\right)\\
t_1 := 2 \cdot t\_0\\
cosTheta\_i\_s \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{\frac{\left(\left(sinTheta\_i \cdot sinTheta\_i\right) \cdot cosTheta\_i\_m\right) \cdot cosTheta\_O}{{v}^{4}}}{t\_1}, 0.5, \frac{\frac{\left(\left({sinTheta\_i}^{3} \cdot sinTheta\_O\right) \cdot cosTheta\_i\_m\right) \cdot cosTheta\_O}{{v}^{5}}}{t\_1} \cdot -0.16666666666666666\right), sinTheta\_O, \frac{\frac{\left(cosTheta\_i\_m \cdot sinTheta\_i\right) \cdot cosTheta\_O}{{v}^{3}}}{\left(-2\right) \cdot t\_0}\right), sinTheta\_O, \frac{\frac{\frac{cosTheta\_O}{v} \cdot cosTheta\_i\_m}{v}}{t\_1}\right)
\end{array}
\end{array}
Initial program 98.7%
Taylor expanded in cosTheta_i around 0
associate-*r*N/A
distribute-neg-frac2N/A
*-commutativeN/A
distribute-neg-frac2N/A
times-fracN/A
lower-*.f32N/A
unpow2N/A
times-fracN/A
lower-*.f32N/A
lower-/.f32N/A
lower-/.f32N/A
Applied rewrites98.7%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
associate-*r/N/A
lower-/.f32N/A
lower-*.f32N/A
lift-/.f3298.8
Applied rewrites98.8%
Taylor expanded in sinTheta_O around 0
Applied rewrites98.4%
Final simplification98.4%
herbie shell --seed 2025059
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:name "HairBSDF, Mp, upper"
:precision binary32
:pre (and (and (and (and (and (and (<= -1.0 cosTheta_i) (<= cosTheta_i 1.0)) (and (<= -1.0 cosTheta_O) (<= cosTheta_O 1.0))) (and (<= -1.0 sinTheta_i) (<= sinTheta_i 1.0))) (and (<= -1.0 sinTheta_O) (<= sinTheta_O 1.0))) (< 0.1 v)) (<= v 1.5707964))
(/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))