Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.3% → 100.0%
Time: 19.4s
Alternatives: 10
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 10 alternatives:

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

Initial Program: 97.3% 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: 100.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \langle \left( \frac{n0_i \cdot \sin \left(normAngle - normAngle \cdot u\right) + n1_i \cdot \sin \left(normAngle \cdot u\right)}{\sin normAngle} \right)_{\text{binary64}} \rangle_{\text{binary32}} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (cast
  (!
   :precision
   binary64
   (/
    (+
     (* n0_i (sin (- normAngle (* normAngle u))))
     (* n1_i (sin (* normAngle u))))
    (sin normAngle)))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	double tmp = ((((double) n0_i) * sin((((double) normAngle) - (((double) normAngle) * ((double) u))))) + (((double) n1_i) * sin((((double) normAngle) * ((double) u))))) / sin(normAngle);
	return (float) 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(8) :: tmp
    tmp = ((real(n0_i, 8) * sin((real(normangle, 8) - (real(normangle, 8) * real(u, 8))))) + (real(n1_i, 8) * sin((real(normangle, 8) * real(u, 8))))) / sin(normangle)
    code = real(tmp, 4)
end function
function code(normAngle, u, n0_i, n1_i)
	tmp = Float64(Float64(Float64(Float64(n0_i) * sin(Float64(Float64(normAngle) - Float64(Float64(normAngle) * Float64(u))))) + Float64(Float64(n1_i) * sin(Float64(Float64(normAngle) * Float64(u))))) / sin(normAngle))
	return Float32(tmp)
end
function tmp_2 = code(normAngle, u, n0_i, n1_i)
	tmp = ((double(n0_i) * sin((double(normAngle) - (double(normAngle) * double(u))))) + (double(n1_i) * sin((double(normAngle) * double(u))))) / sin(normAngle);
	tmp_2 = single(tmp);
end
\begin{array}{l}

\\
\langle \left( \frac{n0_i \cdot \sin \left(normAngle - normAngle \cdot u\right) + n1_i \cdot \sin \left(normAngle \cdot u\right)}{\sin normAngle} \right)_{\text{binary64}} \rangle_{\text{binary32}}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\langle \frac{\mathsf{fma}\left(\sin \left(normAngle - u \cdot normAngle\right), n0_i, \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}{\sin normAngle} \rangle_{\text{binary64}} \]
  2. Taylor expanded in normAngle around 0 100.0%

    \[\leadsto \langle \frac{\color{blue}{n0_i \cdot \sin \left(normAngle - normAngle \cdot u\right) + n1_i \cdot \sin \left(normAngle \cdot u\right)}}{\sin normAngle} \rangle_{\text{binary64}} \]
  3. Final simplification100.0%

    \[\leadsto \langle \frac{n0_i \cdot \sin \left(normAngle - normAngle \cdot u\right) + n1_i \cdot \sin \left(normAngle \cdot u\right)}{\sin normAngle} \rangle_{\text{binary64}} \]

Alternative 2: 98.8% accurate, 1.8× speedup?

\[\begin{array}{l} \\ n0_i \cdot \left(1 - \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(1 - u\right) - {\left(1 - u\right)}^{3}\right)\right)\right)\right) + n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+
  (*
   n0_i
   (-
    1.0
    (+
     u
     (*
      (* normAngle normAngle)
      (* -0.16666666666666666 (- (- 1.0 u) (pow (- 1.0 u) 3.0)))))))
  (*
   n1_i
   (+
    u
    (* (* normAngle normAngle) (* -0.16666666666666666 (- (pow u 3.0) u)))))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return (n0_i * (1.0f - (u + ((normAngle * normAngle) * (-0.16666666666666666f * ((1.0f - u) - powf((1.0f - u), 3.0f))))))) + (n1_i * (u + ((normAngle * normAngle) * (-0.16666666666666666f * (powf(u, 3.0f) - 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 * (1.0e0 - (u + ((normangle * normangle) * ((-0.16666666666666666e0) * ((1.0e0 - u) - ((1.0e0 - u) ** 3.0e0))))))) + (n1_i * (u + ((normangle * normangle) * ((-0.16666666666666666e0) * ((u ** 3.0e0) - u)))))
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(Float32(n0_i * Float32(Float32(1.0) - Float32(u + Float32(Float32(normAngle * normAngle) * Float32(Float32(-0.16666666666666666) * Float32(Float32(Float32(1.0) - u) - (Float32(Float32(1.0) - u) ^ Float32(3.0)))))))) + Float32(n1_i * Float32(u + Float32(Float32(normAngle * normAngle) * Float32(Float32(-0.16666666666666666) * Float32((u ^ Float32(3.0)) - u))))))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = (n0_i * (single(1.0) - (u + ((normAngle * normAngle) * (single(-0.16666666666666666) * ((single(1.0) - u) - ((single(1.0) - u) ^ single(3.0)))))))) + (n1_i * (u + ((normAngle * normAngle) * (single(-0.16666666666666666) * ((u ^ single(3.0)) - u)))));
end
\begin{array}{l}

\\
n0_i \cdot \left(1 - \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(1 - u\right) - {\left(1 - u\right)}^{3}\right)\right)\right)\right) + n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right)
\end{array}
Derivation
  1. Initial program 96.9%

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

    \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \color{blue}{\left(u + {normAngle}^{2} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right)} \cdot n1_i \]
  3. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right) \cdot n1_i \]
    2. distribute-lft-out--97.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)}\right) \cdot n1_i \]
  4. Simplified97.8%

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

    \[\leadsto \color{blue}{\left(\left(1 + {normAngle}^{2} \cdot \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right)\right) - u\right)} \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  6. Step-by-step derivation
    1. associate--l+98.5%

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

      \[\leadsto \left(1 + \left(\color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
    3. distribute-lft-out--98.5%

      \[\leadsto \left(1 + \left(\left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right)\right)} - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  7. Simplified98.5%

    \[\leadsto \color{blue}{\left(1 + \left(\left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right)\right) - u\right)\right)} \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  8. Final simplification98.5%

    \[\leadsto n0_i \cdot \left(1 - \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(1 - u\right) - {\left(1 - u\right)}^{3}\right)\right)\right)\right) + n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \]

Alternative 3: 98.7% accurate, 3.2× speedup?

\[\begin{array}{l} \\ n0_i \cdot \left(1 - \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(1 - u\right) - {\left(1 - u\right)}^{3}\right)\right)\right)\right) + n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(u \cdot 0.16666666666666666\right)\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+
  (*
   n0_i
   (-
    1.0
    (+
     u
     (*
      (* normAngle normAngle)
      (* -0.16666666666666666 (- (- 1.0 u) (pow (- 1.0 u) 3.0)))))))
  (* n1_i (+ u (* (* normAngle normAngle) (* u 0.16666666666666666))))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return (n0_i * (1.0f - (u + ((normAngle * normAngle) * (-0.16666666666666666f * ((1.0f - u) - powf((1.0f - u), 3.0f))))))) + (n1_i * (u + ((normAngle * normAngle) * (u * 0.16666666666666666f))));
}
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 * (1.0e0 - (u + ((normangle * normangle) * ((-0.16666666666666666e0) * ((1.0e0 - u) - ((1.0e0 - u) ** 3.0e0))))))) + (n1_i * (u + ((normangle * normangle) * (u * 0.16666666666666666e0))))
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(Float32(n0_i * Float32(Float32(1.0) - Float32(u + Float32(Float32(normAngle * normAngle) * Float32(Float32(-0.16666666666666666) * Float32(Float32(Float32(1.0) - u) - (Float32(Float32(1.0) - u) ^ Float32(3.0)))))))) + Float32(n1_i * Float32(u + Float32(Float32(normAngle * normAngle) * Float32(u * Float32(0.16666666666666666))))))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = (n0_i * (single(1.0) - (u + ((normAngle * normAngle) * (single(-0.16666666666666666) * ((single(1.0) - u) - ((single(1.0) - u) ^ single(3.0)))))))) + (n1_i * (u + ((normAngle * normAngle) * (u * single(0.16666666666666666)))));
end
\begin{array}{l}

\\
n0_i \cdot \left(1 - \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(1 - u\right) - {\left(1 - u\right)}^{3}\right)\right)\right)\right) + n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(u \cdot 0.16666666666666666\right)\right)
\end{array}
Derivation
  1. Initial program 96.9%

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

    \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \color{blue}{\left(u + {normAngle}^{2} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right)} \cdot n1_i \]
  3. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right) \cdot n1_i \]
    2. distribute-lft-out--97.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)}\right) \cdot n1_i \]
  4. Simplified97.8%

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

    \[\leadsto \color{blue}{\left(\left(1 + {normAngle}^{2} \cdot \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right)\right) - u\right)} \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  6. Step-by-step derivation
    1. associate--l+98.5%

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

      \[\leadsto \left(1 + \left(\color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
    3. distribute-lft-out--98.5%

      \[\leadsto \left(1 + \left(\left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right)\right)} - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  7. Simplified98.5%

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

    \[\leadsto \left(1 + \left(\left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right)\right) - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(0.16666666666666666 \cdot u\right)}\right) \cdot n1_i \]
  9. Final simplification98.5%

    \[\leadsto n0_i \cdot \left(1 - \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left(\left(1 - u\right) - {\left(1 - u\right)}^{3}\right)\right)\right)\right) + n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(u \cdot 0.16666666666666666\right)\right) \]

Alternative 4: 98.7% accurate, 3.3× speedup?

\[\begin{array}{l} \\ n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) + n0_i \cdot \left(1 - \left(u - \left(normAngle \cdot normAngle\right) \cdot \left(u \cdot 0.3333333333333333\right)\right)\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+
  (*
   n1_i
   (+
    u
    (* (* normAngle normAngle) (* -0.16666666666666666 (- (pow u 3.0) u)))))
  (* n0_i (- 1.0 (- u (* (* normAngle normAngle) (* u 0.3333333333333333)))))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return (n1_i * (u + ((normAngle * normAngle) * (-0.16666666666666666f * (powf(u, 3.0f) - u))))) + (n0_i * (1.0f - (u - ((normAngle * normAngle) * (u * 0.3333333333333333f)))));
}
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 = (n1_i * (u + ((normangle * normangle) * ((-0.16666666666666666e0) * ((u ** 3.0e0) - u))))) + (n0_i * (1.0e0 - (u - ((normangle * normangle) * (u * 0.3333333333333333e0)))))
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(Float32(n1_i * Float32(u + Float32(Float32(normAngle * normAngle) * Float32(Float32(-0.16666666666666666) * Float32((u ^ Float32(3.0)) - u))))) + Float32(n0_i * Float32(Float32(1.0) - Float32(u - Float32(Float32(normAngle * normAngle) * Float32(u * Float32(0.3333333333333333)))))))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = (n1_i * (u + ((normAngle * normAngle) * (single(-0.16666666666666666) * ((u ^ single(3.0)) - u))))) + (n0_i * (single(1.0) - (u - ((normAngle * normAngle) * (u * single(0.3333333333333333))))));
end
\begin{array}{l}

\\
n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) + n0_i \cdot \left(1 - \left(u - \left(normAngle \cdot normAngle\right) \cdot \left(u \cdot 0.3333333333333333\right)\right)\right)
\end{array}
Derivation
  1. Initial program 96.9%

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

    \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \color{blue}{\left(u + {normAngle}^{2} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right)} \cdot n1_i \]
  3. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right) \cdot n1_i \]
    2. distribute-lft-out--97.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)}\right) \cdot n1_i \]
  4. Simplified97.8%

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

    \[\leadsto \color{blue}{\left(\left(1 + {normAngle}^{2} \cdot \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right)\right) - u\right)} \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  6. Step-by-step derivation
    1. associate--l+98.5%

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

      \[\leadsto \left(1 + \left(\color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-0.16666666666666666 \cdot {\left(1 - u\right)}^{3} - -0.16666666666666666 \cdot \left(1 - u\right)\right) - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
    3. distribute-lft-out--98.5%

      \[\leadsto \left(1 + \left(\left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left({\left(1 - u\right)}^{3} - \left(1 - u\right)\right)\right)} - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  7. Simplified98.5%

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

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

      \[\leadsto \left(1 + \left(\left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(u \cdot 0.3333333333333333\right)} - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  10. Simplified98.3%

    \[\leadsto \left(1 + \left(\left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(u \cdot 0.3333333333333333\right)} - u\right)\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  11. Final simplification98.3%

    \[\leadsto n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) + n0_i \cdot \left(1 - \left(u - \left(normAngle \cdot normAngle\right) \cdot \left(u \cdot 0.3333333333333333\right)\right)\right) \]

Alternative 5: 98.6% accurate, 3.5× speedup?

\[\begin{array}{l} \\ n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) + n0_i \cdot \left(1 - u\right) \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (+
  (*
   n1_i
   (+
    u
    (* (* normAngle normAngle) (* -0.16666666666666666 (- (pow u 3.0) u)))))
  (* n0_i (- 1.0 u))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return (n1_i * (u + ((normAngle * normAngle) * (-0.16666666666666666f * (powf(u, 3.0f) - u))))) + (n0_i * (1.0f - 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 = (n1_i * (u + ((normangle * normangle) * ((-0.16666666666666666e0) * ((u ** 3.0e0) - u))))) + (n0_i * (1.0e0 - u))
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(Float32(n1_i * Float32(u + Float32(Float32(normAngle * normAngle) * Float32(Float32(-0.16666666666666666) * Float32((u ^ Float32(3.0)) - u))))) + Float32(n0_i * Float32(Float32(1.0) - u)))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = (n1_i * (u + ((normAngle * normAngle) * (single(-0.16666666666666666) * ((u ^ single(3.0)) - u))))) + (n0_i * (single(1.0) - u));
end
\begin{array}{l}

\\
n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) + n0_i \cdot \left(1 - u\right)
\end{array}
Derivation
  1. Initial program 96.9%

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

    \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \color{blue}{\left(u + {normAngle}^{2} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right)} \cdot n1_i \]
  3. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \color{blue}{\left(normAngle \cdot normAngle\right)} \cdot \left(-0.16666666666666666 \cdot {u}^{3} - -0.16666666666666666 \cdot u\right)\right) \cdot n1_i \]
    2. distribute-lft-out--97.8%

      \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \color{blue}{\left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)}\right) \cdot n1_i \]
  4. Simplified97.8%

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

    \[\leadsto \color{blue}{\left(1 - u\right)} \cdot n0_i + \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) \cdot n1_i \]
  6. Final simplification98.1%

    \[\leadsto n1_i \cdot \left(u + \left(normAngle \cdot normAngle\right) \cdot \left(-0.16666666666666666 \cdot \left({u}^{3} - u\right)\right)\right) + n0_i \cdot \left(1 - u\right) \]

Alternative 6: 98.1% 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 96.9%

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

      \[\leadsto \color{blue}{n0_i \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right)} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. associate-*r*77.5%

      \[\leadsto \color{blue}{\left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle}} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    3. *-commutative77.5%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(u \cdot normAngle\right)\right)} \cdot n1_i \]
    4. associate-*l*71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    5. *-commutative71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right) \cdot \frac{1}{\sin normAngle}} \]
    6. distribute-rgt-out72.0%

      \[\leadsto \color{blue}{\frac{1}{\sin normAngle} \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    7. associate-*l/72.2%

      \[\leadsto \color{blue}{\frac{1 \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}{\sin normAngle}} \]
  3. Simplified72.2%

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

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

      \[\leadsto n0_i \cdot \color{blue}{\frac{1 \cdot 1 - u \cdot u}{1 + u}} + n1_i \cdot u \]
    2. associate-*r/96.8%

      \[\leadsto \color{blue}{\frac{n0_i \cdot \left(1 \cdot 1 - u \cdot u\right)}{1 + u}} + n1_i \cdot u \]
    3. metadata-eval96.8%

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

      \[\leadsto \frac{n0_i \cdot \left(1 - u \cdot u\right)}{\color{blue}{u + 1}} + n1_i \cdot u \]
  6. Applied egg-rr96.8%

    \[\leadsto \color{blue}{\frac{n0_i \cdot \left(1 - u \cdot u\right)}{u + 1}} + n1_i \cdot u \]
  7. Step-by-step derivation
    1. associate-/l*96.7%

      \[\leadsto \color{blue}{\frac{n0_i}{\frac{u + 1}{1 - u \cdot u}}} + n1_i \cdot u \]
  8. Simplified96.7%

    \[\leadsto \color{blue}{\frac{n0_i}{\frac{u + 1}{1 - u \cdot u}}} + n1_i \cdot u \]
  9. Taylor expanded in u around 0 97.3%

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(u, n1_i + \color{blue}{\left(-n0_i\right)}, n0_i\right) \]
    6. sub-neg97.4%

      \[\leadsto \mathsf{fma}\left(u, \color{blue}{n1_i - n0_i}, n0_i\right) \]
  11. Simplified97.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(u, n1_i - n0_i, n0_i\right)} \]
  12. Final simplification97.4%

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

Alternative 7: 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 7.199999872485958 \cdot 10^{-22}:\\ \;\;\;\;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 7.199999872485958e-22) 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 <= 7.199999872485958e-22f) {
		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 <= 7.199999872485958e-22) 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(7.199999872485958e-22))
		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(7.199999872485958e-22))
		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 7.199999872485958 \cdot 10^{-22}:\\
\;\;\;\;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 7.19999987e-22 < 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. *-commutative95.6%

        \[\leadsto \color{blue}{n0_i \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right)} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
      2. associate-*r*87.6%

        \[\leadsto \color{blue}{\left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle}} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
      3. *-commutative87.6%

        \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(u \cdot normAngle\right)\right)} \cdot n1_i \]
      4. associate-*l*80.7%

        \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
      5. *-commutative80.7%

        \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right) \cdot \frac{1}{\sin normAngle}} \]
      6. distribute-rgt-out80.9%

        \[\leadsto \color{blue}{\frac{1}{\sin normAngle} \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
      7. associate-*l/81.0%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}{\sin normAngle}} \]
    3. Simplified81.2%

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

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

      \[\leadsto \color{blue}{n1_i \cdot u} \]
    6. Step-by-step derivation
      1. *-commutative64.9%

        \[\leadsto \color{blue}{u \cdot n1_i} \]
    7. Simplified64.9%

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

    if -4.99999998e-13 < n1_i < 7.19999987e-22

    1. Initial program 97.7%

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

        \[\leadsto \color{blue}{n0_i \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right)} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
      2. associate-*r*70.8%

        \[\leadsto \color{blue}{\left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle}} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
      3. *-commutative70.8%

        \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(u \cdot normAngle\right)\right)} \cdot n1_i \]
      4. associate-*l*66.1%

        \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
      5. *-commutative66.1%

        \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right) \cdot \frac{1}{\sin normAngle}} \]
      6. distribute-rgt-out66.1%

        \[\leadsto \color{blue}{\frac{1}{\sin normAngle} \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
      7. associate-*l/66.3%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}{\sin normAngle}} \]
    3. Simplified66.2%

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

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

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

Alternative 8: 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 96.9%

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

      \[\leadsto \color{blue}{n0_i \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right)} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. associate-*r*77.5%

      \[\leadsto \color{blue}{\left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle}} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    3. *-commutative77.5%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(u \cdot normAngle\right)\right)} \cdot n1_i \]
    4. associate-*l*71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    5. *-commutative71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right) \cdot \frac{1}{\sin normAngle}} \]
    6. distribute-rgt-out72.0%

      \[\leadsto \color{blue}{\frac{1}{\sin normAngle} \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    7. associate-*l/72.2%

      \[\leadsto \color{blue}{\frac{1 \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}{\sin normAngle}} \]
  3. Simplified72.2%

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

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

      \[\leadsto n0_i \cdot \color{blue}{\frac{1 \cdot 1 - u \cdot u}{1 + u}} + n1_i \cdot u \]
    2. associate-*r/96.8%

      \[\leadsto \color{blue}{\frac{n0_i \cdot \left(1 \cdot 1 - u \cdot u\right)}{1 + u}} + n1_i \cdot u \]
    3. metadata-eval96.8%

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

      \[\leadsto \frac{n0_i \cdot \left(1 - u \cdot u\right)}{\color{blue}{u + 1}} + n1_i \cdot u \]
  6. Applied egg-rr96.8%

    \[\leadsto \color{blue}{\frac{n0_i \cdot \left(1 - u \cdot u\right)}{u + 1}} + n1_i \cdot u \]
  7. Step-by-step derivation
    1. associate-/l*96.7%

      \[\leadsto \color{blue}{\frac{n0_i}{\frac{u + 1}{1 - u \cdot u}}} + n1_i \cdot u \]
  8. Simplified96.7%

    \[\leadsto \color{blue}{\frac{n0_i}{\frac{u + 1}{1 - u \cdot u}}} + n1_i \cdot u \]
  9. Taylor expanded in u around 0 97.3%

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

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

Alternative 9: 81.8% accurate, 84.2× speedup?

\[\begin{array}{l} \\ n0_i + u \cdot n1_i \end{array} \]
(FPCore (normAngle u n0_i n1_i) :precision binary32 (+ n0_i (* u n1_i)))
float code(float normAngle, float u, float n0_i, float n1_i) {
	return n0_i + (u * n1_i);
}
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)
end function
function code(normAngle, u, n0_i, n1_i)
	return Float32(n0_i + Float32(u * n1_i))
end
function tmp = code(normAngle, u, n0_i, n1_i)
	tmp = n0_i + (u * n1_i);
end
\begin{array}{l}

\\
n0_i + u \cdot n1_i
\end{array}
Derivation
  1. Initial program 96.9%

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

      \[\leadsto \color{blue}{n0_i \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right)} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. associate-*r*77.5%

      \[\leadsto \color{blue}{\left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle}} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    3. *-commutative77.5%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(u \cdot normAngle\right)\right)} \cdot n1_i \]
    4. associate-*l*71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    5. *-commutative71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right) \cdot \frac{1}{\sin normAngle}} \]
    6. distribute-rgt-out72.0%

      \[\leadsto \color{blue}{\frac{1}{\sin normAngle} \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    7. associate-*l/72.2%

      \[\leadsto \color{blue}{\frac{1 \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}{\sin normAngle}} \]
  3. Simplified72.2%

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

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

    \[\leadsto \color{blue}{n0_i} + n1_i \cdot u \]
  6. Final simplification80.3%

    \[\leadsto n0_i + u \cdot n1_i \]

Alternative 10: 47.5% 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 96.9%

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

      \[\leadsto \color{blue}{n0_i \cdot \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right)} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    2. associate-*r*77.5%

      \[\leadsto \color{blue}{\left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle}} + \left(\sin \left(u \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n1_i \]
    3. *-commutative77.5%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\frac{1}{\sin normAngle} \cdot \sin \left(u \cdot normAngle\right)\right)} \cdot n1_i \]
    4. associate-*l*71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\frac{1}{\sin normAngle} \cdot \left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    5. *-commutative71.9%

      \[\leadsto \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right)\right) \cdot \frac{1}{\sin normAngle} + \color{blue}{\left(\sin \left(u \cdot normAngle\right) \cdot n1_i\right) \cdot \frac{1}{\sin normAngle}} \]
    6. distribute-rgt-out72.0%

      \[\leadsto \color{blue}{\frac{1}{\sin normAngle} \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)} \]
    7. associate-*l/72.2%

      \[\leadsto \color{blue}{\frac{1 \cdot \left(n0_i \cdot \sin \left(\left(1 - u\right) \cdot normAngle\right) + \sin \left(u \cdot normAngle\right) \cdot n1_i\right)}{\sin normAngle}} \]
  3. Simplified72.2%

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

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

    \[\leadsto n0_i \]

Reproduce

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