
(FPCore (normAngle u n0_i n1_i)
:precision binary32
(let* ((t_0 (/ 1.0 (sin normAngle))))
(+
(* (* (sin (* (- 1.0 u) normAngle)) t_0) n0_i)
(* (* (sin (* u normAngle)) t_0) n1_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
float t_0 = 1.0f / sinf(normAngle);
return ((sinf(((1.0f - u) * normAngle)) * t_0) * n0_i) + ((sinf((u * normAngle)) * t_0) * n1_i);
}
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(normangle, u, n0_i, n1_i)
use fmin_fmax_functions
real(4), intent (in) :: normangle
real(4), intent (in) :: u
real(4), intent (in) :: n0_i
real(4), intent (in) :: n1_i
real(4) :: t_0
t_0 = 1.0e0 / sin(normangle)
code = ((sin(((1.0e0 - u) * normangle)) * t_0) * n0_i) + ((sin((u * normangle)) * t_0) * n1_i)
end function
function code(normAngle, u, n0_i, n1_i) t_0 = Float32(Float32(1.0) / sin(normAngle)) return Float32(Float32(Float32(sin(Float32(Float32(Float32(1.0) - u) * normAngle)) * t_0) * n0_i) + Float32(Float32(sin(Float32(u * normAngle)) * t_0) * n1_i)) end
function tmp = code(normAngle, u, n0_i, n1_i) t_0 = single(1.0) / sin(normAngle); tmp = ((sin(((single(1.0) - u) * normAngle)) * t_0) * n0_i) + ((sin((u * normAngle)) * t_0) * n1_i); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sin normAngle}\\
\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot t\_0\right) \cdot n0\_i + \left(\sin \left(u \cdot normAngle\right) \cdot t\_0\right) \cdot n1\_i
\end{array}
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (normAngle u n0_i n1_i)
:precision binary32
(let* ((t_0 (/ 1.0 (sin normAngle))))
(+
(* (* (sin (* (- 1.0 u) normAngle)) t_0) n0_i)
(* (* (sin (* u normAngle)) t_0) n1_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
float t_0 = 1.0f / sinf(normAngle);
return ((sinf(((1.0f - u) * normAngle)) * t_0) * n0_i) + ((sinf((u * normAngle)) * t_0) * n1_i);
}
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(normangle, u, n0_i, n1_i)
use fmin_fmax_functions
real(4), intent (in) :: normangle
real(4), intent (in) :: u
real(4), intent (in) :: n0_i
real(4), intent (in) :: n1_i
real(4) :: t_0
t_0 = 1.0e0 / sin(normangle)
code = ((sin(((1.0e0 - u) * normangle)) * t_0) * n0_i) + ((sin((u * normangle)) * t_0) * n1_i)
end function
function code(normAngle, u, n0_i, n1_i) t_0 = Float32(Float32(1.0) / sin(normAngle)) return Float32(Float32(Float32(sin(Float32(Float32(Float32(1.0) - u) * normAngle)) * t_0) * n0_i) + Float32(Float32(sin(Float32(u * normAngle)) * t_0) * n1_i)) end
function tmp = code(normAngle, u, n0_i, n1_i) t_0 = single(1.0) / sin(normAngle); tmp = ((sin(((single(1.0) - u) * normAngle)) * t_0) * n0_i) + ((sin((u * normAngle)) * t_0) * n1_i); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sin normAngle}\\
\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot t\_0\right) \cdot n0\_i + \left(\sin \left(u \cdot normAngle\right) \cdot t\_0\right) \cdot n1\_i
\end{array}
\end{array}
(FPCore (normAngle u n0_i n1_i)
:precision binary32
(fma
(+
(fma
(fma 0.3333333333333333 n0_i (* 0.16666666666666666 n1_i))
(* normAngle normAngle)
(- n0_i))
n1_i)
u
n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
return fmaf((fmaf(fmaf(0.3333333333333333f, n0_i, (0.16666666666666666f * n1_i)), (normAngle * normAngle), -n0_i) + n1_i), u, n0_i);
}
function code(normAngle, u, n0_i, n1_i) return fma(Float32(fma(fma(Float32(0.3333333333333333), n0_i, Float32(Float32(0.16666666666666666) * n1_i)), Float32(normAngle * normAngle), Float32(-n0_i)) + n1_i), u, n0_i) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, n0\_i, 0.16666666666666666 \cdot n1\_i\right), normAngle \cdot normAngle, -n0\_i\right) + n1\_i, u, n0\_i\right)
\end{array}
Initial program 97.2%
Taylor expanded in normAngle around 0
*-commutativeN/A
lower-fma.f32N/A
lift--.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.9%
Taylor expanded in n0_i around 0
+-commutativeN/A
lower-fma.f32N/A
lower-*.f3298.9
Applied rewrites98.9%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (fma (+ (fma (* 0.16666666666666666 n1_i) (* normAngle normAngle) (- n0_i)) n1_i) u n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
return fmaf((fmaf((0.16666666666666666f * n1_i), (normAngle * normAngle), -n0_i) + n1_i), u, n0_i);
}
function code(normAngle, u, n0_i, n1_i) return fma(Float32(fma(Float32(Float32(0.16666666666666666) * n1_i), Float32(normAngle * normAngle), Float32(-n0_i)) + n1_i), u, n0_i) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666 \cdot n1\_i, normAngle \cdot normAngle, -n0\_i\right) + n1\_i, u, n0\_i\right)
\end{array}
Initial program 97.2%
Taylor expanded in normAngle around 0
*-commutativeN/A
lower-fma.f32N/A
lift--.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.9%
Taylor expanded in n0_i around 0
lower-*.f3298.7
Applied rewrites98.7%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (if (<= n0_i -1.999999936531045e-19) n0_i (if (<= n0_i 9.999999887266023e-27) (* n1_i u) n0_i)))
float code(float normAngle, float u, float n0_i, float n1_i) {
float tmp;
if (n0_i <= -1.999999936531045e-19f) {
tmp = n0_i;
} else if (n0_i <= 9.999999887266023e-27f) {
tmp = n1_i * u;
} else {
tmp = n0_i;
}
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(normangle, u, n0_i, n1_i)
use fmin_fmax_functions
real(4), intent (in) :: normangle
real(4), intent (in) :: u
real(4), intent (in) :: n0_i
real(4), intent (in) :: n1_i
real(4) :: tmp
if (n0_i <= (-1.999999936531045e-19)) then
tmp = n0_i
else if (n0_i <= 9.999999887266023e-27) then
tmp = n1_i * u
else
tmp = n0_i
end if
code = tmp
end function
function code(normAngle, u, n0_i, n1_i) tmp = Float32(0.0) if (n0_i <= Float32(-1.999999936531045e-19)) tmp = n0_i; elseif (n0_i <= Float32(9.999999887266023e-27)) tmp = Float32(n1_i * u); else tmp = n0_i; end return tmp end
function tmp_2 = code(normAngle, u, n0_i, n1_i) tmp = single(0.0); if (n0_i <= single(-1.999999936531045e-19)) tmp = n0_i; elseif (n0_i <= single(9.999999887266023e-27)) tmp = n1_i * u; else tmp = n0_i; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n0\_i \leq -1.999999936531045 \cdot 10^{-19}:\\
\;\;\;\;n0\_i\\
\mathbf{elif}\;n0\_i \leq 9.999999887266023 \cdot 10^{-27}:\\
\;\;\;\;n1\_i \cdot u\\
\mathbf{else}:\\
\;\;\;\;n0\_i\\
\end{array}
\end{array}
if n0_i < -1.99999994e-19 or 9.99999989e-27 < n0_i Initial program 98.0%
Taylor expanded in u around 0
Applied rewrites59.8%
if -1.99999994e-19 < n0_i < 9.99999989e-27Initial program 96.1%
Taylor expanded in n0_i around 0
associate-/l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-/.f32N/A
lift-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-sin.f3261.4
Applied rewrites61.4%
Taylor expanded in normAngle around 0
Applied rewrites61.8%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (if (<= n0_i -1.999999967550318e-17) (* n0_i (- 1.0 u)) (fma n1_i u n0_i)))
float code(float normAngle, float u, float n0_i, float n1_i) {
float tmp;
if (n0_i <= -1.999999967550318e-17f) {
tmp = n0_i * (1.0f - u);
} else {
tmp = fmaf(n1_i, u, n0_i);
}
return tmp;
}
function code(normAngle, u, n0_i, n1_i) tmp = Float32(0.0) if (n0_i <= Float32(-1.999999967550318e-17)) tmp = Float32(n0_i * Float32(Float32(1.0) - u)); else tmp = fma(n1_i, u, n0_i); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n0\_i \leq -1.999999967550318 \cdot 10^{-17}:\\
\;\;\;\;n0\_i \cdot \left(1 - u\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\
\end{array}
\end{array}
if n0_i < -1.99999997e-17Initial program 98.1%
Taylor expanded in n0_i around inf
associate-/l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-/.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-sin.f32N/A
lift-sin.f3282.3
Applied rewrites82.3%
Taylor expanded in normAngle around 0
lift--.f3281.9
Applied rewrites81.9%
if -1.99999997e-17 < n0_i Initial program 97.0%
Taylor expanded in normAngle around 0
*-commutativeN/A
lower-fma.f32N/A
lift--.f32N/A
+-commutativeN/A
Applied rewrites98.7%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.8%
Taylor expanded in n0_i around 0
+-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
pow2N/A
lift-*.f3284.1
Applied rewrites84.1%
Taylor expanded in normAngle around 0
Applied rewrites83.4%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (fma (- n1_i n0_i) u n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
return fmaf((n1_i - n0_i), u, n0_i);
}
function code(normAngle, u, n0_i, n1_i) return fma(Float32(n1_i - n0_i), u, n0_i) end
\begin{array}{l}
\\
\mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)
\end{array}
Initial program 97.2%
Taylor expanded in normAngle around 0
*-commutativeN/A
lower-fma.f32N/A
lift--.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.9%
Taylor expanded in normAngle around 0
lower--.f3298.0
Applied rewrites98.0%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (fma n1_i u n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
return fmaf(n1_i, u, n0_i);
}
function code(normAngle, u, n0_i, n1_i) return fma(n1_i, u, n0_i) end
\begin{array}{l}
\\
\mathsf{fma}\left(n1\_i, u, n0\_i\right)
\end{array}
Initial program 97.2%
Taylor expanded in normAngle around 0
*-commutativeN/A
lower-fma.f32N/A
lift--.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites98.9%
Taylor expanded in n0_i around 0
+-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
pow2N/A
lift-*.f3282.2
Applied rewrites82.2%
Taylor expanded in normAngle around 0
Applied rewrites81.6%
(FPCore (normAngle u n0_i n1_i) :precision binary32 n0_i)
float code(float normAngle, float u, float n0_i, float n1_i) {
return n0_i;
}
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(normangle, u, n0_i, n1_i)
use fmin_fmax_functions
real(4), intent (in) :: normangle
real(4), intent (in) :: u
real(4), intent (in) :: n0_i
real(4), intent (in) :: n1_i
code = n0_i
end function
function code(normAngle, u, n0_i, n1_i) return n0_i end
function tmp = code(normAngle, u, n0_i, n1_i) tmp = n0_i; end
\begin{array}{l}
\\
n0\_i
\end{array}
Initial program 97.2%
Taylor expanded in u around 0
Applied rewrites47.4%
herbie shell --seed 2025103
(FPCore (normAngle u n0_i n1_i)
:name "Curve intersection, scale width based on ribbon orientation"
:precision binary32
:pre (and (and (and (and (<= 0.0 normAngle) (<= normAngle (/ PI 2.0))) (and (<= -1.0 n0_i) (<= n0_i 1.0))) (and (<= -1.0 n1_i) (<= n1_i 1.0))) (and (<= 2.328306437e-10 u) (<= u 1.0)))
(+ (* (* (sin (* (- 1.0 u) normAngle)) (/ 1.0 (sin normAngle))) n0_i) (* (* (sin (* u normAngle)) (/ 1.0 (sin normAngle))) n1_i)))