Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.1% → 98.7%
Time: 11.5s
Alternatives: 10
Speedup: 45.9×

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 10 alternatives:

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

Initial Program: 97.1% 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: 98.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(\frac{normAngle}{\sin normAngle} \cdot u\right) \cdot n1\_i \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+
  (* (* (sin (* (- 1.0 u) normAngle)) (/ 1.0 (sin normAngle))) n0_i)
  (* (* (/ normAngle (sin normAngle)) u) n1_i)))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return ((sinf(((1.0f - u) * normAngle)) * (1.0f / sinf(normAngle))) * n0_i) + (((normAngle / sinf(normAngle)) * 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 = ((sin(((1.0e0 - u) * normangle)) * (1.0e0 / sin(normangle))) * n0_i) + (((normangle / sin(normangle)) * u) * n1_i)
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(Float32(Float32(sin(Float32(Float32(Float32(1.0) - u) * normAngle)) * Float32(Float32(1.0) / sin(normAngle))) * n0_i) + Float32(Float32(Float32(normAngle / sin(normAngle)) * u) * n1_i))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = ((sin(((single(1.0) - u) * normAngle)) * (single(1.0) / sin(normAngle))) * n0_i) + (((normAngle / sin(normAngle)) * u) * n1_i);
end
\begin{array}{l}

\\
\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \left(\frac{normAngle}{\sin normAngle} \cdot u\right) \cdot n1\_i
\end{array}
Derivation
  1. Initial program 97.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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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(\color{blue}{\frac{normAngle}{\sin normAngle}} \cdot u\right) \cdot n1\_i \]
    4. lower-sin.f3298.4

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

    \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\right)} \cdot n1\_i \]
  6. Add Preprocessing

Alternative 2: 98.9% accurate, 3.5× speedup?

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

\\
\mathsf{fma}\left(1 - u, n0\_i, n1\_i \cdot \left(\frac{normAngle}{\sin normAngle} \cdot u\right)\right)
\end{array}
Derivation
  1. Initial program 97.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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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(\color{blue}{\frac{normAngle}{\sin normAngle}} \cdot u\right) \cdot n1\_i \]
    4. lower-sin.f3298.4

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

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

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

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

    \[\leadsto \color{blue}{\left(1 - u\right)} \cdot n0\_i + \left(\frac{normAngle}{\sin normAngle} \cdot u\right) \cdot n1\_i \]
  9. Step-by-step derivation
    1. lift-+.f32N/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1 - u, n0\_i, \left(\frac{normAngle}{\sin normAngle} \cdot u\right) \cdot n1\_i\right)} \]
    4. lift-*.f32N/A

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

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

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

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

Alternative 3: 98.8% accurate, 6.3× speedup?

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

\\
\left(1 - u\right) \cdot n0\_i + \left(\frac{normAngle}{\mathsf{fma}\left(\mathsf{fma}\left(-0.0001984126984126984, normAngle \cdot normAngle, 0.008333333333333333\right) \cdot \left(normAngle \cdot normAngle\right) - 0.16666666666666666, normAngle \cdot normAngle, 1\right) \cdot normAngle} \cdot u\right) \cdot n1\_i
\end{array}
Derivation
  1. Initial program 97.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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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(\color{blue}{\frac{normAngle}{\sin normAngle}} \cdot u\right) \cdot n1\_i \]
    4. lower-sin.f3298.4

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

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

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

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

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

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

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

    Alternative 4: 98.8% accurate, 8.3× speedup?

    \[\begin{array}{l} \\ \left(1 - u\right) \cdot n0\_i + \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.00205026455026455, normAngle \cdot normAngle, 0.019444444444444445\right), normAngle \cdot normAngle, 0.16666666666666666\right), normAngle \cdot normAngle, 1\right) \cdot u\right) \cdot n1\_i \end{array} \]
    (FPCore (normAngle u n0_i n1_i)
     :precision binary32
     (+
      (* (- 1.0 u) n0_i)
      (*
       (*
        (fma
         (fma
          (fma 0.00205026455026455 (* normAngle normAngle) 0.019444444444444445)
          (* normAngle normAngle)
          0.16666666666666666)
         (* normAngle normAngle)
         1.0)
        u)
       n1_i)))
    float code(float normAngle, float u, float n0_i, float n1_i) {
    	return ((1.0f - u) * n0_i) + ((fmaf(fmaf(fmaf(0.00205026455026455f, (normAngle * normAngle), 0.019444444444444445f), (normAngle * normAngle), 0.16666666666666666f), (normAngle * normAngle), 1.0f) * u) * n1_i);
    }
    
    function code(normAngle, u, n0_i, n1_i)
    	return Float32(Float32(Float32(Float32(1.0) - u) * n0_i) + Float32(Float32(fma(fma(fma(Float32(0.00205026455026455), Float32(normAngle * normAngle), Float32(0.019444444444444445)), Float32(normAngle * normAngle), Float32(0.16666666666666666)), Float32(normAngle * normAngle), Float32(1.0)) * u) * n1_i))
    end
    
    \begin{array}{l}
    
    \\
    \left(1 - u\right) \cdot n0\_i + \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.00205026455026455, normAngle \cdot normAngle, 0.019444444444444445\right), normAngle \cdot normAngle, 0.16666666666666666\right), normAngle \cdot normAngle, 1\right) \cdot u\right) \cdot n1\_i
    \end{array}
    
    Derivation
    1. Initial program 97.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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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(\color{blue}{\frac{normAngle}{\sin normAngle}} \cdot u\right) \cdot n1\_i \]
      4. lower-sin.f3298.4

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

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

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

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

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

      \[\leadsto \left(1 - u\right) \cdot n0\_i + \left(\left(1 + {normAngle}^{2} \cdot \left(\frac{1}{6} + {normAngle}^{2} \cdot \left(\frac{7}{360} + \frac{31}{15120} \cdot {normAngle}^{2}\right)\right)\right) \cdot u\right) \cdot n1\_i \]
    10. Step-by-step derivation
      1. Applied rewrites97.8%

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

      Alternative 5: 98.7% accurate, 10.4× speedup?

      \[\begin{array}{l} \\ \left(1 - u\right) \cdot n0\_i + \left(\mathsf{fma}\left(\mathsf{fma}\left(0.019444444444444445, normAngle \cdot normAngle, 0.16666666666666666\right), normAngle \cdot normAngle, 1\right) \cdot u\right) \cdot n1\_i \end{array} \]
      (FPCore (normAngle u n0_i n1_i)
       :precision binary32
       (+
        (* (- 1.0 u) n0_i)
        (*
         (*
          (fma
           (fma 0.019444444444444445 (* normAngle normAngle) 0.16666666666666666)
           (* normAngle normAngle)
           1.0)
          u)
         n1_i)))
      float code(float normAngle, float u, float n0_i, float n1_i) {
      	return ((1.0f - u) * n0_i) + ((fmaf(fmaf(0.019444444444444445f, (normAngle * normAngle), 0.16666666666666666f), (normAngle * normAngle), 1.0f) * u) * n1_i);
      }
      
      function code(normAngle, u, n0_i, n1_i)
      	return Float32(Float32(Float32(Float32(1.0) - u) * n0_i) + Float32(Float32(fma(fma(Float32(0.019444444444444445), Float32(normAngle * normAngle), Float32(0.16666666666666666)), Float32(normAngle * normAngle), Float32(1.0)) * u) * n1_i))
      end
      
      \begin{array}{l}
      
      \\
      \left(1 - u\right) \cdot n0\_i + \left(\mathsf{fma}\left(\mathsf{fma}\left(0.019444444444444445, normAngle \cdot normAngle, 0.16666666666666666\right), normAngle \cdot normAngle, 1\right) \cdot u\right) \cdot n1\_i
      \end{array}
      
      Derivation
      1. Initial program 97.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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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(\color{blue}{\frac{normAngle}{\sin normAngle}} \cdot u\right) \cdot n1\_i \]
        4. lower-sin.f3298.4

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

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

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

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

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

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

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

        Alternative 6: 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 97.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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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 + \color{blue}{\left(\frac{normAngle}{\sin normAngle} \cdot u\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(\color{blue}{\frac{normAngle}{\sin normAngle}} \cdot u\right) \cdot n1\_i \]
          4. lower-sin.f3298.4

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

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

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

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

          \[\leadsto \color{blue}{\left(1 - u\right)} \cdot n0\_i + \left(\frac{normAngle}{\sin normAngle} \cdot u\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. Applied rewrites97.5%

            \[\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 \]
          2. Add Preprocessing

          Alternative 7: 98.2% accurate, 45.9× speedup?

          \[\begin{array}{l} \\ \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right) \end{array} \]
          (FPCore (normAngle u n0_i n1_i) :precision binary32 (fma (- n1_i n0_i) u n0_i))
          float code(float normAngle, float u, float n0_i, float n1_i) {
          	return fmaf((n1_i - n0_i), u, n0_i);
          }
          
          function code(normAngle, u, n0_i, n1_i)
          	return fma(Float32(n1_i - n0_i), u, n0_i)
          end
          
          \begin{array}{l}
          
          \\
          \mathsf{fma}\left(n1\_i - n0\_i, u, n0\_i\right)
          \end{array}
          
          Derivation
          1. Initial program 97.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 \color{blue}{\left(1 - u\right) \cdot n0\_i} + n1\_i \cdot u \]
            2. lower-fma.f32N/A

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

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

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

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

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

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

            Alternative 8: 42.6% accurate, 51.0× speedup?

            \[\begin{array}{l} \\ \left(n1\_i + n0\_i\right) \cdot u \end{array} \]
            (FPCore (normAngle u n0_i n1_i) :precision binary32 (* (+ n1_i n0_i) u))
            float code(float normAngle, float u, float n0_i, float n1_i) {
            	return (n1_i + n0_i) * u;
            }
            
            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 = (n1_i + n0_i) * u
            end function
            
            function code(normAngle, u, n0_i, n1_i)
            	return Float32(Float32(n1_i + n0_i) * u)
            end
            
            function tmp = code(normAngle, u, n0_i, n1_i)
            	tmp = (n1_i + n0_i) * u;
            end
            
            \begin{array}{l}
            
            \\
            \left(n1\_i + n0\_i\right) \cdot u
            \end{array}
            
            Derivation
            1. Initial program 97.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 \color{blue}{\left(1 - u\right) \cdot n0\_i} + n1\_i \cdot u \]
              2. lower-fma.f32N/A

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

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

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

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

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

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

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

                    \[\leadsto \left(n1\_i + n0\_i\right) \cdot \color{blue}{u} \]
                  2. Add Preprocessing

                  Alternative 9: 37.1% accurate, 51.0× speedup?

                  \[\begin{array}{l} \\ \left(n1\_i - n0\_i\right) \cdot u \end{array} \]
                  (FPCore (normAngle u n0_i n1_i) :precision binary32 (* (- n1_i n0_i) u))
                  float code(float normAngle, float u, float n0_i, float n1_i) {
                  	return (n1_i - n0_i) * u;
                  }
                  
                  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 = (n1_i - n0_i) * u
                  end function
                  
                  function code(normAngle, u, n0_i, n1_i)
                  	return Float32(Float32(n1_i - n0_i) * u)
                  end
                  
                  function tmp = code(normAngle, u, n0_i, n1_i)
                  	tmp = (n1_i - n0_i) * u;
                  end
                  
                  \begin{array}{l}
                  
                  \\
                  \left(n1\_i - n0\_i\right) \cdot u
                  \end{array}
                  
                  Derivation
                  1. Initial program 97.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 \color{blue}{\left(1 - u\right) \cdot n0\_i} + n1\_i \cdot u \]
                    2. lower-fma.f32N/A

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

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

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

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

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

                      \[\leadsto \left(n1\_i - n0\_i\right) \cdot \color{blue}{u} \]
                    2. Add Preprocessing

                    Alternative 10: 8.0% accurate, 57.4× speedup?

                    \[\begin{array}{l} \\ \left(-n0\_i\right) \cdot u \end{array} \]
                    (FPCore (normAngle u n0_i n1_i) :precision binary32 (* (- n0_i) u))
                    float code(float normAngle, float u, float n0_i, float n1_i) {
                    	return -n0_i * u;
                    }
                    
                    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
                    end function
                    
                    function code(normAngle, u, n0_i, n1_i)
                    	return Float32(Float32(-n0_i) * u)
                    end
                    
                    function tmp = code(normAngle, u, n0_i, n1_i)
                    	tmp = -n0_i * u;
                    end
                    
                    \begin{array}{l}
                    
                    \\
                    \left(-n0\_i\right) \cdot u
                    \end{array}
                    
                    Derivation
                    1. Initial program 97.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 \color{blue}{\left(1 - u\right) \cdot n0\_i} + n1\_i \cdot u \]
                      2. lower-fma.f32N/A

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

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

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

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

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

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

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

                          \[\leadsto \left(-n0\_i\right) \cdot u \]
                        2. Add Preprocessing

                        Reproduce

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