Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.2% → 99.1%
Time: 14.2s
Alternatives: 10
Speedup: 45.9×

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} \\ \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
 (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:

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 10 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.2% accurate, 1.0× speedup?

\[\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
 (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}

Alternative 1: 99.1% accurate, 9.6× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, 0.019444444444444445 \cdot n1\_i, \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right)\right), n1\_i - n0\_i\right), n0\_i\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (fma
  u
  (fma
   (* normAngle normAngle)
   (fma
    (* normAngle normAngle)
    (* 0.019444444444444445 n1_i)
    (fma n0_i 0.3333333333333333 (* n1_i 0.16666666666666666)))
   (- n1_i n0_i))
  n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return fmaf(u, fmaf((normAngle * normAngle), fmaf((normAngle * normAngle), (0.019444444444444445f * n1_i), fmaf(n0_i, 0.3333333333333333f, (n1_i * 0.16666666666666666f))), (n1_i - n0_i)), n0_i);
}
function code(normAngle, u, n0_i, n1_i)
	return fma(u, fma(Float32(normAngle * normAngle), fma(Float32(normAngle * normAngle), Float32(Float32(0.019444444444444445) * n1_i), fma(n0_i, Float32(0.3333333333333333), Float32(n1_i * Float32(0.16666666666666666)))), Float32(n1_i - n0_i)), n0_i)
end
\begin{array}{l}

\\
\mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, 0.019444444444444445 \cdot n1\_i, \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right)\right), n1\_i - n0\_i\right), n0\_i\right)
\end{array}
Derivation
  1. Initial program 97.6%

    \[\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. Add Preprocessing
  3. Taylor expanded in u around 0

    \[\leadsto \color{blue}{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)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{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) + n0\_i} \]
    2. lower-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, -1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}, n0\_i\right)} \]
  5. Applied rewrites99.1%

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

    \[\leadsto \mathsf{fma}\left(u, \color{blue}{n1\_i + \left(-1 \cdot n0\_i + {normAngle}^{2} \cdot \left(\left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) + {normAngle}^{2} \cdot \left(-1 \cdot \left(\frac{1}{24} \cdot n0\_i - \left(\frac{-1}{6} \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) + \frac{1}{120} \cdot n0\_i\right)\right) - \left(\frac{-1}{36} \cdot n1\_i + \frac{1}{120} \cdot n1\_i\right)\right)\right) - \frac{-1}{6} \cdot n1\_i\right)\right)}, n0\_i\right) \]
  7. Applied rewrites99.2%

    \[\leadsto \mathsf{fma}\left(u, \color{blue}{\mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, -\left(\left(n0\_i \cdot 0.041666666666666664 - \mathsf{fma}\left(n0\_i, 0.05555555555555555, n0\_i \cdot 0.008333333333333333\right)\right) + n1\_i \cdot -0.019444444444444445\right), \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right)\right), n1\_i - n0\_i\right)}, n0\_i\right) \]
  8. Taylor expanded in n0_i around 0

    \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{\frac{7}{360} \cdot n1\_i}, \mathsf{fma}\left(n0\_i, \frac{1}{3}, n1\_i \cdot \frac{1}{6}\right)\right), n1\_i - n0\_i\right), n0\_i\right) \]
  9. Step-by-step derivation
    1. lower-*.f3299.2

      \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{0.019444444444444445 \cdot n1\_i}, \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right)\right), n1\_i - n0\_i\right), n0\_i\right) \]
  10. Applied rewrites99.2%

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

Alternative 2: 99.0% accurate, 14.3× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle, normAngle \cdot \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right), n1\_i - n0\_i\right), n0\_i\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (fma
  u
  (fma
   normAngle
   (* normAngle (fma n0_i 0.3333333333333333 (* n1_i 0.16666666666666666)))
   (- n1_i n0_i))
  n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return fmaf(u, fmaf(normAngle, (normAngle * fmaf(n0_i, 0.3333333333333333f, (n1_i * 0.16666666666666666f))), (n1_i - n0_i)), n0_i);
}
function code(normAngle, u, n0_i, n1_i)
	return fma(u, fma(normAngle, Float32(normAngle * fma(n0_i, Float32(0.3333333333333333), Float32(n1_i * Float32(0.16666666666666666)))), Float32(n1_i - n0_i)), n0_i)
end
\begin{array}{l}

\\
\mathsf{fma}\left(u, \mathsf{fma}\left(normAngle, normAngle \cdot \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right), n1\_i - n0\_i\right), n0\_i\right)
\end{array}
Derivation
  1. Initial program 97.6%

    \[\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. Add Preprocessing
  3. Taylor expanded in u around 0

    \[\leadsto \color{blue}{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)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{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) + n0\_i} \]
    2. lower-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, -1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}, n0\_i\right)} \]
  5. Applied rewrites99.1%

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

    \[\leadsto \mathsf{fma}\left(u, \color{blue}{n1\_i + \left(-1 \cdot n0\_i + {normAngle}^{2} \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right)\right)}, n0\_i\right) \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(u, \color{blue}{\left(-1 \cdot n0\_i + {normAngle}^{2} \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right)\right) + n1\_i}, n0\_i\right) \]
    2. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(u, \color{blue}{\left({normAngle}^{2} \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right) + -1 \cdot n0\_i\right)} + n1\_i, n0\_i\right) \]
    3. associate-+l+N/A

      \[\leadsto \mathsf{fma}\left(u, \color{blue}{{normAngle}^{2} \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right) + \left(-1 \cdot n0\_i + n1\_i\right)}, n0\_i\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{fma}\left(u, \color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right) + \left(-1 \cdot n0\_i + n1\_i\right), n0\_i\right) \]
    5. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(u, \color{blue}{normAngle \cdot \left(normAngle \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right)\right)} + \left(-1 \cdot n0\_i + n1\_i\right), n0\_i\right) \]
    6. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(u, normAngle \cdot \left(normAngle \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right)\right) + \color{blue}{\left(n1\_i + -1 \cdot n0\_i\right)}, n0\_i\right) \]
    7. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(u, \color{blue}{\mathsf{fma}\left(normAngle, normAngle \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right), n1\_i + -1 \cdot n0\_i\right)}, n0\_i\right) \]
  8. Applied rewrites99.1%

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

Alternative 3: 98.8% accurate, 14.8× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(normAngle \cdot normAngle, u \cdot \left(n1\_i \cdot 0.16666666666666666\right), \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (fma
  (* normAngle normAngle)
  (* u (* n1_i 0.16666666666666666))
  (fma (- n1_i n0_i) u n0_i)))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return fmaf((normAngle * normAngle), (u * (n1_i * 0.16666666666666666f)), fmaf((n1_i - n0_i), u, n0_i));
}
function code(normAngle, u, n0_i, n1_i)
	return fma(Float32(normAngle * normAngle), Float32(u * Float32(n1_i * Float32(0.16666666666666666))), fma(Float32(n1_i - n0_i), u, n0_i))
end
\begin{array}{l}

\\
\mathsf{fma}\left(normAngle \cdot normAngle, u \cdot \left(n1\_i \cdot 0.16666666666666666\right), \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)\right)
\end{array}
Derivation
  1. Initial program 97.6%

    \[\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. Add Preprocessing
  3. Taylor expanded in u around 0

    \[\leadsto \color{blue}{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)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{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) + n0\_i} \]
    2. lower-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, -1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}, n0\_i\right)} \]
  5. Applied rewrites99.1%

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

    \[\leadsto \color{blue}{n0\_i + \left(u \cdot \left(n1\_i + -1 \cdot n0\_i\right) + {normAngle}^{2} \cdot \left(u \cdot \left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) - \frac{-1}{6} \cdot n1\_i\right)\right)\right)} \]
  7. Applied rewrites99.1%

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

    \[\leadsto \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{\left(\frac{1}{6} \cdot n1\_i\right)} \cdot u, \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)\right) \]
  9. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{\left(n1\_i \cdot \frac{1}{6}\right)} \cdot u, \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)\right) \]
    2. lower-*.f3299.1

      \[\leadsto \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{\left(n1\_i \cdot 0.16666666666666666\right)} \cdot u, \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)\right) \]
  10. Applied rewrites99.1%

    \[\leadsto \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{\left(n1\_i \cdot 0.16666666666666666\right)} \cdot u, \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)\right) \]
  11. Final simplification99.1%

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

Alternative 4: 98.3% accurate, 17.7× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, n0\_i \cdot 0.3333333333333333, n1\_i - n0\_i\right), n0\_i\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (fma
  u
  (fma (* normAngle normAngle) (* n0_i 0.3333333333333333) (- n1_i n0_i))
  n0_i))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return fmaf(u, fmaf((normAngle * normAngle), (n0_i * 0.3333333333333333f), (n1_i - n0_i)), n0_i);
}
function code(normAngle, u, n0_i, n1_i)
	return fma(u, fma(Float32(normAngle * normAngle), Float32(n0_i * Float32(0.3333333333333333)), Float32(n1_i - n0_i)), n0_i)
end
\begin{array}{l}

\\
\mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, n0\_i \cdot 0.3333333333333333, n1\_i - n0\_i\right), n0\_i\right)
\end{array}
Derivation
  1. Initial program 97.6%

    \[\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. Add Preprocessing
  3. Taylor expanded in u around 0

    \[\leadsto \color{blue}{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)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{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) + n0\_i} \]
    2. lower-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, -1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}, n0\_i\right)} \]
  5. Applied rewrites99.1%

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

    \[\leadsto \mathsf{fma}\left(u, \color{blue}{n1\_i + \left(-1 \cdot n0\_i + {normAngle}^{2} \cdot \left(\left(-1 \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) + {normAngle}^{2} \cdot \left(-1 \cdot \left(\frac{1}{24} \cdot n0\_i - \left(\frac{-1}{6} \cdot \left(\frac{-1}{2} \cdot n0\_i - \frac{-1}{6} \cdot n0\_i\right) + \frac{1}{120} \cdot n0\_i\right)\right) - \left(\frac{-1}{36} \cdot n1\_i + \frac{1}{120} \cdot n1\_i\right)\right)\right) - \frac{-1}{6} \cdot n1\_i\right)\right)}, n0\_i\right) \]
  7. Applied rewrites99.2%

    \[\leadsto \mathsf{fma}\left(u, \color{blue}{\mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, -\left(\left(n0\_i \cdot 0.041666666666666664 - \mathsf{fma}\left(n0\_i, 0.05555555555555555, n0\_i \cdot 0.008333333333333333\right)\right) + n1\_i \cdot -0.019444444444444445\right), \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right)\right), n1\_i - n0\_i\right)}, n0\_i\right) \]
  8. Taylor expanded in n0_i around 0

    \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{\frac{7}{360} \cdot n1\_i}, \mathsf{fma}\left(n0\_i, \frac{1}{3}, n1\_i \cdot \frac{1}{6}\right)\right), n1\_i - n0\_i\right), n0\_i\right) \]
  9. Step-by-step derivation
    1. lower-*.f3299.2

      \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{0.019444444444444445 \cdot n1\_i}, \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right)\right), n1\_i - n0\_i\right), n0\_i\right) \]
  10. Applied rewrites99.2%

    \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{0.019444444444444445 \cdot n1\_i}, \mathsf{fma}\left(n0\_i, 0.3333333333333333, n1\_i \cdot 0.16666666666666666\right)\right), n1\_i - n0\_i\right), n0\_i\right) \]
  11. Taylor expanded in n1_i around 0

    \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{\frac{1}{3} \cdot n0\_i}, n1\_i - n0\_i\right), n0\_i\right) \]
  12. Step-by-step derivation
    1. lower-*.f3298.6

      \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{0.3333333333333333 \cdot n0\_i}, n1\_i - n0\_i\right), n0\_i\right) \]
  13. Applied rewrites98.6%

    \[\leadsto \mathsf{fma}\left(u, \mathsf{fma}\left(normAngle \cdot normAngle, \color{blue}{0.3333333333333333 \cdot n0\_i}, n1\_i - n0\_i\right), n0\_i\right) \]
  14. Final simplification98.6%

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

Alternative 5: 85.5% accurate, 21.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1\_i \leq -4.999999841327613 \cdot 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\ \mathbf{elif}\;n1\_i \leq 1.0000000272452012 \cdot 10^{-27}:\\ \;\;\;\;\mathsf{fma}\left(n0\_i, -u, n0\_i\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (<= n1_i -4.999999841327613e-21)
   (fma u n1_i n0_i)
   (if (<= n1_i 1.0000000272452012e-27)
     (fma n0_i (- u) n0_i)
     (fma u n1_i n0_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if (n1_i <= -4.999999841327613e-21f) {
		tmp = fmaf(u, n1_i, n0_i);
	} else if (n1_i <= 1.0000000272452012e-27f) {
		tmp = fmaf(n0_i, -u, n0_i);
	} else {
		tmp = fmaf(u, n1_i, n0_i);
	}
	return tmp;
}
function code(normAngle, u, n0_i, n1_i)
	tmp = Float32(0.0)
	if (n1_i <= Float32(-4.999999841327613e-21))
		tmp = fma(u, n1_i, n0_i);
	elseif (n1_i <= Float32(1.0000000272452012e-27))
		tmp = fma(n0_i, Float32(-u), n0_i);
	else
		tmp = fma(u, n1_i, n0_i);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n1\_i \leq -4.999999841327613 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\

\mathbf{elif}\;n1\_i \leq 1.0000000272452012 \cdot 10^{-27}:\\
\;\;\;\;\mathsf{fma}\left(n0\_i, -u, n0\_i\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n1_i < -4.99999984e-21 or 1.00000003e-27 < n1_i

    1. Initial program 96.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 \]
    2. Add Preprocessing
    3. Taylor expanded in normAngle around 0

      \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
    4. Step-by-step derivation
      1. lower-fma.f32N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right)} \]
      2. lower--.f32N/A

        \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, n1\_i \cdot u\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
      4. lower-*.f3298.0

        \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
    5. Applied rewrites98.0%

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

      \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1}, u \cdot n1\_i\right) \]
    7. Step-by-step derivation
      1. Applied rewrites88.8%

        \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1}, u \cdot n1\_i\right) \]
      2. Step-by-step derivation
        1. lift-*.f32N/A

          \[\leadsto n0\_i \cdot 1 + \color{blue}{u \cdot n1\_i} \]
        2. *-rgt-identityN/A

          \[\leadsto \color{blue}{n0\_i} + u \cdot n1\_i \]
        3. +-commutativeN/A

          \[\leadsto \color{blue}{u \cdot n1\_i + n0\_i} \]
        4. lift-*.f32N/A

          \[\leadsto \color{blue}{u \cdot n1\_i} + n0\_i \]
        5. lower-fma.f3288.8

          \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1\_i, n0\_i\right)} \]
      3. Applied rewrites88.8%

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

      if -4.99999984e-21 < n1_i < 1.00000003e-27

      1. Initial program 98.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 \]
      2. Add Preprocessing
      3. Taylor expanded in normAngle around 0

        \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
      4. Step-by-step derivation
        1. lower-fma.f32N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right)} \]
        2. lower--.f32N/A

          \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, n1\_i \cdot u\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
        4. lower-*.f3298.6

          \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
      5. Applied rewrites98.6%

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

        \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right)} \]
      7. Step-by-step derivation
        1. sub-negN/A

          \[\leadsto n0\_i \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(u\right)\right)\right)} \]
        2. mul-1-negN/A

          \[\leadsto n0\_i \cdot \left(1 + \color{blue}{-1 \cdot u}\right) \]
        3. +-commutativeN/A

          \[\leadsto n0\_i \cdot \color{blue}{\left(-1 \cdot u + 1\right)} \]
        4. distribute-lft-inN/A

          \[\leadsto \color{blue}{n0\_i \cdot \left(-1 \cdot u\right) + n0\_i \cdot 1} \]
        5. *-rgt-identityN/A

          \[\leadsto n0\_i \cdot \left(-1 \cdot u\right) + \color{blue}{n0\_i} \]
        6. lower-fma.f32N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(n0\_i, -1 \cdot u, n0\_i\right)} \]
        7. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{\mathsf{neg}\left(u\right)}, n0\_i\right) \]
        8. lower-neg.f3290.0

          \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{-u}, n0\_i\right) \]
      8. Applied rewrites90.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(n0\_i, -u, n0\_i\right)} \]
    8. Recombined 2 regimes into one program.
    9. Add Preprocessing

    Alternative 6: 85.0% accurate, 21.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1\_i \leq -4.999999841327613 \cdot 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\ \mathbf{elif}\;n1\_i \leq 9.999999796611898 \cdot 10^{-32}:\\ \;\;\;\;n0\_i \cdot \left(1 - u\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\ \end{array} \end{array} \]
    (FPCore (normAngle u n0_i n1_i)
     :precision binary32
     (if (<= n1_i -4.999999841327613e-21)
       (fma u n1_i n0_i)
       (if (<= n1_i 9.999999796611898e-32) (* n0_i (- 1.0 u)) (fma u n1_i n0_i))))
    float code(float normAngle, float u, float n0_i, float n1_i) {
    	float tmp;
    	if (n1_i <= -4.999999841327613e-21f) {
    		tmp = fmaf(u, n1_i, n0_i);
    	} else if (n1_i <= 9.999999796611898e-32f) {
    		tmp = n0_i * (1.0f - u);
    	} else {
    		tmp = fmaf(u, n1_i, n0_i);
    	}
    	return tmp;
    }
    
    function code(normAngle, u, n0_i, n1_i)
    	tmp = Float32(0.0)
    	if (n1_i <= Float32(-4.999999841327613e-21))
    		tmp = fma(u, n1_i, n0_i);
    	elseif (n1_i <= Float32(9.999999796611898e-32))
    		tmp = Float32(n0_i * Float32(Float32(1.0) - u));
    	else
    		tmp = fma(u, n1_i, n0_i);
    	end
    	return tmp
    end
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;n1\_i \leq -4.999999841327613 \cdot 10^{-21}:\\
    \;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\
    
    \mathbf{elif}\;n1\_i \leq 9.999999796611898 \cdot 10^{-32}:\\
    \;\;\;\;n0\_i \cdot \left(1 - u\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(u, n1\_i, n0\_i\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if n1_i < -4.99999984e-21 or 9.9999998e-32 < n1_i

      1. Initial program 96.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 \]
      2. Add Preprocessing
      3. Taylor expanded in normAngle around 0

        \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
      4. Step-by-step derivation
        1. lower-fma.f32N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right)} \]
        2. lower--.f32N/A

          \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, n1\_i \cdot u\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
        4. lower-*.f3298.0

          \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
      5. Applied rewrites98.0%

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

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

          \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1}, u \cdot n1\_i\right) \]
        2. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto n0\_i \cdot 1 + \color{blue}{u \cdot n1\_i} \]
          2. *-rgt-identityN/A

            \[\leadsto \color{blue}{n0\_i} + u \cdot n1\_i \]
          3. +-commutativeN/A

            \[\leadsto \color{blue}{u \cdot n1\_i + n0\_i} \]
          4. lift-*.f32N/A

            \[\leadsto \color{blue}{u \cdot n1\_i} + n0\_i \]
          5. lower-fma.f3288.4

            \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1\_i, n0\_i\right)} \]
        3. Applied rewrites88.4%

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

        if -4.99999984e-21 < n1_i < 9.9999998e-32

        1. Initial program 98.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 \]
        2. Add Preprocessing
        3. Taylor expanded in n0_i around inf

          \[\leadsto \color{blue}{\frac{n0\_i \cdot \sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
        4. Step-by-step derivation
          1. associate-/l*N/A

            \[\leadsto \color{blue}{n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
          2. lower-*.f32N/A

            \[\leadsto \color{blue}{n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
          3. lower-/.f32N/A

            \[\leadsto n0\_i \cdot \color{blue}{\frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
          4. lower-sin.f32N/A

            \[\leadsto n0\_i \cdot \frac{\color{blue}{\sin \left(normAngle \cdot \left(1 - u\right)\right)}}{\sin normAngle} \]
          5. *-commutativeN/A

            \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle} \]
          6. sub-negN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(u\right)\right)\right)} \cdot normAngle\right)}{\sin normAngle} \]
          7. +-commutativeN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(\left(\mathsf{neg}\left(u\right)\right) + 1\right)} \cdot normAngle\right)}{\sin normAngle} \]
          8. distribute-lft1-inN/A

            \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\left(\mathsf{neg}\left(u\right)\right) \cdot normAngle + normAngle\right)}}{\sin normAngle} \]
          9. distribute-lft-neg-inN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(\mathsf{neg}\left(u \cdot normAngle\right)\right)} + normAngle\right)}{\sin normAngle} \]
          10. distribute-rgt-neg-inN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{u \cdot \left(\mathsf{neg}\left(normAngle\right)\right)} + normAngle\right)}{\sin normAngle} \]
          11. mul-1-negN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(u \cdot \color{blue}{\left(-1 \cdot normAngle\right)} + normAngle\right)}{\sin normAngle} \]
          12. lower-fma.f32N/A

            \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\mathsf{fma}\left(u, -1 \cdot normAngle, normAngle\right)\right)}}{\sin normAngle} \]
          13. mul-1-negN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, \color{blue}{\mathsf{neg}\left(normAngle\right)}, normAngle\right)\right)}{\sin normAngle} \]
          14. lower-neg.f32N/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, \color{blue}{\mathsf{neg}\left(normAngle\right)}, normAngle\right)\right)}{\sin normAngle} \]
          15. lower-sin.f3290.7

            \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, -normAngle, normAngle\right)\right)}{\color{blue}{\sin normAngle}} \]
        5. Applied rewrites90.7%

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

          \[\leadsto n0\_i \cdot \color{blue}{\left(1 + -1 \cdot u\right)} \]
        7. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto n0\_i \cdot \left(1 + \color{blue}{\left(\mathsf{neg}\left(u\right)\right)}\right) \]
          2. sub-negN/A

            \[\leadsto n0\_i \cdot \color{blue}{\left(1 - u\right)} \]
          3. lower--.f3290.3

            \[\leadsto n0\_i \cdot \color{blue}{\left(1 - u\right)} \]
        8. Applied rewrites90.3%

          \[\leadsto n0\_i \cdot \color{blue}{\left(1 - u\right)} \]
      8. Recombined 2 regimes into one program.
      9. Add Preprocessing

      Alternative 7: 60.6% accurate, 25.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n0\_i \leq -1.4999999523982838 \cdot 10^{-21}:\\ \;\;\;\;n0\_i\\ \mathbf{elif}\;n0\_i \leq 4.999999841327613 \cdot 10^{-22}:\\ \;\;\;\;u \cdot n1\_i\\ \mathbf{else}:\\ \;\;\;\;n0\_i\\ \end{array} \end{array} \]
      (FPCore (normAngle u n0_i n1_i)
       :precision binary32
       (if (<= n0_i -1.4999999523982838e-21)
         n0_i
         (if (<= n0_i 4.999999841327613e-22) (* u n1_i) n0_i)))
      float code(float normAngle, float u, float n0_i, float n1_i) {
      	float tmp;
      	if (n0_i <= -1.4999999523982838e-21f) {
      		tmp = n0_i;
      	} else if (n0_i <= 4.999999841327613e-22f) {
      		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 (n0_i <= (-1.4999999523982838e-21)) then
              tmp = n0_i
          else if (n0_i <= 4.999999841327613e-22) 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 (n0_i <= Float32(-1.4999999523982838e-21))
      		tmp = n0_i;
      	elseif (n0_i <= Float32(4.999999841327613e-22))
      		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 (n0_i <= single(-1.4999999523982838e-21))
      		tmp = n0_i;
      	elseif (n0_i <= single(4.999999841327613e-22))
      		tmp = u * n1_i;
      	else
      		tmp = n0_i;
      	end
      	tmp_2 = tmp;
      end
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;n0\_i \leq -1.4999999523982838 \cdot 10^{-21}:\\
      \;\;\;\;n0\_i\\
      
      \mathbf{elif}\;n0\_i \leq 4.999999841327613 \cdot 10^{-22}:\\
      \;\;\;\;u \cdot n1\_i\\
      
      \mathbf{else}:\\
      \;\;\;\;n0\_i\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if n0_i < -1.5e-21 or 4.9999998e-22 < n0_i

        1. Initial program 98.4%

          \[\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. Add Preprocessing
        3. Taylor expanded in n0_i around inf

          \[\leadsto \color{blue}{\frac{n0\_i \cdot \sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
        4. Step-by-step derivation
          1. associate-/l*N/A

            \[\leadsto \color{blue}{n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
          2. lower-*.f32N/A

            \[\leadsto \color{blue}{n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
          3. lower-/.f32N/A

            \[\leadsto n0\_i \cdot \color{blue}{\frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
          4. lower-sin.f32N/A

            \[\leadsto n0\_i \cdot \frac{\color{blue}{\sin \left(normAngle \cdot \left(1 - u\right)\right)}}{\sin normAngle} \]
          5. *-commutativeN/A

            \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle} \]
          6. sub-negN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(u\right)\right)\right)} \cdot normAngle\right)}{\sin normAngle} \]
          7. +-commutativeN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(\left(\mathsf{neg}\left(u\right)\right) + 1\right)} \cdot normAngle\right)}{\sin normAngle} \]
          8. distribute-lft1-inN/A

            \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\left(\mathsf{neg}\left(u\right)\right) \cdot normAngle + normAngle\right)}}{\sin normAngle} \]
          9. distribute-lft-neg-inN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(\mathsf{neg}\left(u \cdot normAngle\right)\right)} + normAngle\right)}{\sin normAngle} \]
          10. distribute-rgt-neg-inN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{u \cdot \left(\mathsf{neg}\left(normAngle\right)\right)} + normAngle\right)}{\sin normAngle} \]
          11. mul-1-negN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(u \cdot \color{blue}{\left(-1 \cdot normAngle\right)} + normAngle\right)}{\sin normAngle} \]
          12. lower-fma.f32N/A

            \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\mathsf{fma}\left(u, -1 \cdot normAngle, normAngle\right)\right)}}{\sin normAngle} \]
          13. mul-1-negN/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, \color{blue}{\mathsf{neg}\left(normAngle\right)}, normAngle\right)\right)}{\sin normAngle} \]
          14. lower-neg.f32N/A

            \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, \color{blue}{\mathsf{neg}\left(normAngle\right)}, normAngle\right)\right)}{\sin normAngle} \]
          15. lower-sin.f3286.3

            \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, -normAngle, normAngle\right)\right)}{\color{blue}{\sin normAngle}} \]
        5. Applied rewrites86.3%

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

          \[\leadsto n0\_i \cdot \color{blue}{1} \]
        7. Step-by-step derivation
          1. Applied rewrites67.7%

            \[\leadsto n0\_i \cdot \color{blue}{1} \]
          2. Step-by-step derivation
            1. *-rgt-identity67.7

              \[\leadsto \color{blue}{n0\_i} \]
          3. Applied rewrites67.7%

            \[\leadsto \color{blue}{n0\_i} \]

          if -1.5e-21 < n0_i < 4.9999998e-22

          1. Initial program 96.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 \]
          2. Add Preprocessing
          3. Taylor expanded in normAngle around 0

            \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
          4. Step-by-step derivation
            1. lower-fma.f32N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right)} \]
            2. lower--.f32N/A

              \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, n1\_i \cdot u\right) \]
            3. *-commutativeN/A

              \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
            4. lower-*.f3298.0

              \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
          5. Applied rewrites98.0%

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

            \[\leadsto \color{blue}{n1\_i \cdot u} \]
          7. Step-by-step derivation
            1. lower-*.f3264.0

              \[\leadsto \color{blue}{n1\_i \cdot u} \]
          8. Applied rewrites64.0%

            \[\leadsto \color{blue}{n1\_i \cdot u} \]
        8. Recombined 2 regimes into one program.
        9. Final simplification65.9%

          \[\leadsto \begin{array}{l} \mathbf{if}\;n0\_i \leq -1.4999999523982838 \cdot 10^{-21}:\\ \;\;\;\;n0\_i\\ \mathbf{elif}\;n0\_i \leq 4.999999841327613 \cdot 10^{-22}:\\ \;\;\;\;u \cdot n1\_i\\ \mathbf{else}:\\ \;\;\;\;n0\_i\\ \end{array} \]
        10. Add Preprocessing

        Alternative 8: 98.1% accurate, 45.9× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \end{array} \]
        (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}
        
        Derivation
        1. Initial program 97.6%

          \[\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. Add Preprocessing
        3. Taylor expanded in u around 0

          \[\leadsto \color{blue}{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)} \]
        4. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{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) + n0\_i} \]
          2. lower-fma.f32N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(u, -1 \cdot \frac{n0\_i \cdot \left(normAngle \cdot \cos normAngle\right)}{\sin normAngle} + \frac{n1\_i \cdot normAngle}{\sin normAngle}, n0\_i\right)} \]
        5. Applied rewrites99.1%

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

          \[\leadsto \color{blue}{n0\_i + u \cdot \left(n1\_i + -1 \cdot n0\_i\right)} \]
        7. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{u \cdot \left(n1\_i + -1 \cdot n0\_i\right) + n0\_i} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\left(n1\_i + -1 \cdot n0\_i\right) \cdot u} + n0\_i \]
          3. lower-fma.f32N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(n1\_i + -1 \cdot n0\_i, u, n0\_i\right)} \]
          4. mul-1-negN/A

            \[\leadsto \mathsf{fma}\left(n1\_i + \color{blue}{\left(\mathsf{neg}\left(n0\_i\right)\right)}, u, n0\_i\right) \]
          5. unsub-negN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{n1\_i - n0\_i}, u, n0\_i\right) \]
          6. lower--.f3298.6

            \[\leadsto \mathsf{fma}\left(\color{blue}{n1\_i - n0\_i}, u, n0\_i\right) \]
        8. Applied rewrites98.6%

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

        Alternative 9: 81.5% accurate, 65.6× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(u, n1\_i, n0\_i\right) \end{array} \]
        (FPCore (normAngle u n0_i n1_i) :precision binary32 (fma u n1_i n0_i))
        float code(float normAngle, float u, float n0_i, float n1_i) {
        	return fmaf(u, n1_i, n0_i);
        }
        
        function code(normAngle, u, n0_i, n1_i)
        	return fma(u, n1_i, n0_i)
        end
        
        \begin{array}{l}
        
        \\
        \mathsf{fma}\left(u, n1\_i, n0\_i\right)
        \end{array}
        
        Derivation
        1. Initial program 97.6%

          \[\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. Add Preprocessing
        3. Taylor expanded in normAngle around 0

          \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
        4. Step-by-step derivation
          1. lower-fma.f32N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right)} \]
          2. lower--.f32N/A

            \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, n1\_i \cdot u\right) \]
          3. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
          4. lower-*.f3298.2

            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \color{blue}{u \cdot n1\_i}\right) \]
        5. Applied rewrites98.2%

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

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

            \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1}, u \cdot n1\_i\right) \]
          2. Step-by-step derivation
            1. lift-*.f32N/A

              \[\leadsto n0\_i \cdot 1 + \color{blue}{u \cdot n1\_i} \]
            2. *-rgt-identityN/A

              \[\leadsto \color{blue}{n0\_i} + u \cdot n1\_i \]
            3. +-commutativeN/A

              \[\leadsto \color{blue}{u \cdot n1\_i + n0\_i} \]
            4. lift-*.f32N/A

              \[\leadsto \color{blue}{u \cdot n1\_i} + n0\_i \]
            5. lower-fma.f3282.5

              \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1\_i, n0\_i\right)} \]
          3. Applied rewrites82.5%

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

          Alternative 10: 47.5% accurate, 459.0× speedup?

          \[\begin{array}{l} \\ n0\_i \end{array} \]
          (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}
          
          Derivation
          1. Initial program 97.6%

            \[\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. Add Preprocessing
          3. Taylor expanded in n0_i around inf

            \[\leadsto \color{blue}{\frac{n0\_i \cdot \sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
          4. Step-by-step derivation
            1. associate-/l*N/A

              \[\leadsto \color{blue}{n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
            2. lower-*.f32N/A

              \[\leadsto \color{blue}{n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
            3. lower-/.f32N/A

              \[\leadsto n0\_i \cdot \color{blue}{\frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
            4. lower-sin.f32N/A

              \[\leadsto n0\_i \cdot \frac{\color{blue}{\sin \left(normAngle \cdot \left(1 - u\right)\right)}}{\sin normAngle} \]
            5. *-commutativeN/A

              \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle} \]
            6. sub-negN/A

              \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(u\right)\right)\right)} \cdot normAngle\right)}{\sin normAngle} \]
            7. +-commutativeN/A

              \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(\left(\mathsf{neg}\left(u\right)\right) + 1\right)} \cdot normAngle\right)}{\sin normAngle} \]
            8. distribute-lft1-inN/A

              \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\left(\mathsf{neg}\left(u\right)\right) \cdot normAngle + normAngle\right)}}{\sin normAngle} \]
            9. distribute-lft-neg-inN/A

              \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{\left(\mathsf{neg}\left(u \cdot normAngle\right)\right)} + normAngle\right)}{\sin normAngle} \]
            10. distribute-rgt-neg-inN/A

              \[\leadsto n0\_i \cdot \frac{\sin \left(\color{blue}{u \cdot \left(\mathsf{neg}\left(normAngle\right)\right)} + normAngle\right)}{\sin normAngle} \]
            11. mul-1-negN/A

              \[\leadsto n0\_i \cdot \frac{\sin \left(u \cdot \color{blue}{\left(-1 \cdot normAngle\right)} + normAngle\right)}{\sin normAngle} \]
            12. lower-fma.f32N/A

              \[\leadsto n0\_i \cdot \frac{\sin \color{blue}{\left(\mathsf{fma}\left(u, -1 \cdot normAngle, normAngle\right)\right)}}{\sin normAngle} \]
            13. mul-1-negN/A

              \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, \color{blue}{\mathsf{neg}\left(normAngle\right)}, normAngle\right)\right)}{\sin normAngle} \]
            14. lower-neg.f32N/A

              \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, \color{blue}{\mathsf{neg}\left(normAngle\right)}, normAngle\right)\right)}{\sin normAngle} \]
            15. lower-sin.f3260.0

              \[\leadsto n0\_i \cdot \frac{\sin \left(\mathsf{fma}\left(u, -normAngle, normAngle\right)\right)}{\color{blue}{\sin normAngle}} \]
          5. Applied rewrites60.0%

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

            \[\leadsto n0\_i \cdot \color{blue}{1} \]
          7. Step-by-step derivation
            1. Applied rewrites48.4%

              \[\leadsto n0\_i \cdot \color{blue}{1} \]
            2. Step-by-step derivation
              1. *-rgt-identity48.4

                \[\leadsto \color{blue}{n0\_i} \]
            3. Applied rewrites48.4%

              \[\leadsto \color{blue}{n0\_i} \]
            4. Add Preprocessing

            Reproduce

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