
(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);
}
real(4) function code(normangle, u, n0_i, n1_i)
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}
Sampling outcomes in binary32 precision:
Herbie found 9 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);
}
real(4) function code(normangle, u, n0_i, n1_i)
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 u (- (/ n1_i (/ (sin normAngle) normAngle)) n0_i) n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
return fmaf(u, ((n1_i / (sinf(normAngle) / normAngle)) - n0_i), n0_i);
}
function code(normAngle, u, n0_i, n1_i) return fma(u, Float32(Float32(n1_i / Float32(sin(normAngle) / normAngle)) - n0_i), n0_i) end
\begin{array}{l}
\\
\mathsf{fma}\left(u, \frac{n1_i}{\frac{\sin normAngle}{normAngle}} - n0_i, n0_i\right)
\end{array}
Initial program 96.9%
fma-def96.9%
associate-*r/97.1%
*-rgt-identity97.1%
associate-*r/97.7%
*-rgt-identity97.7%
Simplified97.7%
Taylor expanded in u around 0 90.5%
fma-def90.5%
associate-/l*91.7%
associate-/r/91.3%
associate-/l*99.2%
associate-/r/98.8%
Simplified98.8%
Taylor expanded in normAngle around 0 99.0%
Taylor expanded in n0_i around 0 85.6%
+-commutative85.6%
*-commutative85.6%
associate-*l/97.4%
distribute-rgt-in97.6%
*-commutative97.6%
associate-+r+97.6%
+-commutative97.6%
*-lft-identity97.6%
distribute-lft-in97.6%
*-lft-identity97.6%
mul-1-neg97.6%
distribute-rgt-neg-in97.6%
mul-1-neg97.6%
associate-+r+97.7%
+-commutative97.7%
associate-*l/85.8%
*-commutative85.8%
Simplified99.6%
Final simplification99.6%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (+ n0_i (* u (- (/ n1_i (/ (sin normAngle) normAngle)) n0_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
return n0_i + (u * ((n1_i / (sinf(normAngle) / normAngle)) - n0_i));
}
real(4) function code(normangle, u, n0_i, n1_i)
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 + (u * ((n1_i / (sin(normangle) / normangle)) - n0_i))
end function
function code(normAngle, u, n0_i, n1_i) return Float32(n0_i + Float32(u * Float32(Float32(n1_i / Float32(sin(normAngle) / normAngle)) - n0_i))) end
function tmp = code(normAngle, u, n0_i, n1_i) tmp = n0_i + (u * ((n1_i / (sin(normAngle) / normAngle)) - n0_i)); end
\begin{array}{l}
\\
n0_i + u \cdot \left(\frac{n1_i}{\frac{\sin normAngle}{normAngle}} - n0_i\right)
\end{array}
Initial program 96.9%
fma-def96.9%
associate-*r/97.1%
*-rgt-identity97.1%
associate-*r/97.7%
*-rgt-identity97.7%
Simplified97.7%
Taylor expanded in u around 0 90.5%
fma-def90.5%
associate-/l*91.7%
associate-/r/91.3%
associate-/l*99.2%
associate-/r/98.8%
Simplified98.8%
Taylor expanded in normAngle around 0 99.0%
Taylor expanded in u around 0 91.5%
+-commutative91.5%
mul-1-neg91.5%
unsub-neg91.5%
associate-/l*99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (fma u (- n1_i n0_i) n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
return fmaf(u, (n1_i - n0_i), n0_i);
}
function code(normAngle, u, n0_i, n1_i) return fma(u, Float32(n1_i - n0_i), n0_i) end
\begin{array}{l}
\\
\mathsf{fma}\left(u, n1_i - n0_i, n0_i\right)
\end{array}
Initial program 96.9%
fma-def96.9%
associate-*r/97.1%
*-rgt-identity97.1%
associate-*r/97.7%
*-rgt-identity97.7%
Simplified97.7%
Taylor expanded in u around 0 90.5%
fma-def90.5%
associate-/l*91.7%
associate-/r/91.3%
associate-/l*99.2%
associate-/r/98.8%
Simplified98.8%
Taylor expanded in normAngle around 0 99.0%
Taylor expanded in n0_i around 0 85.6%
+-commutative85.6%
*-commutative85.6%
associate-*l/97.4%
distribute-rgt-in97.6%
*-commutative97.6%
associate-+r+97.6%
+-commutative97.6%
*-lft-identity97.6%
distribute-lft-in97.6%
*-lft-identity97.6%
mul-1-neg97.6%
distribute-rgt-neg-in97.6%
mul-1-neg97.6%
associate-+r+97.7%
+-commutative97.7%
associate-*l/85.8%
*-commutative85.8%
Simplified99.6%
Taylor expanded in normAngle around 0 98.1%
Final simplification98.1%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (if (or (<= n1_i -1.999999967550318e-17) (not (<= n1_i 3.99999992980668e-13))) (* u n1_i) (* n0_i (- 1.0 u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
float tmp;
if ((n1_i <= -1.999999967550318e-17f) || !(n1_i <= 3.99999992980668e-13f)) {
tmp = u * n1_i;
} else {
tmp = n0_i * (1.0f - u);
}
return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
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 ((n1_i <= (-1.999999967550318e-17)) .or. (.not. (n1_i <= 3.99999992980668e-13))) then
tmp = u * n1_i
else
tmp = n0_i * (1.0e0 - u)
end if
code = tmp
end function
function code(normAngle, u, n0_i, n1_i) tmp = Float32(0.0) if ((n1_i <= Float32(-1.999999967550318e-17)) || !(n1_i <= Float32(3.99999992980668e-13))) tmp = Float32(u * n1_i); else tmp = Float32(n0_i * Float32(Float32(1.0) - u)); end return tmp end
function tmp_2 = code(normAngle, u, n0_i, n1_i) tmp = single(0.0); if ((n1_i <= single(-1.999999967550318e-17)) || ~((n1_i <= single(3.99999992980668e-13)))) tmp = u * n1_i; else tmp = n0_i * (single(1.0) - u); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n1_i \leq -1.999999967550318 \cdot 10^{-17} \lor \neg \left(n1_i \leq 3.99999992980668 \cdot 10^{-13}\right):\\
\;\;\;\;u \cdot n1_i\\
\mathbf{else}:\\
\;\;\;\;n0_i \cdot \left(1 - u\right)\\
\end{array}
\end{array}
if n1_i < -1.99999997e-17 or 3.99999993e-13 < n1_i Initial program 95.3%
fma-def95.4%
associate-*r/95.4%
*-rgt-identity95.4%
associate-*r/96.8%
*-rgt-identity96.8%
Simplified96.8%
Taylor expanded in normAngle around 0 97.8%
Taylor expanded in n0_i around 0 71.8%
if -1.99999997e-17 < n1_i < 3.99999993e-13Initial program 97.9%
fma-def97.9%
associate-*r/98.3%
*-rgt-identity98.3%
associate-*r/98.4%
*-rgt-identity98.4%
Simplified98.4%
Taylor expanded in u around 0 88.0%
fma-def88.0%
associate-/l*90.0%
associate-/r/90.0%
associate-/l*99.8%
associate-/r/99.8%
Simplified99.8%
Taylor expanded in normAngle around 0 99.5%
Taylor expanded in n0_i around inf 77.2%
mul-1-neg77.2%
sub-neg77.2%
Simplified77.2%
Final simplification75.1%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (if (or (<= n1_i -1.999999967550318e-17) (not (<= n1_i 3.99999992980668e-13))) (* u n1_i) n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
float tmp;
if ((n1_i <= -1.999999967550318e-17f) || !(n1_i <= 3.99999992980668e-13f)) {
tmp = u * n1_i;
} else {
tmp = n0_i;
}
return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
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 ((n1_i <= (-1.999999967550318e-17)) .or. (.not. (n1_i <= 3.99999992980668e-13))) then
tmp = u * n1_i
else
tmp = n0_i
end if
code = tmp
end function
function code(normAngle, u, n0_i, n1_i) tmp = Float32(0.0) if ((n1_i <= Float32(-1.999999967550318e-17)) || !(n1_i <= Float32(3.99999992980668e-13))) tmp = Float32(u * n1_i); else tmp = n0_i; end return tmp end
function tmp_2 = code(normAngle, u, n0_i, n1_i) tmp = single(0.0); if ((n1_i <= single(-1.999999967550318e-17)) || ~((n1_i <= single(3.99999992980668e-13)))) tmp = u * n1_i; else tmp = n0_i; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n1_i \leq -1.999999967550318 \cdot 10^{-17} \lor \neg \left(n1_i \leq 3.99999992980668 \cdot 10^{-13}\right):\\
\;\;\;\;u \cdot n1_i\\
\mathbf{else}:\\
\;\;\;\;n0_i\\
\end{array}
\end{array}
if n1_i < -1.99999997e-17 or 3.99999993e-13 < n1_i Initial program 95.3%
fma-def95.4%
associate-*r/95.4%
*-rgt-identity95.4%
associate-*r/96.8%
*-rgt-identity96.8%
Simplified96.8%
Taylor expanded in normAngle around 0 97.8%
Taylor expanded in n0_i around 0 71.8%
if -1.99999997e-17 < n1_i < 3.99999993e-13Initial program 97.9%
fma-def97.9%
associate-*r/98.3%
*-rgt-identity98.3%
associate-*r/98.4%
*-rgt-identity98.4%
Simplified98.4%
Taylor expanded in u around 0 62.5%
Final simplification66.1%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (if (<= n0_i -5.00000006675716e-11) (* n0_i (- 1.0 u)) (+ n0_i (* u n1_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
float tmp;
if (n0_i <= -5.00000006675716e-11f) {
tmp = n0_i * (1.0f - u);
} else {
tmp = n0_i + (u * n1_i);
}
return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
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 <= (-5.00000006675716e-11)) then
tmp = n0_i * (1.0e0 - u)
else
tmp = n0_i + (u * n1_i)
end if
code = tmp
end function
function code(normAngle, u, n0_i, n1_i) tmp = Float32(0.0) if (n0_i <= Float32(-5.00000006675716e-11)) tmp = Float32(n0_i * Float32(Float32(1.0) - u)); else tmp = Float32(n0_i + Float32(u * n1_i)); end return tmp end
function tmp_2 = code(normAngle, u, n0_i, n1_i) tmp = single(0.0); if (n0_i <= single(-5.00000006675716e-11)) tmp = n0_i * (single(1.0) - u); else tmp = n0_i + (u * n1_i); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n0_i \leq -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;n0_i \cdot \left(1 - u\right)\\
\mathbf{else}:\\
\;\;\;\;n0_i + u \cdot n1_i\\
\end{array}
\end{array}
if n0_i < -5.00000007e-11Initial program 96.2%
fma-def96.2%
associate-*r/96.3%
*-rgt-identity96.3%
associate-*r/99.3%
*-rgt-identity99.3%
Simplified99.3%
Taylor expanded in u around 0 98.7%
fma-def98.7%
associate-/l*99.9%
associate-/r/96.7%
associate-/l*96.8%
associate-/r/96.8%
Simplified96.8%
Taylor expanded in normAngle around 0 100.0%
Taylor expanded in n0_i around inf 96.3%
mul-1-neg96.3%
sub-neg96.3%
Simplified96.3%
if -5.00000007e-11 < n0_i Initial program 97.0%
fma-def97.1%
associate-*r/97.2%
*-rgt-identity97.2%
associate-*r/97.5%
*-rgt-identity97.5%
Simplified97.5%
Taylor expanded in u around 0 89.3%
fma-def89.3%
associate-/l*90.5%
associate-/r/90.5%
associate-/l*99.6%
associate-/r/99.1%
Simplified99.1%
Taylor expanded in n0_i around 0 74.0%
Taylor expanded in normAngle around 0 86.5%
*-commutative86.5%
Simplified86.5%
Final simplification87.8%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (if (<= n0_i -5.00000006675716e-11) (- n0_i (* u n0_i)) (+ n0_i (* u n1_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
float tmp;
if (n0_i <= -5.00000006675716e-11f) {
tmp = n0_i - (u * n0_i);
} else {
tmp = n0_i + (u * n1_i);
}
return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
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 <= (-5.00000006675716e-11)) then
tmp = n0_i - (u * n0_i)
else
tmp = n0_i + (u * n1_i)
end if
code = tmp
end function
function code(normAngle, u, n0_i, n1_i) tmp = Float32(0.0) if (n0_i <= Float32(-5.00000006675716e-11)) tmp = Float32(n0_i - Float32(u * n0_i)); else tmp = Float32(n0_i + Float32(u * n1_i)); end return tmp end
function tmp_2 = code(normAngle, u, n0_i, n1_i) tmp = single(0.0); if (n0_i <= single(-5.00000006675716e-11)) tmp = n0_i - (u * n0_i); else tmp = n0_i + (u * n1_i); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n0_i \leq -5.00000006675716 \cdot 10^{-11}:\\
\;\;\;\;n0_i - u \cdot n0_i\\
\mathbf{else}:\\
\;\;\;\;n0_i + u \cdot n1_i\\
\end{array}
\end{array}
if n0_i < -5.00000007e-11Initial program 96.2%
fma-def96.2%
associate-*r/96.3%
*-rgt-identity96.3%
associate-*r/99.3%
*-rgt-identity99.3%
Simplified99.3%
Taylor expanded in u around 0 98.7%
fma-def98.7%
associate-/l*99.9%
associate-/r/96.7%
associate-/l*96.8%
associate-/r/96.8%
Simplified96.8%
Taylor expanded in normAngle around 0 100.0%
Taylor expanded in n0_i around inf 96.8%
mul-1-neg96.8%
distribute-lft-neg-out96.8%
*-commutative96.8%
Simplified96.8%
if -5.00000007e-11 < n0_i Initial program 97.0%
fma-def97.1%
associate-*r/97.2%
*-rgt-identity97.2%
associate-*r/97.5%
*-rgt-identity97.5%
Simplified97.5%
Taylor expanded in u around 0 89.3%
fma-def89.3%
associate-/l*90.5%
associate-/r/90.5%
associate-/l*99.6%
associate-/r/99.1%
Simplified99.1%
Taylor expanded in n0_i around 0 74.0%
Taylor expanded in normAngle around 0 86.5%
*-commutative86.5%
Simplified86.5%
Final simplification87.8%
(FPCore (normAngle u n0_i n1_i) :precision binary32 (+ n0_i (* u (- n1_i n0_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
return n0_i + (u * (n1_i - n0_i));
}
real(4) function code(normangle, u, n0_i, n1_i)
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 + (u * (n1_i - n0_i))
end function
function code(normAngle, u, n0_i, n1_i) return Float32(n0_i + Float32(u * Float32(n1_i - n0_i))) end
function tmp = code(normAngle, u, n0_i, n1_i) tmp = n0_i + (u * (n1_i - n0_i)); end
\begin{array}{l}
\\
n0_i + u \cdot \left(n1_i - n0_i\right)
\end{array}
Initial program 96.9%
fma-def96.9%
associate-*r/97.1%
*-rgt-identity97.1%
associate-*r/97.7%
*-rgt-identity97.7%
Simplified97.7%
Taylor expanded in normAngle around 0 97.7%
Taylor expanded in u around -inf 98.0%
mul-1-neg98.0%
unsub-neg98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Final simplification98.0%
(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;
}
real(4) function code(normangle, u, n0_i, n1_i)
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 96.9%
fma-def96.9%
associate-*r/97.1%
*-rgt-identity97.1%
associate-*r/97.7%
*-rgt-identity97.7%
Simplified97.7%
Taylor expanded in u around 0 46.3%
Final simplification46.3%
herbie shell --seed 2023301
(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)))