Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.2% → 98.3%
Time: 23.1s
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.3% accurate, 4.0× speedup?

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

\\
\mathsf{fma}\left(u, n1_i - n0_i, n0_i\right)
\end{array}
Derivation
  1. Initial program 97.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-def97.8%

      \[\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.3%

      \[\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.3%

      \[\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.4%

      \[\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.4%

      \[\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.4%

    \[\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.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(n0_i, 1 - u, n1_i \cdot u\right)} \]
    2. *-commutative98.7%

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

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

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

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

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

      \[\leadsto u \cdot n1_i + n0_i \cdot \color{blue}{\left(1 + \left(-u\right)\right)} \]
    4. distribute-lft-out98.8%

      \[\leadsto u \cdot n1_i + \color{blue}{\left(n0_i \cdot 1 + n0_i \cdot \left(-u\right)\right)} \]
    5. *-rgt-identity98.8%

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

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

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

      \[\leadsto \left(\color{blue}{n1_i \cdot u} + n0_i \cdot \left(-u\right)\right) + n0_i \]
    9. distribute-rgt-neg-out99.0%

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

      \[\leadsto \left(n1_i \cdot u + \color{blue}{-1 \cdot \left(n0_i \cdot u\right)}\right) + n0_i \]
    11. associate-*r*99.0%

      \[\leadsto \left(n1_i \cdot u + \color{blue}{\left(-1 \cdot n0_i\right) \cdot u}\right) + n0_i \]
    12. distribute-rgt-in99.0%

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i - n0_i, n0_i\right)} \]
  10. Final simplification99.1%

    \[\leadsto \mathsf{fma}\left(u, n1_i - n0_i, n0_i\right) \]

Alternative 2: 70.7% accurate, 45.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999980020986 \cdot 10^{-13} \lor \neg \left(n1_i \leq 2.000000026702864 \cdot 10^{-10}\right):\\ \;\;\;\;u \cdot n1_i\\ \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.999999980020986e-13)
         (not (<= n1_i 2.000000026702864e-10)))
   (* u n1_i)
   (* n0_i (- 1.0 u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if ((n1_i <= -4.999999980020986e-13f) || !(n1_i <= 2.000000026702864e-10f)) {
		tmp = u * n1_i;
	} 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.999999980020986e-13)) .or. (.not. (n1_i <= 2.000000026702864e-10))) then
        tmp = u * n1_i
    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.999999980020986e-13)) || !(n1_i <= Float32(2.000000026702864e-10)))
		tmp = Float32(u * n1_i);
	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.999999980020986e-13)) || ~((n1_i <= single(2.000000026702864e-10))))
		tmp = u * n1_i;
	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.999999980020986 \cdot 10^{-13} \lor \neg \left(n1_i \leq 2.000000026702864 \cdot 10^{-10}\right):\\
\;\;\;\;u \cdot n1_i\\

\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.99999998e-13 or 2.00000003e-10 < n1_i

    1. Initial program 95.6%

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

        \[\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 99.5%

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

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

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

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

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

    if -4.99999998e-13 < n1_i < 2.00000003e-10

    1. Initial program 98.3%

      \[\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.9%

        \[\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.9%

        \[\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/99.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-identity99.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. Simplified99.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.3%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(n0_i, 1 - u, n1_i \cdot u\right)} \]
      2. *-commutative98.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999980020986 \cdot 10^{-13} \lor \neg \left(n1_i \leq 2.000000026702864 \cdot 10^{-10}\right):\\ \;\;\;\;u \cdot n1_i\\ \mathbf{else}:\\ \;\;\;\;n0_i \cdot \left(1 - u\right)\\ \end{array} \]

Alternative 3: 59.8% accurate, 58.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999980020986 \cdot 10^{-13}:\\ \;\;\;\;u \cdot n1_i\\ \mathbf{elif}\;n1_i \leq 2.000000026702864 \cdot 10^{-10}:\\ \;\;\;\;n0_i\\ \mathbf{else}:\\ \;\;\;\;u \cdot n1_i\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (<= n1_i -4.999999980020986e-13)
   (* u n1_i)
   (if (<= n1_i 2.000000026702864e-10) n0_i (* u n1_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if (n1_i <= -4.999999980020986e-13f) {
		tmp = u * n1_i;
	} else if (n1_i <= 2.000000026702864e-10f) {
		tmp = n0_i;
	} else {
		tmp = u * n1_i;
	}
	return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: tmp
    if (n1_i <= (-4.999999980020986e-13)) then
        tmp = u * n1_i
    else if (n1_i <= 2.000000026702864e-10) then
        tmp = n0_i
    else
        tmp = u * n1_i
    end if
    code = tmp
end function
function code(normAngle, u, n0_i, n1_i)
	tmp = Float32(0.0)
	if (n1_i <= Float32(-4.999999980020986e-13))
		tmp = Float32(u * n1_i);
	elseif (n1_i <= Float32(2.000000026702864e-10))
		tmp = n0_i;
	else
		tmp = Float32(u * n1_i);
	end
	return tmp
end
function tmp_2 = code(normAngle, u, n0_i, n1_i)
	tmp = single(0.0);
	if (n1_i <= single(-4.999999980020986e-13))
		tmp = u * n1_i;
	elseif (n1_i <= single(2.000000026702864e-10))
		tmp = n0_i;
	else
		tmp = u * n1_i;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n1_i < -4.99999998e-13 or 2.00000003e-10 < n1_i

    1. Initial program 95.6%

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

        \[\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 99.5%

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

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

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

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

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

    if -4.99999998e-13 < n1_i < 2.00000003e-10

    1. Initial program 98.3%

      \[\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.9%

        \[\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.9%

        \[\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/99.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-identity99.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. Simplified99.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 u around 0 59.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n1_i \leq -4.999999980020986 \cdot 10^{-13}:\\ \;\;\;\;u \cdot n1_i\\ \mathbf{elif}\;n1_i \leq 2.000000026702864 \cdot 10^{-10}:\\ \;\;\;\;n0_i\\ \mathbf{else}:\\ \;\;\;\;u \cdot n1_i\\ \end{array} \]

Alternative 4: 83.3% accurate, 59.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n0_i \leq 4.9999998413276127 \cdot 10^{-20}:\\ \;\;\;\;n0_i + u \cdot n1_i\\ \mathbf{else}:\\ \;\;\;\;n0_i \cdot \left(1 - u\right)\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (<= n0_i 4.9999998413276127e-20) (+ n0_i (* u n1_i)) (* n0_i (- 1.0 u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if (n0_i <= 4.9999998413276127e-20f) {
		tmp = n0_i + (u * n1_i);
	} 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 (n0_i <= 4.9999998413276127e-20) then
        tmp = n0_i + (u * n1_i)
    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 (n0_i <= Float32(4.9999998413276127e-20))
		tmp = Float32(n0_i + Float32(u * n1_i));
	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 (n0_i <= single(4.9999998413276127e-20))
		tmp = n0_i + (u * n1_i);
	else
		tmp = n0_i * (single(1.0) - u);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n0_i \leq 4.9999998413276127 \cdot 10^{-20}:\\
\;\;\;\;n0_i + u \cdot n1_i\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n0_i < 4.99999984e-20

    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. Step-by-step derivation
      1. fma-def97.5%

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

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

        \[\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.2%

        \[\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.2%

        \[\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.2%

      \[\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}{n0_i \cdot \left(1 - u\right) + n1_i \cdot u} \]
    5. Step-by-step derivation
      1. fma-def98.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(n0_i, 1 - u, n1_i \cdot u\right)} \]
      2. *-commutative98.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto n0_i - \color{blue}{\left(-n1_i \cdot u\right)} \]
      2. distribute-lft-neg-out81.8%

        \[\leadsto n0_i - \color{blue}{\left(-n1_i\right) \cdot u} \]
      3. *-commutative81.8%

        \[\leadsto n0_i - \color{blue}{u \cdot \left(-n1_i\right)} \]
    12. Simplified81.8%

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

        \[\leadsto n0_i - \color{blue}{\left(-n1_i\right) \cdot u} \]
      2. cancel-sign-sub81.8%

        \[\leadsto \color{blue}{n0_i + n1_i \cdot u} \]
      3. +-commutative81.8%

        \[\leadsto \color{blue}{n1_i \cdot u + n0_i} \]
    14. Applied egg-rr81.8%

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

    if 4.99999984e-20 < n0_i

    1. Initial program 98.4%

      \[\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. Step-by-step derivation
      1. fma-def98.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/99.1%

        \[\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-identity99.1%

        \[\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/99.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-identity99.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. Simplified99.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.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n0_i \leq 4.9999998413276127 \cdot 10^{-20}:\\ \;\;\;\;n0_i + u \cdot n1_i\\ \mathbf{else}:\\ \;\;\;\;n0_i \cdot \left(1 - u\right)\\ \end{array} \]

Alternative 5: 83.4% accurate, 59.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n0_i \leq 4.9999998413276127 \cdot 10^{-20}:\\ \;\;\;\;n0_i + u \cdot n1_i\\ \mathbf{else}:\\ \;\;\;\;n0_i - u \cdot n0_i\\ \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (if (<= n0_i 4.9999998413276127e-20) (+ n0_i (* u n1_i)) (- n0_i (* u n0_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float tmp;
	if (n0_i <= 4.9999998413276127e-20f) {
		tmp = n0_i + (u * n1_i);
	} else {
		tmp = n0_i - (u * n0_i);
	}
	return tmp;
}
real(4) function code(normangle, u, n0_i, n1_i)
    real(4), intent (in) :: normangle
    real(4), intent (in) :: u
    real(4), intent (in) :: n0_i
    real(4), intent (in) :: n1_i
    real(4) :: tmp
    if (n0_i <= 4.9999998413276127e-20) then
        tmp = n0_i + (u * n1_i)
    else
        tmp = n0_i - (u * n0_i)
    end if
    code = tmp
end function
function code(normAngle, u, n0_i, n1_i)
	tmp = Float32(0.0)
	if (n0_i <= Float32(4.9999998413276127e-20))
		tmp = Float32(n0_i + Float32(u * n1_i));
	else
		tmp = Float32(n0_i - Float32(u * n0_i));
	end
	return tmp
end
function tmp_2 = code(normAngle, u, n0_i, n1_i)
	tmp = single(0.0);
	if (n0_i <= single(4.9999998413276127e-20))
		tmp = n0_i + (u * n1_i);
	else
		tmp = n0_i - (u * n0_i);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n0_i \leq 4.9999998413276127 \cdot 10^{-20}:\\
\;\;\;\;n0_i + u \cdot n1_i\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n0_i < 4.99999984e-20

    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. Step-by-step derivation
      1. fma-def97.5%

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

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

        \[\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.2%

        \[\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.2%

        \[\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.2%

      \[\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}{n0_i \cdot \left(1 - u\right) + n1_i \cdot u} \]
    5. Step-by-step derivation
      1. fma-def98.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(n0_i, 1 - u, n1_i \cdot u\right)} \]
      2. *-commutative98.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto n0_i - \color{blue}{\left(-n1_i \cdot u\right)} \]
      2. distribute-lft-neg-out81.8%

        \[\leadsto n0_i - \color{blue}{\left(-n1_i\right) \cdot u} \]
      3. *-commutative81.8%

        \[\leadsto n0_i - \color{blue}{u \cdot \left(-n1_i\right)} \]
    12. Simplified81.8%

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

        \[\leadsto n0_i - \color{blue}{\left(-n1_i\right) \cdot u} \]
      2. cancel-sign-sub81.8%

        \[\leadsto \color{blue}{n0_i + n1_i \cdot u} \]
      3. +-commutative81.8%

        \[\leadsto \color{blue}{n1_i \cdot u + n0_i} \]
    14. Applied egg-rr81.8%

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

    if 4.99999984e-20 < n0_i

    1. Initial program 98.4%

      \[\left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. Step-by-step derivation
      1. fma-def98.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/99.1%

        \[\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-identity99.1%

        \[\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/99.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-identity99.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. Simplified99.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.8%

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

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

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

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

      \[\leadsto \color{blue}{n0_i \cdot \left(1 - u\right)} \]
    8. Step-by-step derivation
      1. sub-neg95.5%

        \[\leadsto n0_i \cdot \color{blue}{\left(1 + \left(-u\right)\right)} \]
      2. distribute-lft-out95.8%

        \[\leadsto \color{blue}{n0_i \cdot 1 + n0_i \cdot \left(-u\right)} \]
      3. *-rgt-identity95.8%

        \[\leadsto \color{blue}{n0_i} + n0_i \cdot \left(-u\right) \]
      4. distribute-rgt-neg-out95.8%

        \[\leadsto n0_i + \color{blue}{\left(-n0_i \cdot u\right)} \]
      5. unsub-neg95.8%

        \[\leadsto \color{blue}{n0_i - n0_i \cdot u} \]
      6. *-commutative95.8%

        \[\leadsto n0_i - \color{blue}{u \cdot n0_i} \]
    9. Simplified95.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n0_i \leq 4.9999998413276127 \cdot 10^{-20}:\\ \;\;\;\;n0_i + u \cdot n1_i\\ \mathbf{else}:\\ \;\;\;\;n0_i - u \cdot n0_i\\ \end{array} \]

Alternative 6: 98.2% 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.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-def97.8%

      \[\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.3%

      \[\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.3%

      \[\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.4%

      \[\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.4%

      \[\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.4%

    \[\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.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(n0_i, 1 - u, n1_i \cdot u\right)} \]
    2. *-commutative98.7%

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

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

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

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

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

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

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

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

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

Alternative 7: 47.0% 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.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-def97.8%

      \[\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.3%

      \[\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.3%

      \[\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.4%

      \[\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.4%

      \[\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.4%

    \[\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 51.4%

    \[\leadsto \color{blue}{n0_i} \]
  5. Final simplification51.4%

    \[\leadsto n0_i \]

Reproduce

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