| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 544 |
(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
(+
(* (- n1_i n0_i) u)
(+
n0_i
(*
(fma 0.16666666666666666 n1_i (* n0_i 0.3333333333333333))
(* u (* normAngle normAngle))))))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 ((n1_i - n0_i) * u) + (n0_i + (fmaf(0.16666666666666666f, n1_i, (n0_i * 0.3333333333333333f)) * (u * (normAngle * normAngle))));
}
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 Float32(Float32(Float32(n1_i - n0_i) * u) + Float32(n0_i + Float32(fma(Float32(0.16666666666666666), n1_i, Float32(n0_i * Float32(0.3333333333333333))) * Float32(u * Float32(normAngle * normAngle))))) 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
\left(n1_i - n0_i\right) \cdot u + \left(n0_i + \mathsf{fma}\left(0.16666666666666666, n1_i, n0_i \cdot 0.3333333333333333\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right)\right)
Initial program 0.9
Simplified8.2
[Start]0.9 | \[ \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
\] |
|---|---|
*-commutative [=>]0.9 | \[ \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right)} \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i
\] |
associate-*l* [=>]6.1 | \[ \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i\right)} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i
\] |
*-commutative [=>]6.1 | \[ \frac{1}{\sin normAngle} \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i\right) + \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(u \cdot normAngle\right)\right)} \cdot n1_i
\] |
associate-*l* [=>]8.3 | \[ \frac{1}{\sin normAngle} \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i\right) + \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right)}
\] |
distribute-lft-out [=>]8.3 | \[ \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}
\] |
+-commutative [<=]8.3 | \[ \frac{1}{\sin normAngle} \cdot \color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i + \sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i\right)}
\] |
associate-*l/ [=>]8.2 | \[ \color{blue}{\frac{1 \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i + \sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i\right)}{\sin normAngle}}
\] |
*-commutative [=>]8.2 | \[ \frac{\color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i + \sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i\right) \cdot 1}}{\sin normAngle}
\] |
associate-/l* [=>]8.2 | \[ \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot n1_i + \sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i}{\frac{\sin normAngle}{1}}}
\] |
/-rgt-identity [=>]8.2 | \[ \frac{\sin \left(u \cdot normAngle\right) \cdot n1_i + \sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot n0_i}{\color{blue}{\sin normAngle}}
\] |
Taylor expanded in u around 0 8.4
Taylor expanded in normAngle around 0 0.4
Taylor expanded in u around 0 0.4
Simplified0.4
[Start]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(\left(0.5 \cdot n0_i - -0.16666666666666666 \cdot \left(n1_i + -1 \cdot n0_i\right)\right) \cdot u\right) \cdot {normAngle}^{2} + n0_i\right)
\] |
|---|---|
*-commutative [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\color{blue}{\left(u \cdot \left(0.5 \cdot n0_i - -0.16666666666666666 \cdot \left(n1_i + -1 \cdot n0_i\right)\right)\right)} \cdot {normAngle}^{2} + n0_i\right)
\] |
*-commutative [<=]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(u \cdot \left(\color{blue}{n0_i \cdot 0.5} - -0.16666666666666666 \cdot \left(n1_i + -1 \cdot n0_i\right)\right)\right) \cdot {normAngle}^{2} + n0_i\right)
\] |
cancel-sign-sub-inv [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(u \cdot \color{blue}{\left(n0_i \cdot 0.5 + \left(--0.16666666666666666\right) \cdot \left(n1_i + -1 \cdot n0_i\right)\right)}\right) \cdot {normAngle}^{2} + n0_i\right)
\] |
*-commutative [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(u \cdot \left(\color{blue}{0.5 \cdot n0_i} + \left(--0.16666666666666666\right) \cdot \left(n1_i + -1 \cdot n0_i\right)\right)\right) \cdot {normAngle}^{2} + n0_i\right)
\] |
metadata-eval [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(u \cdot \left(0.5 \cdot n0_i + \color{blue}{0.16666666666666666} \cdot \left(n1_i + -1 \cdot n0_i\right)\right)\right) \cdot {normAngle}^{2} + n0_i\right)
\] |
mul-1-neg [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(u \cdot \left(0.5 \cdot n0_i + 0.16666666666666666 \cdot \left(n1_i + \color{blue}{\left(-n0_i\right)}\right)\right)\right) \cdot {normAngle}^{2} + n0_i\right)
\] |
Taylor expanded in u around 0 0.4
Simplified0.4
[Start]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(0.5 \cdot n0_i + 0.16666666666666666 \cdot \left(n1_i - n0_i\right)\right) \cdot \left(u \cdot {normAngle}^{2}\right) + n0_i\right)
\] |
|---|---|
associate-*r* [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\color{blue}{\left(\left(0.5 \cdot n0_i + 0.16666666666666666 \cdot \left(n1_i - n0_i\right)\right) \cdot u\right) \cdot {normAngle}^{2}} + n0_i\right)
\] |
unpow2 [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(\left(0.5 \cdot n0_i + 0.16666666666666666 \cdot \left(n1_i - n0_i\right)\right) \cdot u\right) \cdot \color{blue}{\left(normAngle \cdot normAngle\right)} + n0_i\right)
\] |
associate-*r* [<=]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\color{blue}{\left(0.5 \cdot n0_i + 0.16666666666666666 \cdot \left(n1_i - n0_i\right)\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right)} + n0_i\right)
\] |
+-commutative [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\color{blue}{\left(0.16666666666666666 \cdot \left(n1_i - n0_i\right) + 0.5 \cdot n0_i\right)} \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
distribute-lft-out-- [<=]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(\color{blue}{\left(0.16666666666666666 \cdot n1_i - 0.16666666666666666 \cdot n0_i\right)} + 0.5 \cdot n0_i\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
cancel-sign-sub-inv [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(\color{blue}{\left(0.16666666666666666 \cdot n1_i + \left(-0.16666666666666666\right) \cdot n0_i\right)} + 0.5 \cdot n0_i\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
metadata-eval [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(\left(0.16666666666666666 \cdot n1_i + \color{blue}{-0.16666666666666666} \cdot n0_i\right) + 0.5 \cdot n0_i\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
*-commutative [<=]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(\left(0.16666666666666666 \cdot n1_i + -0.16666666666666666 \cdot n0_i\right) + \color{blue}{n0_i \cdot 0.5}\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
associate-+r+ [<=]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\color{blue}{\left(0.16666666666666666 \cdot n1_i + \left(-0.16666666666666666 \cdot n0_i + n0_i \cdot 0.5\right)\right)} \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
*-commutative [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\left(0.16666666666666666 \cdot n1_i + \left(-0.16666666666666666 \cdot n0_i + \color{blue}{0.5 \cdot n0_i}\right)\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
fma-def [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\color{blue}{\mathsf{fma}\left(0.16666666666666666, n1_i, -0.16666666666666666 \cdot n0_i + 0.5 \cdot n0_i\right)} \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
distribute-rgt-out [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\mathsf{fma}\left(0.16666666666666666, n1_i, \color{blue}{n0_i \cdot \left(-0.16666666666666666 + 0.5\right)}\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
metadata-eval [=>]0.4 | \[ \left(n1_i + -1 \cdot n0_i\right) \cdot u + \left(\mathsf{fma}\left(0.16666666666666666, n1_i, n0_i \cdot \color{blue}{0.3333333333333333}\right) \cdot \left(u \cdot \left(normAngle \cdot normAngle\right)\right) + n0_i\right)
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 544 |
| Alternative 2 | |
|---|---|
| Error | 9.8 |
| Cost | 434 |
| Alternative 3 | |
|---|---|
| Error | 4.7 |
| Cost | 297 |
| Alternative 4 | |
|---|---|
| Error | 4.7 |
| Cost | 297 |
| Alternative 5 | |
|---|---|
| Error | 0.7 |
| Cost | 288 |
| Alternative 6 | |
|---|---|
| Error | 12.6 |
| Cost | 232 |
| Alternative 7 | |
|---|---|
| Error | 0.6 |
| Cost | 224 |
| Alternative 8 | |
|---|---|
| Error | 17.0 |
| Cost | 32 |
herbie shell --seed 2023053
(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)))