Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.2% → 99.0%
Time: 5.7s
Alternatives: 11
Speedup: 30.6×

Specification

?
\[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\mathsf{PI}\left(\right)}{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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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}

\\
\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 11 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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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}

\\
\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.0% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right), normAngle \cdot normAngle, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+
  (*
   (-
    (fma
     (* -0.16666666666666666 (- (pow (- 1.0 u) 3.0) (- 1.0 u)))
     (* normAngle normAngle)
     1.0)
    u)
   n0_i)
  (* (* normAngle (/ u (sin normAngle))) n1_i)))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return ((fmaf((-0.16666666666666666f * (powf((1.0f - u), 3.0f) - (1.0f - u))), (normAngle * normAngle), 1.0f) - u) * n0_i) + ((normAngle * (u / sinf(normAngle))) * n1_i);
}
function code(normAngle, u, n0_i, n1_i)
	return Float32(Float32(Float32(fma(Float32(Float32(-0.16666666666666666) * Float32((Float32(Float32(1.0) - u) ^ Float32(3.0)) - Float32(Float32(1.0) - u))), Float32(normAngle * normAngle), Float32(1.0)) - u) * n0_i) + Float32(Float32(normAngle * Float32(u / sin(normAngle))) * n1_i))
end
\begin{array}{l}

\\
\left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right), normAngle \cdot normAngle, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i
\end{array}
Derivation
  1. Initial program 96.5%

    \[\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 \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\frac{normAngle \cdot u}{\sin normAngle}} \cdot n1\_i \]
  4. Step-by-step derivation
    1. associate-/l*N/A

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

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

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\color{blue}{\sin normAngle}}\right) \cdot n1\_i \]
    4. lower-sin.f3298.0

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  5. Applied rewrites98.0%

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

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

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

      \[\leadsto \left(\left({normAngle}^{2} \cdot \left(\frac{-1}{6} \cdot {\left(1 - u\right)}^{3} - \frac{-1}{6} \cdot \left(1 - u\right)\right) + 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    3. *-commutativeN/A

      \[\leadsto \left(\left(\left(\frac{-1}{6} \cdot {\left(1 - u\right)}^{3} - \frac{-1}{6} \cdot \left(1 - u\right)\right) \cdot {normAngle}^{2} + 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    4. lower-fma.f32N/A

      \[\leadsto \left(\mathsf{fma}\left(\frac{-1}{6} \cdot {\left(1 - u\right)}^{3} - \frac{-1}{6} \cdot \left(1 - u\right), {normAngle}^{2}, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    5. distribute-lft-out--N/A

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

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

      \[\leadsto \left(\mathsf{fma}\left(\frac{-1}{6} \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right), {normAngle}^{2}, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    8. lower-pow.f32N/A

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

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

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

      \[\leadsto \left(\mathsf{fma}\left(\frac{-1}{6} \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right), normAngle \cdot normAngle, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    12. lower-*.f3298.9

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

    \[\leadsto \color{blue}{\left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right), normAngle \cdot normAngle, 1\right) - u\right)} \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  9. Final simplification98.9%

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

Alternative 2: 98.9% accurate, 3.1× speedup?

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

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

    \[\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 \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\frac{normAngle \cdot u}{\sin normAngle}} \cdot n1\_i \]
  4. Step-by-step derivation
    1. associate-/l*N/A

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

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

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\color{blue}{\sin normAngle}}\right) \cdot n1\_i \]
    4. lower-sin.f3298.0

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  5. Applied rewrites98.0%

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

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

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

      \[\leadsto \left(\left({normAngle}^{2} \cdot \left(\frac{-1}{6} \cdot {\left(1 - u\right)}^{3} - \frac{-1}{6} \cdot \left(1 - u\right)\right) + 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    3. *-commutativeN/A

      \[\leadsto \left(\left(\left(\frac{-1}{6} \cdot {\left(1 - u\right)}^{3} - \frac{-1}{6} \cdot \left(1 - u\right)\right) \cdot {normAngle}^{2} + 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    4. lower-fma.f32N/A

      \[\leadsto \left(\mathsf{fma}\left(\frac{-1}{6} \cdot {\left(1 - u\right)}^{3} - \frac{-1}{6} \cdot \left(1 - u\right), {normAngle}^{2}, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    5. distribute-lft-out--N/A

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

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

      \[\leadsto \left(\mathsf{fma}\left(\frac{-1}{6} \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right), {normAngle}^{2}, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    8. lower-pow.f32N/A

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

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

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

      \[\leadsto \left(\mathsf{fma}\left(\frac{-1}{6} \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right), normAngle \cdot normAngle, 1\right) - u\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    12. lower-*.f3298.9

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

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

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

      \[\leadsto \left(u \cdot \left(\frac{1}{3} \cdot {normAngle}^{2} - 1\right) + 1\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    2. *-commutativeN/A

      \[\leadsto \left(\left(\frac{1}{3} \cdot {normAngle}^{2} - 1\right) \cdot u + 1\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    3. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{3} \cdot {normAngle}^{2} - 1, u, 1\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    4. lower--.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{3} \cdot {normAngle}^{2} - 1, u, 1\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    5. lower-*.f32N/A

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{3} \cdot \left(normAngle \cdot normAngle\right) - 1, u, 1\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
    7. lower-*.f3298.9

      \[\leadsto \mathsf{fma}\left(0.3333333333333333 \cdot \left(normAngle \cdot normAngle\right) - 1, u, 1\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  11. Applied rewrites98.9%

    \[\leadsto \mathsf{fma}\left(0.3333333333333333 \cdot \left(normAngle \cdot normAngle\right) - 1, \color{blue}{u}, 1\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  12. Final simplification98.9%

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

Alternative 3: 99.1% accurate, 7.2× speedup?

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

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

    \[\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) + \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)} \]
  4. Step-by-step derivation
    1. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, 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) \]
    2. lower--.f32N/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - \color{blue}{u}, 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. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - 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) + n1\_i \cdot u\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \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) \cdot {normAngle}^{2} + n1\_i \cdot u\right) \]
    5. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \mathsf{fma}\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), {normAngle}^{2}, n1\_i \cdot u\right)\right) \]
  5. Applied rewrites98.6%

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

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

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

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

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

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

Alternative 4: 99.0% accurate, 11.5× speedup?

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

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

    \[\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) + \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)} \]
  4. Step-by-step derivation
    1. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, 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) \]
    2. lower--.f32N/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - \color{blue}{u}, 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. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - 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) + n1\_i \cdot u\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \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) \cdot {normAngle}^{2} + n1\_i \cdot u\right) \]
    5. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \mathsf{fma}\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), {normAngle}^{2}, n1\_i \cdot u\right)\right) \]
  5. Applied rewrites98.6%

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

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

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

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

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

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

Alternative 5: 98.5% accurate, 13.9× speedup?

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

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

    \[\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 \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\frac{normAngle \cdot u}{\sin normAngle}} \cdot n1\_i \]
  4. Step-by-step derivation
    1. associate-/l*N/A

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

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

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\color{blue}{\sin normAngle}}\right) \cdot n1\_i \]
    4. lower-sin.f3298.0

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  5. Applied rewrites98.0%

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

    \[\leadsto \color{blue}{\left(1 - u\right)} \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  7. Step-by-step derivation
    1. lower--.f3298.5

      \[\leadsto \left(1 - \color{blue}{u}\right) \cdot n0\_i + \left(normAngle \cdot \frac{u}{\sin normAngle}\right) \cdot n1\_i \]
  8. Applied rewrites98.5%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 71.5% accurate, 21.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1\_i \leq -1.0499999912357231 \cdot 10^{-17} \lor \neg \left(n1\_i \leq 9.9999998245167 \cdot 10^{-14}\right):\\ \;\;\;\;n1\_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0\_i \cdot \left(1 - u\right)\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (or (<= n1_i -1.0499999912357231e-17) (not (<= n1_i 9.9999998245167e-14)))
   (* n1_i u)
   (* n0_i (- 1.0 u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if ((n1_i <= -1.0499999912357231e-17f) || !(n1_i <= 9.9999998245167e-14f)) {
		tmp = n1_i * u;
	} else {
		tmp = n0_i * (1.0f - u);
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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) :: tmp
    if ((n1_i <= (-1.0499999912357231e-17)) .or. (.not. (n1_i <= 9.9999998245167e-14))) then
        tmp = n1_i * u
    else
        tmp = n0_i * (1.0e0 - u)
    end if
    code = tmp
end function
function code(normAngle, u, n0_i, n1_i)
	tmp = Float32(0.0)
	if ((n1_i <= Float32(-1.0499999912357231e-17)) || !(n1_i <= Float32(9.9999998245167e-14)))
		tmp = Float32(n1_i * u);
	else
		tmp = Float32(n0_i * Float32(Float32(1.0) - u));
	end
	return tmp
end
function tmp_2 = code(normAngle, u, n0_i, n1_i)
	tmp = single(0.0);
	if ((n1_i <= single(-1.0499999912357231e-17)) || ~((n1_i <= single(9.9999998245167e-14))))
		tmp = n1_i * u;
	else
		tmp = n0_i * (single(1.0) - u);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n1\_i \leq -1.0499999912357231 \cdot 10^{-17} \lor \neg \left(n1\_i \leq 9.9999998245167 \cdot 10^{-14}\right):\\
\;\;\;\;n1\_i \cdot u\\

\mathbf{else}:\\
\;\;\;\;n0\_i \cdot \left(1 - u\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n1_i < -1.04999999e-17 or 9.99999982e-14 < n1_i

    1. Initial program 96.5%

      \[\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 0

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

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

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

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

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

        \[\leadsto n1\_i \cdot \frac{\sin \left(normAngle \cdot u\right)}{\sin normAngle} \]
      6. lower-sin.f32N/A

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

        \[\leadsto n1\_i \cdot \frac{\sin \left(normAngle \cdot u\right)}{\sin normAngle} \]
      8. lower-sin.f3266.8

        \[\leadsto n1\_i \cdot \frac{\sin \left(normAngle \cdot u\right)}{\sin normAngle} \]
    5. Applied rewrites66.8%

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

      \[\leadsto n1\_i \cdot u \]
    7. Step-by-step derivation
      1. Applied rewrites67.1%

        \[\leadsto n1\_i \cdot u \]

      if -1.04999999e-17 < n1_i < 9.99999982e-14

      1. Initial program 96.5%

        \[\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 n0\_i \cdot \color{blue}{\frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle}} \]
        2. lower-*.f32N/A

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

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

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

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

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

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

          \[\leadsto n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle} \]
        9. lower-sin.f3278.5

          \[\leadsto n0\_i \cdot \frac{\sin \left(normAngle \cdot \left(1 - u\right)\right)}{\sin normAngle} \]
      5. Applied rewrites78.5%

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

        \[\leadsto n0\_i \cdot \left(1 - \color{blue}{u}\right) \]
      7. Step-by-step derivation
        1. lower--.f3278.4

          \[\leadsto n0\_i \cdot \left(1 - u\right) \]
      8. Applied rewrites78.4%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;n1\_i \leq -1.0499999912357231 \cdot 10^{-17} \lor \neg \left(n1\_i \leq 9.9999998245167 \cdot 10^{-14}\right):\\ \;\;\;\;n1\_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0\_i \cdot \left(1 - u\right)\\ \end{array} \]
    10. Add Preprocessing

    Alternative 7: 61.3% accurate, 25.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1\_i \leq -1.0499999912357231 \cdot 10^{-17} \lor \neg \left(n1\_i \leq 9.9999998245167 \cdot 10^{-15}\right):\\ \;\;\;\;n1\_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0\_i\\ \end{array} \end{array} \]
    (FPCore (normAngle u n0_i n1_i)
     :precision binary32
     (if (or (<= n1_i -1.0499999912357231e-17) (not (<= n1_i 9.9999998245167e-15)))
       (* n1_i u)
       n0_i))
    float code(float normAngle, float u, float n0_i, float n1_i) {
    	float tmp;
    	if ((n1_i <= -1.0499999912357231e-17f) || !(n1_i <= 9.9999998245167e-15f)) {
    		tmp = n1_i * u;
    	} else {
    		tmp = n0_i;
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    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) :: tmp
        if ((n1_i <= (-1.0499999912357231e-17)) .or. (.not. (n1_i <= 9.9999998245167e-15))) then
            tmp = n1_i * u
        else
            tmp = n0_i
        end if
        code = tmp
    end function
    
    function code(normAngle, u, n0_i, n1_i)
    	tmp = Float32(0.0)
    	if ((n1_i <= Float32(-1.0499999912357231e-17)) || !(n1_i <= Float32(9.9999998245167e-15)))
    		tmp = Float32(n1_i * u);
    	else
    		tmp = n0_i;
    	end
    	return tmp
    end
    
    function tmp_2 = code(normAngle, u, n0_i, n1_i)
    	tmp = single(0.0);
    	if ((n1_i <= single(-1.0499999912357231e-17)) || ~((n1_i <= single(9.9999998245167e-15))))
    		tmp = n1_i * u;
    	else
    		tmp = n0_i;
    	end
    	tmp_2 = tmp;
    end
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;n1\_i \leq -1.0499999912357231 \cdot 10^{-17} \lor \neg \left(n1\_i \leq 9.9999998245167 \cdot 10^{-15}\right):\\
    \;\;\;\;n1\_i \cdot u\\
    
    \mathbf{else}:\\
    \;\;\;\;n0\_i\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if n1_i < -1.04999999e-17 or 9.99999982e-15 < n1_i

      1. Initial program 96.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 0

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

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

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

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

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

          \[\leadsto n1\_i \cdot \frac{\sin \left(normAngle \cdot u\right)}{\sin normAngle} \]
        6. lower-sin.f32N/A

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

          \[\leadsto n1\_i \cdot \frac{\sin \left(normAngle \cdot u\right)}{\sin normAngle} \]
        8. lower-sin.f3264.8

          \[\leadsto n1\_i \cdot \frac{\sin \left(normAngle \cdot u\right)}{\sin normAngle} \]
      5. Applied rewrites64.8%

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

        \[\leadsto n1\_i \cdot u \]
      7. Step-by-step derivation
        1. Applied rewrites65.1%

          \[\leadsto n1\_i \cdot u \]

        if -1.04999999e-17 < n1_i < 9.99999982e-15

        1. Initial program 96.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 u around 0

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

            \[\leadsto \color{blue}{n0\_i} \]
        5. Recombined 2 regimes into one program.
        6. Final simplification64.3%

          \[\leadsto \begin{array}{l} \mathbf{if}\;n1\_i \leq -1.0499999912357231 \cdot 10^{-17} \lor \neg \left(n1\_i \leq 9.9999998245167 \cdot 10^{-15}\right):\\ \;\;\;\;n1\_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0\_i\\ \end{array} \]
        7. Add Preprocessing

        Alternative 8: 97.9% accurate, 30.6× speedup?

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

          \[\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. +-commutativeN/A

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

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

            \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i \cdot \left(1 - u\right)\right) \]
          4. lower--.f3297.8

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

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

        Alternative 9: 97.8% accurate, 30.6× speedup?

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

          \[\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) + \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)} \]
        4. Step-by-step derivation
          1. lower-fma.f32N/A

            \[\leadsto \mathsf{fma}\left(n0\_i, \color{blue}{1 - u}, 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) \]
          2. lower--.f32N/A

            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - \color{blue}{u}, 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. +-commutativeN/A

            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - 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) + n1\_i \cdot u\right) \]
          4. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \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) \cdot {normAngle}^{2} + n1\_i \cdot u\right) \]
          5. lower-fma.f32N/A

            \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, \mathsf{fma}\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), {normAngle}^{2}, n1\_i \cdot u\right)\right) \]
        5. Applied rewrites98.6%

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

          \[\leadsto \mathsf{fma}\left(n0\_i, 1 - u, n1\_i \cdot u\right) \]
        7. Step-by-step derivation
          1. lower-*.f3297.7

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

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

        Alternative 10: 81.8% accurate, 51.0× speedup?

        \[\begin{array}{l} \\ n0\_i + u \cdot n1\_i \end{array} \]
        (FPCore (normAngle u n0_i n1_i) :precision binary32 (+ n0_i (* u n1_i)))
        float code(float normAngle, float u, float n0_i, float n1_i) {
        	return n0_i + (u * n1_i);
        }
        
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        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 = n0_i + (u * n1_i)
        end function
        
        function code(normAngle, u, n0_i, n1_i)
        	return Float32(n0_i + Float32(u * n1_i))
        end
        
        function tmp = code(normAngle, u, n0_i, n1_i)
        	tmp = n0_i + (u * n1_i);
        end
        
        \begin{array}{l}
        
        \\
        n0\_i + u \cdot n1\_i
        \end{array}
        
        Derivation
        1. Initial program 96.5%

          \[\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 \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{u} \cdot n1\_i \]
        4. Step-by-step derivation
          1. Applied rewrites96.9%

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

            \[\leadsto \color{blue}{n0\_i} + u \cdot n1\_i \]
          3. Step-by-step derivation
            1. Applied rewrites82.4%

              \[\leadsto \color{blue}{n0\_i} + u \cdot n1\_i \]
            2. Final simplification82.4%

              \[\leadsto n0\_i + u \cdot n1\_i \]
            3. Add Preprocessing

            Alternative 11: 46.8% 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;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            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 = 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 96.5%

              \[\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} \]
            4. Step-by-step derivation
              1. Applied rewrites47.2%

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

              Reproduce

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