Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.2% → 99.0%
Time: 4.5s
Alternatives: 7
Speedup: 19.0×

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);
}
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}

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 7 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, 5.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\left(n1\_i + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot n0\_i - \mathsf{fma}\left(-0.5, n0\_i, -0.16666666666666666 \cdot n1\_i\right)\right)\right) - n0\_i, u, n0\_i\right) \]
  7. Applied rewrites99.0%

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

Alternative 2: 98.2% accurate, 19.0× 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.2%

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

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

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

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

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

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

    \[\leadsto \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \]
  6. Step-by-step derivation
    1. lower--.f3298.2

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

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

Alternative 3: 86.4% accurate, 11.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(-n0\_i, u, n0\_i\right)\\ \mathbf{if}\;n0\_i \leq -1.99999996490334 \cdot 10^{-13}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n0\_i \leq 2.0000000072549875 \cdot 10^{-15}:\\ \;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (let* ((t_0 (fma (- n0_i) u n0_i)))
   (if (<= n0_i -1.99999996490334e-13)
     t_0
     (if (<= n0_i 2.0000000072549875e-15) (fma n1_i u n0_i) t_0))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float t_0 = fmaf(-n0_i, u, n0_i);
	float tmp;
	if (n0_i <= -1.99999996490334e-13f) {
		tmp = t_0;
	} else if (n0_i <= 2.0000000072549875e-15f) {
		tmp = fmaf(n1_i, u, n0_i);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(normAngle, u, n0_i, n1_i)
	t_0 = fma(Float32(-n0_i), u, n0_i)
	tmp = Float32(0.0)
	if (n0_i <= Float32(-1.99999996490334e-13))
		tmp = t_0;
	elseif (n0_i <= Float32(2.0000000072549875e-15))
		tmp = fma(n1_i, u, n0_i);
	else
		tmp = t_0;
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-n0\_i, u, n0\_i\right)\\
\mathbf{if}\;n0\_i \leq -1.99999996490334 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n0_i < -1.99999996e-13 or 2.00000001e-15 < n0_i

    1. Initial program 97.2%

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \]
    6. Step-by-step derivation
      1. lower--.f3298.2

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(-1 \cdot n0\_i, u, n0\_i\right) \]
    12. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(n0\_i\right), u, n0\_i\right) \]
      2. lower-neg.f3259.7

        \[\leadsto \mathsf{fma}\left(-n0\_i, u, n0\_i\right) \]
    13. Applied rewrites59.7%

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

    if -1.99999996e-13 < n0_i < 2.00000001e-15

    1. Initial program 97.2%

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \]
    6. Step-by-step derivation
      1. lower--.f3298.2

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i\right) \]
    12. Step-by-step derivation
      1. Applied rewrites81.7%

        \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i\right) \]
    13. Recombined 2 regimes into one program.
    14. Add Preprocessing

    Alternative 4: 86.3% accurate, 11.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := n0\_i \cdot \left(1 - u\right)\\ \mathbf{if}\;n0\_i \leq -1.99999996490334 \cdot 10^{-13}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n0\_i \leq 2.0000000072549875 \cdot 10^{-15}:\\ \;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (normAngle u n0_i n1_i)
     :precision binary32
     (let* ((t_0 (* n0_i (- 1.0 u))))
       (if (<= n0_i -1.99999996490334e-13)
         t_0
         (if (<= n0_i 2.0000000072549875e-15) (fma n1_i u n0_i) t_0))))
    float code(float normAngle, float u, float n0_i, float n1_i) {
    	float t_0 = n0_i * (1.0f - u);
    	float tmp;
    	if (n0_i <= -1.99999996490334e-13f) {
    		tmp = t_0;
    	} else if (n0_i <= 2.0000000072549875e-15f) {
    		tmp = fmaf(n1_i, u, n0_i);
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    function code(normAngle, u, n0_i, n1_i)
    	t_0 = Float32(n0_i * Float32(Float32(1.0) - u))
    	tmp = Float32(0.0)
    	if (n0_i <= Float32(-1.99999996490334e-13))
    		tmp = t_0;
    	elseif (n0_i <= Float32(2.0000000072549875e-15))
    		tmp = fma(n1_i, u, n0_i);
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := n0\_i \cdot \left(1 - u\right)\\
    \mathbf{if}\;n0\_i \leq -1.99999996490334 \cdot 10^{-13}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;n0\_i \leq 2.0000000072549875 \cdot 10^{-15}:\\
    \;\;\;\;\mathsf{fma}\left(n1\_i, u, n0\_i\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if n0_i < -1.99999996e-13 or 2.00000001e-15 < n0_i

      1. Initial program 97.2%

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

        \[\leadsto \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)} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \left(1 - u\right) \cdot n0\_i + \left(\color{blue}{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-fma.f32N/A

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

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

          \[\leadsto \mathsf{fma}\left(1 - u, n0\_i, {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. Applied rewrites98.8%

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

        \[\leadsto n0\_i \cdot \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)} \]
      6. Step-by-step derivation
        1. lower-*.f32N/A

          \[\leadsto n0\_i \cdot \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) \]
        2. lower--.f32N/A

          \[\leadsto n0\_i \cdot \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) \]
      7. Applied rewrites59.6%

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

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

          \[\leadsto n0\_i \cdot \left(1 - u\right) \]

        if -1.99999996e-13 < n0_i < 2.00000001e-15

        1. Initial program 97.2%

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \]
        6. Step-by-step derivation
          1. lower--.f3298.2

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i\right) \]
        12. Step-by-step derivation
          1. Applied rewrites81.7%

            \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i\right) \]
        13. Recombined 2 regimes into one program.
        14. Add Preprocessing

        Alternative 5: 81.7% accurate, 26.9× speedup?

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \]
        6. Step-by-step derivation
          1. lower--.f3298.2

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(n1\_i, u, n0\_i\right) \]
        12. Step-by-step derivation
          1. Applied rewrites81.7%

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

          Alternative 6: 60.5% accurate, 14.0× speedup?

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

            1. Initial program 97.2%

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

              \[\leadsto \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)} \]
            3. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \left(1 - u\right) \cdot n0\_i + \left(\color{blue}{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-fma.f32N/A

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

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

                \[\leadsto \mathsf{fma}\left(1 - u, n0\_i, {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. Applied rewrites98.8%

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

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

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

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

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

                \[\leadsto n1\_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(\frac{-1}{6} \cdot {u}^{3} - \color{blue}{\frac{-1}{6}} \cdot u\right)\right) \]
              5. lift-*.f32N/A

                \[\leadsto n1\_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(\frac{-1}{6} \cdot {u}^{3} - \color{blue}{\frac{-1}{6}} \cdot u\right)\right) \]
              6. distribute-lft-out--N/A

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

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

                \[\leadsto n1\_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(\frac{-1}{6} \cdot \left({u}^{3} - u\right)\right)\right) \]
              9. pow3N/A

                \[\leadsto n1\_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(\frac{-1}{6} \cdot \left(\left(u \cdot u\right) \cdot u - u\right)\right)\right) \]
              10. lift-*.f32N/A

                \[\leadsto n1\_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(\frac{-1}{6} \cdot \left(\left(u \cdot u\right) \cdot u - u\right)\right)\right) \]
              11. lift-*.f3238.1

                \[\leadsto n1\_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(u \cdot u\right) \cdot u - u\right)\right)\right) \]
            7. Applied rewrites38.1%

              \[\leadsto n1\_i \cdot \color{blue}{\left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(u \cdot u\right) \cdot u - u\right)\right)\right)} \]
            8. Taylor expanded in normAngle around 0

              \[\leadsto n1\_i \cdot u \]
            9. Step-by-step derivation
              1. Applied rewrites37.5%

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

              if -5.6999998e-14 < n1_i < 5.00000002e-16

              1. Initial program 97.2%

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

                \[\leadsto \color{blue}{n0\_i} \]
              3. Step-by-step derivation
                1. Applied rewrites47.6%

                  \[\leadsto \color{blue}{n0\_i} \]
              4. Recombined 2 regimes into one program.
              5. Add Preprocessing

              Alternative 7: 47.6% accurate, 161.4× 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 97.2%

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

                \[\leadsto \color{blue}{n0\_i} \]
              3. Step-by-step derivation
                1. Applied rewrites47.6%

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

                Reproduce

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