| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 3552 |
\[n0_i + u \cdot \left(n1_i \cdot \frac{normAngle}{\sin normAngle} - n0_i\right)
\]
(FPCore (normAngle u n0_i n1_i) :precision binary32 (+ (* (* (sin (* (- 1.0 u) normAngle)) (/ 1.0 (sin normAngle))) n0_i) (* (* (sin (* u normAngle)) (/ 1.0 (sin normAngle))) n1_i)))
(FPCore (normAngle u n0_i n1_i)
:precision binary32
(fma
u
n1_i
(fma
(* normAngle normAngle)
(+
(* 0.16666666666666666 (* n0_i (- (- 1.0 (pow (- 1.0 u) 3.0)) u)))
(* -0.16666666666666666 (* n1_i (- (pow u 3.0) u))))
(* (- 1.0 u) n0_i))))float code(float normAngle, float u, float n0_i, float n1_i) {
return ((sinf(((1.0f - u) * normAngle)) * (1.0f / sinf(normAngle))) * n0_i) + ((sinf((u * normAngle)) * (1.0f / sinf(normAngle))) * n1_i);
}
float code(float normAngle, float u, float n0_i, float n1_i) {
return fmaf(u, n1_i, fmaf((normAngle * normAngle), ((0.16666666666666666f * (n0_i * ((1.0f - powf((1.0f - u), 3.0f)) - u))) + (-0.16666666666666666f * (n1_i * (powf(u, 3.0f) - u)))), ((1.0f - u) * n0_i)));
}
function code(normAngle, u, n0_i, n1_i) return Float32(Float32(Float32(sin(Float32(Float32(Float32(1.0) - u) * normAngle)) * Float32(Float32(1.0) / sin(normAngle))) * n0_i) + Float32(Float32(sin(Float32(u * normAngle)) * Float32(Float32(1.0) / sin(normAngle))) * n1_i)) end
function code(normAngle, u, n0_i, n1_i) return fma(u, n1_i, fma(Float32(normAngle * normAngle), Float32(Float32(Float32(0.16666666666666666) * Float32(n0_i * Float32(Float32(Float32(1.0) - (Float32(Float32(1.0) - u) ^ Float32(3.0))) - u))) + Float32(Float32(-0.16666666666666666) * Float32(n1_i * Float32((u ^ Float32(3.0)) - u)))), Float32(Float32(Float32(1.0) - u) * n0_i))) end
\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i
\mathsf{fma}\left(u, n1_i, \mathsf{fma}\left(normAngle \cdot normAngle, 0.16666666666666666 \cdot \left(n0_i \cdot \left(\left(1 - {\left(1 - u\right)}^{3}\right) - u\right)\right) + -0.16666666666666666 \cdot \left(n1_i \cdot \left({u}^{3} - u\right)\right), \left(1 - u\right) \cdot n0_i\right)\right)
Initial program 0.8
Simplified0.7
[Start]0.8 | \[ \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i
\] |
|---|---|
fma-def [=>]0.8 | \[ \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)}
\] |
associate-*r/ [=>]0.8 | \[ \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)
\] |
*-rgt-identity [=>]0.8 | \[ \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)
\] |
associate-*r/ [=>]0.7 | \[ \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right)
\] |
*-rgt-identity [=>]0.7 | \[ \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right)
\] |
Taylor expanded in normAngle around 0 0.3
Simplified0.3
[Start]0.3 | \[ n1_i \cdot u + \left(\left(\left(-0.16666666666666666 \cdot \left(n1_i \cdot {u}^{3}\right) + \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) \cdot n0_i\right) - -0.16666666666666666 \cdot \left(n1_i \cdot u\right)\right) \cdot {normAngle}^{2} + \left(1 - u\right) \cdot n0_i\right)
\] |
|---|---|
*-commutative [=>]0.3 | \[ \color{blue}{u \cdot n1_i} + \left(\left(\left(-0.16666666666666666 \cdot \left(n1_i \cdot {u}^{3}\right) + \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) \cdot n0_i\right) - -0.16666666666666666 \cdot \left(n1_i \cdot u\right)\right) \cdot {normAngle}^{2} + \left(1 - u\right) \cdot n0_i\right)
\] |
fma-def [=>]0.3 | \[ \color{blue}{\mathsf{fma}\left(u, n1_i, \left(\left(-0.16666666666666666 \cdot \left(n1_i \cdot {u}^{3}\right) + \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) \cdot n0_i\right) - -0.16666666666666666 \cdot \left(n1_i \cdot u\right)\right) \cdot {normAngle}^{2} + \left(1 - u\right) \cdot n0_i\right)}
\] |
*-commutative [=>]0.3 | \[ \mathsf{fma}\left(u, n1_i, \color{blue}{{normAngle}^{2} \cdot \left(\left(-0.16666666666666666 \cdot \left(n1_i \cdot {u}^{3}\right) + \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) \cdot n0_i\right) - -0.16666666666666666 \cdot \left(n1_i \cdot u\right)\right)} + \left(1 - u\right) \cdot n0_i\right)
\] |
fma-def [=>]0.3 | \[ \mathsf{fma}\left(u, n1_i, \color{blue}{\mathsf{fma}\left({normAngle}^{2}, \left(-0.16666666666666666 \cdot \left(n1_i \cdot {u}^{3}\right) + \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) \cdot n0_i\right) - -0.16666666666666666 \cdot \left(n1_i \cdot u\right), \left(1 - u\right) \cdot n0_i\right)}\right)
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 3552 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 3424 |
| Alternative 3 | |
|---|---|
| Error | 0.6 |
| Cost | 3424 |
| Alternative 4 | |
|---|---|
| Error | 9.0 |
| Cost | 297 |
| Alternative 5 | |
|---|---|
| Error | 4.3 |
| Cost | 297 |
| Alternative 6 | |
|---|---|
| Error | 4.2 |
| Cost | 297 |
| Alternative 7 | |
|---|---|
| Error | 12.4 |
| Cost | 232 |
| Alternative 8 | |
|---|---|
| Error | 0.5 |
| Cost | 224 |
| Alternative 9 | |
|---|---|
| Error | 16.7 |
| Cost | 32 |
herbie shell --seed 2023073
(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)))