Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.3% → 99.1%
Time: 6.6s
Alternatives: 9
Speedup: 19.5×

Specification

?
\[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
\[\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} \]
(FPCore (normAngle u n0_i n1_i)
  :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)))
  (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)
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}
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}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 97.3% accurate, 1.0× speedup?

\[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
\[\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} \]
(FPCore (normAngle u n0_i n1_i)
  :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)))
  (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)
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}
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}

Alternative 1: 99.1% accurate, 4.7× speedup?

\[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
\[n0\_i + u \cdot \mathsf{fma}\left(n1\_i, \frac{normAngle}{\mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, 0.008333333333333333, -0.16666666666666666\right), 1\right) \cdot normAngle}, -n0\_i\right) \]
(FPCore (normAngle u n0_i n1_i)
  :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)))
  (+
 n0_i
 (*
  u
  (fma
   n1_i
   (/
    normAngle
    (*
     (fma
      (* normAngle normAngle)
      (fma
       (* normAngle normAngle)
       0.008333333333333333
       -0.16666666666666666)
      1.0)
     normAngle))
   (- n0_i)))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return n0_i + (u * fmaf(n1_i, (normAngle / (fmaf((normAngle * normAngle), fmaf((normAngle * normAngle), 0.008333333333333333f, -0.16666666666666666f), 1.0f) * normAngle)), -n0_i));
}
function code(normAngle, u, n0_i, n1_i)
	return Float32(n0_i + Float32(u * fma(n1_i, Float32(normAngle / Float32(fma(Float32(normAngle * normAngle), fma(Float32(normAngle * normAngle), Float32(0.008333333333333333), Float32(-0.16666666666666666)), Float32(1.0)) * normAngle)), Float32(-n0_i))))
end
n0\_i + u \cdot \mathsf{fma}\left(n1\_i, \frac{normAngle}{\mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, 0.008333333333333333, -0.16666666666666666\right), 1\right) \cdot normAngle}, -n0\_i\right)
Derivation
  1. Initial program 97.3%

    \[\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 \]
  2. Taylor expanded in u around 0

    \[\leadsto n0\_i + u \cdot \left(-1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
  3. Step-by-step derivation
    1. Applied rewrites88.0%

      \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle}, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
    2. Taylor expanded in normAngle around 0

      \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
    3. Step-by-step derivation
      1. Applied rewrites90.1%

        \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
      2. Taylor expanded in normAngle around 0

        \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{normAngle \cdot \left(1 + {normAngle}^{2} \cdot \left(\frac{1}{120} \cdot {normAngle}^{2} - \frac{1}{6}\right)\right)}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites90.0%

          \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{normAngle \cdot \left(1 + {normAngle}^{2} \cdot \left(0.008333333333333333 \cdot {normAngle}^{2} - 0.16666666666666666\right)\right)}\right) \]
        2. Step-by-step derivation
          1. Applied rewrites99.0%

            \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(n1\_i, \frac{normAngle}{\mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, 0.008333333333333333, -0.16666666666666666\right), 1\right) \cdot normAngle}, -n0\_i\right) \]
          2. Add Preprocessing

          Alternative 2: 99.0% accurate, 5.4× speedup?

          \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
          \[\mathsf{fma}\left(\left(n1\_i - \mathsf{fma}\left(-0.16666666666666666, n1\_i, \left(normAngle \cdot normAngle\right) \cdot \left(n1\_i \cdot -0.019444444444444445\right)\right) \cdot \left(normAngle \cdot normAngle\right)\right) - n0\_i, u, n0\_i\right) \]
          (FPCore (normAngle u n0_i n1_i)
            :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)))
            (fma
           (-
            (-
             n1_i
             (*
              (fma
               -0.16666666666666666
               n1_i
               (* (* normAngle normAngle) (* n1_i -0.019444444444444445)))
              (* normAngle normAngle)))
            n0_i)
           u
           n0_i))
          float code(float normAngle, float u, float n0_i, float n1_i) {
          	return fmaf(((n1_i - (fmaf(-0.16666666666666666f, n1_i, ((normAngle * normAngle) * (n1_i * -0.019444444444444445f))) * (normAngle * normAngle))) - n0_i), u, n0_i);
          }
          
          function code(normAngle, u, n0_i, n1_i)
          	return fma(Float32(Float32(n1_i - Float32(fma(Float32(-0.16666666666666666), n1_i, Float32(Float32(normAngle * normAngle) * Float32(n1_i * Float32(-0.019444444444444445)))) * Float32(normAngle * normAngle))) - n0_i), u, n0_i)
          end
          
          \mathsf{fma}\left(\left(n1\_i - \mathsf{fma}\left(-0.16666666666666666, n1\_i, \left(normAngle \cdot normAngle\right) \cdot \left(n1\_i \cdot -0.019444444444444445\right)\right) \cdot \left(normAngle \cdot normAngle\right)\right) - n0\_i, u, n0\_i\right)
          
          Derivation
          1. Initial program 97.3%

            \[\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 \]
          2. Taylor expanded in u around 0

            \[\leadsto n0\_i + u \cdot \left(-1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
          3. Step-by-step derivation
            1. Applied rewrites88.0%

              \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle}, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
            2. Taylor expanded in normAngle around 0

              \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
            3. Step-by-step derivation
              1. Applied rewrites90.1%

                \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
              2. Taylor expanded in normAngle around 0

                \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, n1\_i + {normAngle}^{2} \cdot \left(-1 \cdot \left({normAngle}^{2} \cdot \left(\frac{-1}{36} \cdot n1\_i + \frac{1}{120} \cdot n1\_i\right)\right) - \frac{-1}{6} \cdot n1\_i\right)\right) \]
              3. Step-by-step derivation
                1. Applied rewrites99.0%

                  \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, n1\_i + {normAngle}^{2} \cdot \left(-1 \cdot \left({normAngle}^{2} \cdot \mathsf{fma}\left(-0.027777777777777776, n1\_i, 0.008333333333333333 \cdot n1\_i\right)\right) - -0.16666666666666666 \cdot n1\_i\right)\right) \]
                2. Applied rewrites99.1%

                  \[\leadsto \mathsf{fma}\left(\left(n1\_i - \mathsf{fma}\left(-0.16666666666666666, n1\_i, \left(normAngle \cdot normAngle\right) \cdot \left(n1\_i \cdot -0.019444444444444445\right)\right) \cdot \left(normAngle \cdot normAngle\right)\right) - n0\_i, u, n0\_i\right) \]
                3. Add Preprocessing

                Alternative 3: 98.9% accurate, 6.1× speedup?

                \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
                \[n0\_i + u \cdot \mathsf{fma}\left(n1\_i, \frac{normAngle}{\mathsf{fma}\left(normAngle \cdot normAngle, -0.16666666666666666, 1\right) \cdot normAngle}, -n0\_i\right) \]
                (FPCore (normAngle u n0_i n1_i)
                  :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)))
                  (+
                 n0_i
                 (*
                  u
                  (fma
                   n1_i
                   (/
                    normAngle
                    (*
                     (fma (* normAngle normAngle) -0.16666666666666666 1.0)
                     normAngle))
                   (- n0_i)))))
                float code(float normAngle, float u, float n0_i, float n1_i) {
                	return n0_i + (u * fmaf(n1_i, (normAngle / (fmaf((normAngle * normAngle), -0.16666666666666666f, 1.0f) * normAngle)), -n0_i));
                }
                
                function code(normAngle, u, n0_i, n1_i)
                	return Float32(n0_i + Float32(u * fma(n1_i, Float32(normAngle / Float32(fma(Float32(normAngle * normAngle), Float32(-0.16666666666666666), Float32(1.0)) * normAngle)), Float32(-n0_i))))
                end
                
                n0\_i + u \cdot \mathsf{fma}\left(n1\_i, \frac{normAngle}{\mathsf{fma}\left(normAngle \cdot normAngle, -0.16666666666666666, 1\right) \cdot normAngle}, -n0\_i\right)
                
                Derivation
                1. Initial program 97.3%

                  \[\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 \]
                2. Taylor expanded in u around 0

                  \[\leadsto n0\_i + u \cdot \left(-1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                3. Step-by-step derivation
                  1. Applied rewrites88.0%

                    \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle}, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                  2. Taylor expanded in normAngle around 0

                    \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                  3. Step-by-step derivation
                    1. Applied rewrites90.1%

                      \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                    2. Taylor expanded in normAngle around 0

                      \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{normAngle \cdot \left(1 + \frac{-1}{6} \cdot {normAngle}^{2}\right)}\right) \]
                    3. Step-by-step derivation
                      1. Applied rewrites89.8%

                        \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i, \frac{n1\_i \cdot normAngle}{normAngle \cdot \left(1 + -0.16666666666666666 \cdot {normAngle}^{2}\right)}\right) \]
                      2. Step-by-step derivation
                        1. Applied rewrites98.9%

                          \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(n1\_i, \frac{normAngle}{\mathsf{fma}\left(normAngle \cdot normAngle, -0.16666666666666666, 1\right) \cdot normAngle}, -n0\_i\right) \]
                        2. Add Preprocessing

                        Alternative 4: 98.7% accurate, 7.2× speedup?

                        \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
                        \[\mathsf{fma}\left(n0\_i, 1 - u, \left(n1\_i - \left(-0.16666666666666666 \cdot n1\_i\right) \cdot \left(normAngle \cdot normAngle\right)\right) \cdot u\right) \]
                        (FPCore (normAngle u n0_i n1_i)
                          :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)))
                          (fma
                         n0_i
                         (- 1.0 u)
                         (*
                          (- n1_i (* (* -0.16666666666666666 n1_i) (* normAngle normAngle)))
                          u)))
                        float code(float normAngle, float u, float n0_i, float n1_i) {
                        	return fmaf(n0_i, (1.0f - u), ((n1_i - ((-0.16666666666666666f * n1_i) * (normAngle * normAngle))) * u));
                        }
                        
                        function code(normAngle, u, n0_i, n1_i)
                        	return fma(n0_i, Float32(Float32(1.0) - u), Float32(Float32(n1_i - Float32(Float32(Float32(-0.16666666666666666) * n1_i) * Float32(normAngle * normAngle))) * u))
                        end
                        
                        \mathsf{fma}\left(n0\_i, 1 - u, \left(n1\_i - \left(-0.16666666666666666 \cdot n1\_i\right) \cdot \left(normAngle \cdot normAngle\right)\right) \cdot u\right)
                        
                        Derivation
                        1. Initial program 97.3%

                          \[\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 \]
                        2. Taylor expanded in normAngle around 0

                          \[\leadsto n0\_i \cdot \left(1 - u\right) + \left(n1\_i \cdot u + {normAngle}^{2} \cdot \left(\left(\frac{-1}{6} \cdot \left(n0\_i \cdot {\left(1 - u\right)}^{3}\right) + \frac{-1}{6} \cdot \left(n1\_i \cdot {u}^{3}\right)\right) - \left(\frac{-1}{6} \cdot \left(n0\_i \cdot \left(1 - u\right)\right) + \frac{-1}{6} \cdot \left(n1\_i \cdot u\right)\right)\right)\right) \]
                        3. Step-by-step derivation
                          1. Applied rewrites98.9%

                            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \mathsf{fma}\left(n1\_i, u, {normAngle}^{2} \cdot \left(\mathsf{fma}\left(-0.16666666666666666, n0\_i \cdot {\left(1 - u\right)}^{3}, -0.16666666666666666 \cdot \left(n1\_i \cdot {u}^{3}\right)\right) - \mathsf{fma}\left(-0.16666666666666666, n0\_i \cdot \left(1 - u\right), -0.16666666666666666 \cdot \left(n1\_i \cdot u\right)\right)\right)\right)\right) \]
                          2. Taylor expanded in u around 0

                            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, u \cdot \left(n1\_i + {normAngle}^{2} \cdot \left(\frac{1}{2} \cdot n0\_i - \left(\frac{-1}{6} \cdot n1\_i + \frac{1}{6} \cdot n0\_i\right)\right)\right)\right) \]
                          3. Step-by-step derivation
                            1. Applied rewrites98.8%

                              \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, u \cdot \left(n1\_i + {normAngle}^{2} \cdot \left(0.5 \cdot n0\_i - \mathsf{fma}\left(-0.16666666666666666, n1\_i, 0.16666666666666666 \cdot n0\_i\right)\right)\right)\right) \]
                            2. Applied rewrites98.8%

                              \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \left(n1\_i - \left(-0.16666666666666666 \cdot n1\_i - n0\_i \cdot 0.3333333333333333\right) \cdot \left(normAngle \cdot normAngle\right)\right) \cdot u\right) \]
                            3. Taylor expanded in n0_i around 0

                              \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \left(n1\_i - \left(\frac{-1}{6} \cdot n1\_i\right) \cdot \left(normAngle \cdot normAngle\right)\right) \cdot u\right) \]
                            4. Step-by-step derivation
                              1. Applied rewrites98.7%

                                \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \left(n1\_i - \left(-0.16666666666666666 \cdot n1\_i\right) \cdot \left(normAngle \cdot normAngle\right)\right) \cdot u\right) \]
                              2. Add Preprocessing

                              Alternative 5: 98.4% accurate, 8.6× speedup?

                              \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
                              \[\mathsf{fma}\left(n1\_i - \mathsf{fma}\left(\left(normAngle \cdot normAngle\right) \cdot n0\_i, -0.3333333333333333, n0\_i\right), u, n0\_i\right) \]
                              (FPCore (normAngle u n0_i n1_i)
                                :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)))
                                (fma
                               (-
                                n1_i
                                (fma (* (* normAngle normAngle) n0_i) -0.3333333333333333 n0_i))
                               u
                               n0_i))
                              float code(float normAngle, float u, float n0_i, float n1_i) {
                              	return fmaf((n1_i - fmaf(((normAngle * normAngle) * n0_i), -0.3333333333333333f, n0_i)), u, n0_i);
                              }
                              
                              function code(normAngle, u, n0_i, n1_i)
                              	return fma(Float32(n1_i - fma(Float32(Float32(normAngle * normAngle) * n0_i), Float32(-0.3333333333333333), n0_i)), u, n0_i)
                              end
                              
                              \mathsf{fma}\left(n1\_i - \mathsf{fma}\left(\left(normAngle \cdot normAngle\right) \cdot n0\_i, -0.3333333333333333, n0\_i\right), u, n0\_i\right)
                              
                              Derivation
                              1. Initial program 97.3%

                                \[\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 \]
                              2. Taylor expanded in u around 0

                                \[\leadsto n0\_i + u \cdot \left(-1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                              3. Step-by-step derivation
                                1. Applied rewrites88.0%

                                  \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle}, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                                2. Taylor expanded in normAngle around 0

                                  \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i + {normAngle}^{2} \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right), \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                                3. Step-by-step derivation
                                  1. Applied rewrites90.3%

                                    \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, n0\_i + {normAngle}^{2} \cdot \left(-0.5 \cdot n0\_i - -0.16666666666666666 \cdot n0\_i\right), \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                                  2. Applied rewrites90.4%

                                    \[\leadsto \mathsf{fma}\left(\frac{n1\_i \cdot normAngle}{\sin normAngle} - \mathsf{fma}\left(\left(normAngle \cdot normAngle\right) \cdot n0\_i, -0.3333333333333333, n0\_i\right), u, n0\_i\right) \]
                                  3. Taylor expanded in normAngle around 0

                                    \[\leadsto \mathsf{fma}\left(n1\_i - \mathsf{fma}\left(\left(normAngle \cdot normAngle\right) \cdot n0\_i, -0.3333333333333333, n0\_i\right), u, n0\_i\right) \]
                                  4. Step-by-step derivation
                                    1. Applied rewrites98.4%

                                      \[\leadsto \mathsf{fma}\left(n1\_i - \mathsf{fma}\left(\left(normAngle \cdot normAngle\right) \cdot n0\_i, -0.3333333333333333, n0\_i\right), u, n0\_i\right) \]
                                    2. Add Preprocessing

                                    Alternative 6: 98.3% accurate, 19.5× speedup?

                                    \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
                                    \[\mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \]
                                    (FPCore (normAngle u n0_i n1_i)
                                      :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)))
                                      (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
                                    
                                    \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)
                                    
                                    Derivation
                                    1. Initial program 97.3%

                                      \[\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 \]
                                    2. Taylor expanded in u around 0

                                      \[\leadsto n0\_i + u \cdot \left(-1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites88.0%

                                        \[\leadsto n0\_i + u \cdot \mathsf{fma}\left(-1, \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle}, \frac{n1\_i \cdot normAngle}{\sin normAngle}\right) \]
                                      2. Taylor expanded in normAngle around 0

                                        \[\leadsto n0\_i + u \cdot \left(n1\_i + -1 \cdot n0\_i\right) \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites98.2%

                                          \[\leadsto n0\_i + u \cdot \left(n1\_i + -1 \cdot n0\_i\right) \]
                                        2. Applied rewrites98.3%

                                          \[\leadsto \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \]
                                        3. Add Preprocessing

                                        Alternative 7: 85.9% accurate, 11.8× speedup?

                                        \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
                                        \[\begin{array}{l} \mathbf{if}\;n1\_i \leq -3.018727824514825 \cdot 10^{-27}:\\ \;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\ \mathbf{elif}\;n1\_i \leq 2.483693850208526 \cdot 10^{-22}:\\ \;\;\;\;n0\_i \cdot \left(1 - u\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\ \end{array} \]
                                        (FPCore (normAngle u n0_i n1_i)
                                          :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)))
                                          (if (<= n1_i -3.018727824514825e-27)
                                          (fma n1_i u n0_i)
                                          (if (<= n1_i 2.483693850208526e-22)
                                            (* 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 (n1_i <= -3.018727824514825e-27f) {
                                        		tmp = fmaf(n1_i, u, n0_i);
                                        	} else if (n1_i <= 2.483693850208526e-22f) {
                                        		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 (n1_i <= Float32(-3.018727824514825e-27))
                                        		tmp = fma(n1_i, u, n0_i);
                                        	elseif (n1_i <= Float32(2.483693850208526e-22))
                                        		tmp = Float32(n0_i * Float32(Float32(1.0) - u));
                                        	else
                                        		tmp = fma(n1_i, u, n0_i);
                                        	end
                                        	return tmp
                                        end
                                        
                                        \begin{array}{l}
                                        \mathbf{if}\;n1\_i \leq -3.018727824514825 \cdot 10^{-27}:\\
                                        \;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\
                                        
                                        \mathbf{elif}\;n1\_i \leq 2.483693850208526 \cdot 10^{-22}:\\
                                        \;\;\;\;n0\_i \cdot \left(1 - u\right)\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\
                                        
                                        
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if n1_i < -3.01872782e-27 or 2.48369385e-22 < n1_i

                                          1. Initial program 97.3%

                                            \[\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 \]
                                          2. Taylor expanded in u around 0

                                            \[\leadsto n0\_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1\_i \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites81.0%

                                              \[\leadsto n0\_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1\_i \]
                                            2. Taylor expanded in normAngle around 0

                                              \[\leadsto n0\_i + u \cdot n1\_i \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites81.6%

                                                \[\leadsto n0\_i + u \cdot n1\_i \]
                                              2. Step-by-step derivation
                                                1. Applied rewrites81.7%

                                                  \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i\right) \]

                                                if -3.01872782e-27 < n1_i < 2.48369385e-22

                                                1. Initial program 97.3%

                                                  \[\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 \]
                                                2. Taylor expanded in normAngle around 0

                                                  \[\leadsto n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u \]
                                                3. Step-by-step derivation
                                                  1. Applied rewrites98.0%

                                                    \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right) \]
                                                  2. Taylor expanded in n0_i around -inf

                                                    \[\leadsto -1 \cdot \left(n0\_i \cdot \left(-1 \cdot \left(1 - u\right) + -1 \cdot \frac{n1\_i \cdot u}{n0\_i}\right)\right) \]
                                                  3. Step-by-step derivation
                                                    1. Applied rewrites97.8%

                                                      \[\leadsto -1 \cdot \left(n0\_i \cdot \mathsf{fma}\left(-1, 1 - u, -1 \cdot \frac{n1\_i \cdot u}{n0\_i}\right)\right) \]
                                                    2. Applied rewrites97.7%

                                                      \[\leadsto n0\_i \cdot \mathsf{fma}\left(\frac{u}{n0\_i}, n1\_i, 1 - u\right) \]
                                                    3. Taylor expanded in n0_i around inf

                                                      \[\leadsto n0\_i \cdot \left(1 - u\right) \]
                                                    4. Step-by-step derivation
                                                      1. Applied rewrites58.4%

                                                        \[\leadsto n0\_i \cdot \left(1 - u\right) \]
                                                    5. Recombined 2 regimes into one program.
                                                    6. Add Preprocessing

                                                    Alternative 8: 81.7% accurate, 28.0× speedup?

                                                    \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
                                                    \[\mathsf{fma}\left(n1\_i, u, n0\_i\right) \]
                                                    (FPCore (normAngle u n0_i n1_i)
                                                      :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)))
                                                      (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
                                                    
                                                    \mathsf{fma}\left(n1\_i, u, n0\_i\right)
                                                    
                                                    Derivation
                                                    1. Initial program 97.3%

                                                      \[\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 \]
                                                    2. Taylor expanded in u around 0

                                                      \[\leadsto n0\_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1\_i \]
                                                    3. Step-by-step derivation
                                                      1. Applied rewrites81.0%

                                                        \[\leadsto n0\_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1\_i \]
                                                      2. Taylor expanded in normAngle around 0

                                                        \[\leadsto n0\_i + u \cdot n1\_i \]
                                                      3. Step-by-step derivation
                                                        1. Applied rewrites81.6%

                                                          \[\leadsto n0\_i + u \cdot n1\_i \]
                                                        2. Step-by-step derivation
                                                          1. Applied rewrites81.7%

                                                            \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i\right) \]
                                                          2. Add Preprocessing

                                                          Alternative 9: 46.8% accurate, 33.6× speedup?

                                                          \[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
                                                          \[--1 \cdot n0\_i \]
                                                          (FPCore (normAngle u n0_i n1_i)
                                                            :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)))
                                                            (- (* -1.0 n0_i)))
                                                          float code(float normAngle, float u, float n0_i, float n1_i) {
                                                          	return -(-1.0f * n0_i);
                                                          }
                                                          
                                                          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 = -((-1.0e0) * n0_i)
                                                          end function
                                                          
                                                          function code(normAngle, u, n0_i, n1_i)
                                                          	return Float32(-Float32(Float32(-1.0) * n0_i))
                                                          end
                                                          
                                                          function tmp = code(normAngle, u, n0_i, n1_i)
                                                          	tmp = -(single(-1.0) * n0_i);
                                                          end
                                                          
                                                          --1 \cdot n0\_i
                                                          
                                                          Derivation
                                                          1. Initial program 97.3%

                                                            \[\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 \]
                                                          2. Taylor expanded in normAngle around 0

                                                            \[\leadsto n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u \]
                                                          3. Step-by-step derivation
                                                            1. Applied rewrites98.0%

                                                              \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right) \]
                                                            2. Taylor expanded in n0_i around -inf

                                                              \[\leadsto -1 \cdot \left(n0\_i \cdot \left(-1 \cdot \left(1 - u\right) + -1 \cdot \frac{n1\_i \cdot u}{n0\_i}\right)\right) \]
                                                            3. Step-by-step derivation
                                                              1. Applied rewrites97.8%

                                                                \[\leadsto -1 \cdot \left(n0\_i \cdot \mathsf{fma}\left(-1, 1 - u, -1 \cdot \frac{n1\_i \cdot u}{n0\_i}\right)\right) \]
                                                              2. Taylor expanded in u around 0

                                                                \[\leadsto -1 \cdot \left(n0\_i \cdot -1\right) \]
                                                              3. Step-by-step derivation
                                                                1. Applied rewrites46.8%

                                                                  \[\leadsto -1 \cdot \left(n0\_i \cdot -1\right) \]
                                                                2. Applied rewrites46.8%

                                                                  \[\leadsto --1 \cdot n0\_i \]
                                                                3. Add Preprocessing

                                                                Reproduce

                                                                ?
                                                                herbie shell --seed 2026084 
                                                                (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)))