Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.2% → 98.7%
Time: 11.5s
Alternatives: 7
Speedup: 60.1×

Specification

?
\[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\pi}{2}\right) \land \left(-1 \leq n0_i \land n0_i \leq 1\right)\right) \land \left(-1 \leq n1_i \land n1_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\sin normAngle}\\ \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot t_0\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot t_0\right) \cdot n1_i \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (let* ((t_0 (/ 1.0 (sin normAngle))))
   (+
    (* (* (sin (* (- 1.0 u) normAngle)) t_0) n0_i)
    (* (* (sin (* u normAngle)) t_0) n1_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float t_0 = 1.0f / sinf(normAngle);
	return ((sinf(((1.0f - u) * normAngle)) * t_0) * n0_i) + ((sinf((u * normAngle)) * t_0) * n1_i);
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: t_0
    t_0 = 1.0e0 / sin(normangle)
    code = ((sin(((1.0e0 - u) * normangle)) * t_0) * n0_i) + ((sin((u * normangle)) * t_0) * n1_i)
end function
function code(normAngle, u, n0_i, n1_i)
	t_0 = Float32(Float32(1.0) / sin(normAngle))
	return Float32(Float32(Float32(sin(Float32(Float32(Float32(1.0) - u) * normAngle)) * t_0) * n0_i) + Float32(Float32(sin(Float32(u * normAngle)) * t_0) * n1_i))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	t_0 = single(1.0) / sin(normAngle);
	tmp = ((sin(((single(1.0) - u) * normAngle)) * t_0) * n0_i) + ((sin((u * normAngle)) * t_0) * n1_i);
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\sin normAngle}\\
\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot t_0\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot t_0\right) \cdot n1_i
\end{array}
\end{array}

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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);
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: t_0
    t_0 = 1.0e0 / sin(normangle)
    code = ((sin(((1.0e0 - u) * normangle)) * t_0) * n0_i) + ((sin((u * normangle)) * t_0) * n1_i)
end function
function code(normAngle, u, n0_i, n1_i)
	t_0 = Float32(Float32(1.0) / sin(normAngle))
	return Float32(Float32(Float32(sin(Float32(Float32(Float32(1.0) - u) * normAngle)) * t_0) * n0_i) + Float32(Float32(sin(Float32(u * normAngle)) * t_0) * n1_i))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	t_0 = single(1.0) / sin(normAngle);
	tmp = ((sin(((single(1.0) - u) * normAngle)) * t_0) * n0_i) + ((sin((u * normAngle)) * t_0) * n1_i);
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\sin normAngle}\\
\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot t_0\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot t_0\right) \cdot n1_i
\end{array}
\end{array}

Alternative 1: 98.7% accurate, 28.1× speedup?

\[\begin{array}{l} \\ n0_i + \left(0.16666666666666666 \cdot \left(n1_i \cdot \left(normAngle \cdot normAngle\right)\right) + \left(n1_i - n0_i\right)\right) \cdot u \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+
  n0_i
  (*
   (+ (* 0.16666666666666666 (* n1_i (* normAngle normAngle))) (- n1_i n0_i))
   u)))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return n0_i + (((0.16666666666666666f * (n1_i * (normAngle * normAngle))) + (n1_i - n0_i)) * u);
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    code = n0_i + (((0.16666666666666666e0 * (n1_i * (normangle * normangle))) + (n1_i - n0_i)) * u)
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(n0_i + Float32(Float32(Float32(Float32(0.16666666666666666) * Float32(n1_i * Float32(normAngle * normAngle))) + Float32(n1_i - n0_i)) * u))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = n0_i + (((single(0.16666666666666666) * (n1_i * (normAngle * normAngle))) + (n1_i - n0_i)) * u);
end
\begin{array}{l}

\\
n0_i + \left(0.16666666666666666 \cdot \left(n1_i \cdot \left(normAngle \cdot normAngle\right)\right) + \left(n1_i - n0_i\right)\right) \cdot u
\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 normAngle around 0 97.6%

    \[\leadsto \color{blue}{\left(1 - u\right) \cdot n0_i} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
  3. Taylor expanded in u around 0 91.9%

    \[\leadsto \color{blue}{\left(\frac{n1_i \cdot normAngle}{\sin normAngle} + -1 \cdot n0_i\right) \cdot u + n0_i} \]
  4. Taylor expanded in normAngle around 0 99.4%

    \[\leadsto \color{blue}{\left(n1_i + \left(-1 \cdot n0_i + 0.16666666666666666 \cdot \left(n1_i \cdot {normAngle}^{2}\right)\right)\right)} \cdot u + n0_i \]
  5. Step-by-step derivation
    1. mul-1-neg99.4%

      \[\leadsto \left(n1_i + \left(\color{blue}{\left(-n0_i\right)} + 0.16666666666666666 \cdot \left(n1_i \cdot {normAngle}^{2}\right)\right)\right) \cdot u + n0_i \]
    2. associate-+r+99.4%

      \[\leadsto \color{blue}{\left(\left(n1_i + \left(-n0_i\right)\right) + 0.16666666666666666 \cdot \left(n1_i \cdot {normAngle}^{2}\right)\right)} \cdot u + n0_i \]
    3. sub-neg99.4%

      \[\leadsto \left(\color{blue}{\left(n1_i - n0_i\right)} + 0.16666666666666666 \cdot \left(n1_i \cdot {normAngle}^{2}\right)\right) \cdot u + n0_i \]
    4. unpow299.4%

      \[\leadsto \left(\left(n1_i - n0_i\right) + 0.16666666666666666 \cdot \left(n1_i \cdot \color{blue}{\left(normAngle \cdot normAngle\right)}\right)\right) \cdot u + n0_i \]
  6. Simplified99.4%

    \[\leadsto \color{blue}{\left(\left(n1_i - n0_i\right) + 0.16666666666666666 \cdot \left(n1_i \cdot \left(normAngle \cdot normAngle\right)\right)\right)} \cdot u + n0_i \]
  7. Final simplification99.4%

    \[\leadsto n0_i + \left(0.16666666666666666 \cdot \left(n1_i \cdot \left(normAngle \cdot normAngle\right)\right) + \left(n1_i - n0_i\right)\right) \cdot u \]

Alternative 2: 86.3% accurate, 45.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999943633011 \cdot 10^{-27} \lor \neg \left(n1_i \leq 1.0800000566035406 \cdot 10^{-22}\right):\\ \;\;\;\;n0_i + n1_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0_i \cdot \left(1 - u\right)\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (or (<= n1_i -4.999999943633011e-27)
         (not (<= n1_i 1.0800000566035406e-22)))
   (+ n0_i (* n1_i u))
   (* n0_i (- 1.0 u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if ((n1_i <= -4.999999943633011e-27f) || !(n1_i <= 1.0800000566035406e-22f)) {
		tmp = n0_i + (n1_i * u);
	} else {
		tmp = n0_i * (1.0f - u);
	}
	return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: tmp
    if ((n1_i <= (-4.999999943633011e-27)) .or. (.not. (n1_i <= 1.0800000566035406e-22))) then
        tmp = n0_i + (n1_i * u)
    else
        tmp = n0_i * (1.0e0 - u)
    end if
    code = tmp
end function
function code(normAngle, u, n0_i, n1_i)
	tmp = Float32(0.0)
	if ((n1_i <= Float32(-4.999999943633011e-27)) || !(n1_i <= Float32(1.0800000566035406e-22)))
		tmp = Float32(n0_i + Float32(n1_i * u));
	else
		tmp = Float32(n0_i * Float32(Float32(1.0) - u));
	end
	return tmp
end
function tmp_2 = code(normAngle, u, n0_i, n1_i)
	tmp = single(0.0);
	if ((n1_i <= single(-4.999999943633011e-27)) || ~((n1_i <= single(1.0800000566035406e-22))))
		tmp = n0_i + (n1_i * u);
	else
		tmp = n0_i * (single(1.0) - u);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n1_i \leq -4.999999943633011 \cdot 10^{-27} \lor \neg \left(n1_i \leq 1.0800000566035406 \cdot 10^{-22}\right):\\
\;\;\;\;n0_i + n1_i \cdot u\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n1_i < -4.99999994e-27 or 1.08000006e-22 < n1_i

    1. Initial program 96.5%

      \[\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. Step-by-step derivation
      1. fma-def96.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/96.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity96.7%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/97.0%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity97.0%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified97.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in normAngle around 0 98.2%

      \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
    5. Taylor expanded in u around 0 88.0%

      \[\leadsto n1_i \cdot u + \color{blue}{n0_i} \]

    if -4.99999994e-27 < n1_i < 1.08000006e-22

    1. Initial program 98.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. Step-by-step derivation
      1. fma-def98.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/98.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity98.7%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/98.8%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity98.8%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified98.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in normAngle around 0 99.0%

      \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
    5. Step-by-step derivation
      1. *-commutative99.0%

        \[\leadsto \color{blue}{u \cdot n1_i} + \left(1 - u\right) \cdot n0_i \]
      2. fma-def99.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    6. Simplified99.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    7. Taylor expanded in n1_i around 0 87.9%

      \[\leadsto \color{blue}{\left(1 - u\right) \cdot n0_i} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999943633011 \cdot 10^{-27} \lor \neg \left(n1_i \leq 1.0800000566035406 \cdot 10^{-22}\right):\\ \;\;\;\;n0_i + n1_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0_i \cdot \left(1 - u\right)\\ \end{array} \]

Alternative 3: 86.4% accurate, 45.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999943633011 \cdot 10^{-27} \lor \neg \left(n1_i \leq 1.0800000566035406 \cdot 10^{-22}\right):\\ \;\;\;\;n0_i + n1_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0_i - n0_i \cdot u\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (or (<= n1_i -4.999999943633011e-27)
         (not (<= n1_i 1.0800000566035406e-22)))
   (+ n0_i (* n1_i u))
   (- n0_i (* n0_i u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if ((n1_i <= -4.999999943633011e-27f) || !(n1_i <= 1.0800000566035406e-22f)) {
		tmp = n0_i + (n1_i * u);
	} else {
		tmp = n0_i - (n0_i * u);
	}
	return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: tmp
    if ((n1_i <= (-4.999999943633011e-27)) .or. (.not. (n1_i <= 1.0800000566035406e-22))) then
        tmp = n0_i + (n1_i * u)
    else
        tmp = n0_i - (n0_i * u)
    end if
    code = tmp
end function
function code(normAngle, u, n0_i, n1_i)
	tmp = Float32(0.0)
	if ((n1_i <= Float32(-4.999999943633011e-27)) || !(n1_i <= Float32(1.0800000566035406e-22)))
		tmp = Float32(n0_i + Float32(n1_i * u));
	else
		tmp = Float32(n0_i - Float32(n0_i * u));
	end
	return tmp
end
function tmp_2 = code(normAngle, u, n0_i, n1_i)
	tmp = single(0.0);
	if ((n1_i <= single(-4.999999943633011e-27)) || ~((n1_i <= single(1.0800000566035406e-22))))
		tmp = n0_i + (n1_i * u);
	else
		tmp = n0_i - (n0_i * u);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n1_i \leq -4.999999943633011 \cdot 10^{-27} \lor \neg \left(n1_i \leq 1.0800000566035406 \cdot 10^{-22}\right):\\
\;\;\;\;n0_i + n1_i \cdot u\\

\mathbf{else}:\\
\;\;\;\;n0_i - n0_i \cdot u\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n1_i < -4.99999994e-27 or 1.08000006e-22 < n1_i

    1. Initial program 96.5%

      \[\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. Step-by-step derivation
      1. fma-def96.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/96.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity96.7%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/97.0%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity97.0%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified97.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in normAngle around 0 98.2%

      \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
    5. Taylor expanded in u around 0 88.0%

      \[\leadsto n1_i \cdot u + \color{blue}{n0_i} \]

    if -4.99999994e-27 < n1_i < 1.08000006e-22

    1. Initial program 98.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. Step-by-step derivation
      1. fma-def98.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/98.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity98.7%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/98.8%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity98.8%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified98.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in normAngle around 0 99.0%

      \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
    5. Step-by-step derivation
      1. *-commutative99.0%

        \[\leadsto \color{blue}{u \cdot n1_i} + \left(1 - u\right) \cdot n0_i \]
      2. fma-def99.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    6. Simplified99.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    7. Taylor expanded in u around 0 99.2%

      \[\leadsto \color{blue}{\left(n1_i + -1 \cdot n0_i\right) \cdot u + n0_i} \]
    8. Step-by-step derivation
      1. *-commutative99.2%

        \[\leadsto \color{blue}{u \cdot \left(n1_i + -1 \cdot n0_i\right)} + n0_i \]
      2. fma-def99.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i + -1 \cdot n0_i, n0_i\right)} \]
      3. mul-1-neg99.3%

        \[\leadsto \mathsf{fma}\left(u, n1_i + \color{blue}{\left(-n0_i\right)}, n0_i\right) \]
      4. unsub-neg99.3%

        \[\leadsto \mathsf{fma}\left(u, \color{blue}{n1_i - n0_i}, n0_i\right) \]
    9. Simplified99.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i - n0_i, n0_i\right)} \]
    10. Taylor expanded in n1_i around 0 88.0%

      \[\leadsto \color{blue}{-1 \cdot \left(n0_i \cdot u\right) + n0_i} \]
    11. Step-by-step derivation
      1. +-commutative88.0%

        \[\leadsto \color{blue}{n0_i + -1 \cdot \left(n0_i \cdot u\right)} \]
      2. mul-1-neg88.0%

        \[\leadsto n0_i + \color{blue}{\left(-n0_i \cdot u\right)} \]
      3. *-commutative88.0%

        \[\leadsto n0_i + \left(-\color{blue}{u \cdot n0_i}\right) \]
      4. unsub-neg88.0%

        \[\leadsto \color{blue}{n0_i - u \cdot n0_i} \]
      5. *-commutative88.0%

        \[\leadsto n0_i - \color{blue}{n0_i \cdot u} \]
    12. Simplified88.0%

      \[\leadsto \color{blue}{n0_i - n0_i \cdot u} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999943633011 \cdot 10^{-27} \lor \neg \left(n1_i \leq 1.0800000566035406 \cdot 10^{-22}\right):\\ \;\;\;\;n0_i + n1_i \cdot u\\ \mathbf{else}:\\ \;\;\;\;n0_i - n0_i \cdot u\\ \end{array} \]

Alternative 4: 70.8% accurate, 45.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1_i \leq -1.99999996490334 \cdot 10^{-14}:\\ \;\;\;\;n1_i \cdot u\\ \mathbf{elif}\;n1_i \leq 1.0000000036274937 \cdot 10^{-15}:\\ \;\;\;\;n0_i \cdot \left(1 - u\right)\\ \mathbf{else}:\\ \;\;\;\;n1_i \cdot u\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (<= n1_i -1.99999996490334e-14)
   (* n1_i u)
   (if (<= n1_i 1.0000000036274937e-15) (* n0_i (- 1.0 u)) (* n1_i u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if (n1_i <= -1.99999996490334e-14f) {
		tmp = n1_i * u;
	} else if (n1_i <= 1.0000000036274937e-15f) {
		tmp = n0_i * (1.0f - u);
	} else {
		tmp = n1_i * u;
	}
	return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: tmp
    if (n1_i <= (-1.99999996490334e-14)) then
        tmp = n1_i * u
    else if (n1_i <= 1.0000000036274937e-15) then
        tmp = n0_i * (1.0e0 - u)
    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(-1.99999996490334e-14))
		tmp = Float32(n1_i * u);
	elseif (n1_i <= Float32(1.0000000036274937e-15))
		tmp = Float32(n0_i * Float32(Float32(1.0) - u));
	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(-1.99999996490334e-14))
		tmp = n1_i * u;
	elseif (n1_i <= single(1.0000000036274937e-15))
		tmp = n0_i * (single(1.0) - u);
	else
		tmp = n1_i * u;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n1_i \leq -1.99999996490334 \cdot 10^{-14}:\\
\;\;\;\;n1_i \cdot u\\

\mathbf{elif}\;n1_i \leq 1.0000000036274937 \cdot 10^{-15}:\\
\;\;\;\;n0_i \cdot \left(1 - u\right)\\

\mathbf{else}:\\
\;\;\;\;n1_i \cdot u\\


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

    1. Initial program 95.8%

      \[\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. Step-by-step derivation
      1. fma-def95.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/95.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity95.8%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/96.1%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity96.1%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified96.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in normAngle around 0 98.0%

      \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
    5. Step-by-step derivation
      1. *-commutative98.0%

        \[\leadsto \color{blue}{u \cdot n1_i} + \left(1 - u\right) \cdot n0_i \]
      2. fma-def98.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    6. Simplified98.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    7. Taylor expanded in n1_i around inf 67.0%

      \[\leadsto \color{blue}{n1_i \cdot u} \]
    8. Step-by-step derivation
      1. *-commutative67.0%

        \[\leadsto \color{blue}{u \cdot n1_i} \]
    9. Simplified67.0%

      \[\leadsto \color{blue}{u \cdot n1_i} \]

    if -1.99999996e-14 < n1_i < 1e-15

    1. Initial program 98.1%

      \[\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. Step-by-step derivation
      1. fma-def98.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/98.6%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity98.6%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/98.7%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity98.7%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified98.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in normAngle around 0 98.9%

      \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
    5. Step-by-step derivation
      1. *-commutative98.9%

        \[\leadsto \color{blue}{u \cdot n1_i} + \left(1 - u\right) \cdot n0_i \]
      2. fma-def98.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    6. Simplified98.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    7. Taylor expanded in n1_i around 0 79.8%

      \[\leadsto \color{blue}{\left(1 - u\right) \cdot n0_i} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification74.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n1_i \leq -1.99999996490334 \cdot 10^{-14}:\\ \;\;\;\;n1_i \cdot u\\ \mathbf{elif}\;n1_i \leq 1.0000000036274937 \cdot 10^{-15}:\\ \;\;\;\;n0_i \cdot \left(1 - u\right)\\ \mathbf{else}:\\ \;\;\;\;n1_i \cdot u\\ \end{array} \]

Alternative 5: 60.5% accurate, 58.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1_i \leq -1.99999996490334 \cdot 10^{-14}:\\ \;\;\;\;n1_i \cdot u\\ \mathbf{elif}\;n1_i \leq 1.0000000036274937 \cdot 10^{-15}:\\ \;\;\;\;n0_i\\ \mathbf{else}:\\ \;\;\;\;n1_i \cdot u\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (<= n1_i -1.99999996490334e-14)
   (* n1_i u)
   (if (<= n1_i 1.0000000036274937e-15) n0_i (* n1_i u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if (n1_i <= -1.99999996490334e-14f) {
		tmp = n1_i * u;
	} else if (n1_i <= 1.0000000036274937e-15f) {
		tmp = n0_i;
	} else {
		tmp = n1_i * u;
	}
	return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: tmp
    if (n1_i <= (-1.99999996490334e-14)) then
        tmp = n1_i * u
    else if (n1_i <= 1.0000000036274937e-15) 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(-1.99999996490334e-14))
		tmp = Float32(n1_i * u);
	elseif (n1_i <= Float32(1.0000000036274937e-15))
		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(-1.99999996490334e-14))
		tmp = n1_i * u;
	elseif (n1_i <= single(1.0000000036274937e-15))
		tmp = n0_i;
	else
		tmp = n1_i * u;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n1_i \leq -1.99999996490334 \cdot 10^{-14}:\\
\;\;\;\;n1_i \cdot u\\

\mathbf{elif}\;n1_i \leq 1.0000000036274937 \cdot 10^{-15}:\\
\;\;\;\;n0_i\\

\mathbf{else}:\\
\;\;\;\;n1_i \cdot u\\


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

    1. Initial program 95.8%

      \[\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. Step-by-step derivation
      1. fma-def95.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/95.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity95.8%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/96.1%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity96.1%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified96.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in normAngle around 0 98.0%

      \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
    5. Step-by-step derivation
      1. *-commutative98.0%

        \[\leadsto \color{blue}{u \cdot n1_i} + \left(1 - u\right) \cdot n0_i \]
      2. fma-def98.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    6. Simplified98.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
    7. Taylor expanded in n1_i around inf 67.0%

      \[\leadsto \color{blue}{n1_i \cdot u} \]
    8. Step-by-step derivation
      1. *-commutative67.0%

        \[\leadsto \color{blue}{u \cdot n1_i} \]
    9. Simplified67.0%

      \[\leadsto \color{blue}{u \cdot n1_i} \]

    if -1.99999996e-14 < n1_i < 1e-15

    1. Initial program 98.1%

      \[\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. Step-by-step derivation
      1. fma-def98.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
      2. associate-*r/98.6%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      3. *-rgt-identity98.6%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
      4. associate-*r/98.7%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
      5. *-rgt-identity98.7%

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
    3. Simplified98.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
    4. Taylor expanded in u around 0 62.2%

      \[\leadsto \color{blue}{n0_i} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n1_i \leq -1.99999996490334 \cdot 10^{-14}:\\ \;\;\;\;n1_i \cdot u\\ \mathbf{elif}\;n1_i \leq 1.0000000036274937 \cdot 10^{-15}:\\ \;\;\;\;n0_i\\ \mathbf{else}:\\ \;\;\;\;n1_i \cdot u\\ \end{array} \]

Alternative 6: 98.0% accurate, 60.1× speedup?

\[\begin{array}{l} \\ n0_i + u \cdot \left(n1_i - n0_i\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+ n0_i (* u (- n1_i n0_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return n0_i + (u * (n1_i - n0_i));
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    code = n0_i + (u * (n1_i - n0_i))
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(n0_i + Float32(u * Float32(n1_i - n0_i)))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = n0_i + (u * (n1_i - n0_i));
end
\begin{array}{l}

\\
n0_i + u \cdot \left(n1_i - 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. Step-by-step derivation
    1. fma-def97.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
    2. associate-*r/97.5%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
    3. *-rgt-identity97.5%

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
    4. associate-*r/97.7%

      \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
    5. *-rgt-identity97.7%

      \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
  3. Simplified97.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
  4. Taylor expanded in normAngle around 0 98.5%

    \[\leadsto \color{blue}{n1_i \cdot u + \left(1 - u\right) \cdot n0_i} \]
  5. Step-by-step derivation
    1. *-commutative98.5%

      \[\leadsto \color{blue}{u \cdot n1_i} + \left(1 - u\right) \cdot n0_i \]
    2. fma-def98.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
  6. Simplified98.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i, \left(1 - u\right) \cdot n0_i\right)} \]
  7. Taylor expanded in u around -inf 98.7%

    \[\leadsto \color{blue}{-1 \cdot \left(u \cdot \left(-1 \cdot n1_i + n0_i\right)\right) + n0_i} \]
  8. Step-by-step derivation
    1. +-commutative98.7%

      \[\leadsto \color{blue}{n0_i + -1 \cdot \left(u \cdot \left(-1 \cdot n1_i + n0_i\right)\right)} \]
    2. mul-1-neg98.7%

      \[\leadsto n0_i + \color{blue}{\left(-u \cdot \left(-1 \cdot n1_i + n0_i\right)\right)} \]
    3. unsub-neg98.7%

      \[\leadsto \color{blue}{n0_i - u \cdot \left(-1 \cdot n1_i + n0_i\right)} \]
    4. neg-mul-198.7%

      \[\leadsto n0_i - u \cdot \left(\color{blue}{\left(-n1_i\right)} + n0_i\right) \]
    5. +-commutative98.7%

      \[\leadsto n0_i - u \cdot \color{blue}{\left(n0_i + \left(-n1_i\right)\right)} \]
    6. unsub-neg98.7%

      \[\leadsto n0_i - u \cdot \color{blue}{\left(n0_i - n1_i\right)} \]
  9. Simplified98.7%

    \[\leadsto \color{blue}{n0_i - u \cdot \left(n0_i - n1_i\right)} \]
  10. Final simplification98.7%

    \[\leadsto n0_i + u \cdot \left(n1_i - n0_i\right) \]

Alternative 7: 47.1% accurate, 421.0× speedup?

\[\begin{array}{l} \\ n0_i \end{array} \]
(FPCore (normAngle u n0_i n1_i) :precision binary32 n0_i)
float code(float normAngle, float u, float n0_i, float n1_i) {
	return n0_i;
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    code = n0_i
end function
function code(normAngle, u, n0_i, n1_i)
	return n0_i
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = n0_i;
end
\begin{array}{l}

\\
n0_i
\end{array}
Derivation
  1. Initial program 97.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. Step-by-step derivation
    1. fma-def97.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right)} \]
    2. associate-*r/97.5%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot 1}{\sin normAngle}}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
    3. *-rgt-identity97.5%

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin \left(\left(1 - u\right) \cdot normAngle\right)}}{\sin normAngle}, n0_i, \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i\right) \]
    4. associate-*r/97.7%

      \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \color{blue}{\frac{\sin \left(u \cdot normAngle\right) \cdot 1}{\sin normAngle}} \cdot n1_i\right) \]
    5. *-rgt-identity97.7%

      \[\leadsto \mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\color{blue}{\sin \left(u \cdot normAngle\right)}}{\sin normAngle} \cdot n1_i\right) \]
  3. Simplified97.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin \left(\left(1 - u\right) \cdot normAngle\right)}{\sin normAngle}, n0_i, \frac{\sin \left(u \cdot normAngle\right)}{\sin normAngle} \cdot n1_i\right)} \]
  4. Taylor expanded in u around 0 47.6%

    \[\leadsto \color{blue}{n0_i} \]
  5. Final simplification47.6%

    \[\leadsto n0_i \]

Reproduce

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