Curve intersection, scale width based on ribbon orientation

Percentage Accurate: 97.2% → 98.8%
Time: 10.5s
Alternatives: 5
Speedup: 38.3×

Specification

?
\[\left(\left(\left(0 \leq normAngle \land normAngle \leq \frac{\mathsf{PI}\left(\right)}{2}\right) \land \left(-1 \leq n0\_i \land n0\_i \leq 1\right)\right) \land \left(-1 \leq n1\_i \land n1\_i \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 1\right)\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\sin normAngle}\\ \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot t\_0\right) \cdot n0\_i + \left(\sin \left(u \cdot normAngle\right) \cdot t\_0\right) \cdot n1\_i \end{array} \end{array} \]
(FPCore (normAngle u n0_i n1_i)
 :precision binary32
 (let* ((t_0 (/ 1.0 (sin normAngle))))
   (+
    (* (* (sin (* (- 1.0 u) normAngle)) t_0) n0_i)
    (* (* (sin (* u normAngle)) t_0) n1_i))))
float code(float normAngle, float u, float n0_i, float n1_i) {
	float t_0 = 1.0f / sinf(normAngle);
	return ((sinf(((1.0f - u) * normAngle)) * t_0) * n0_i) + ((sinf((u * normAngle)) * t_0) * n1_i);
}
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 5 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.8% accurate, 3.5× speedup?

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

\\
n1\_i \cdot \left(\frac{normAngle}{\sin normAngle} \cdot u\right) + n0\_i \cdot \left(1 - u\right)
\end{array}
Derivation
  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. Add Preprocessing
  3. Taylor expanded in u around 0

    \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\frac{normAngle \cdot u}{\sin normAngle}} \cdot n1\_i \]
  4. Step-by-step derivation
    1. associate-*l/N/A

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(1 - u\right)} \cdot n0\_i + \left(\frac{normAngle}{\sin normAngle} \cdot u\right) \cdot n1\_i \]
  9. Final simplification99.2%

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

Alternative 2: 98.7% accurate, 3.5× speedup?

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

\\
\left(\frac{u}{\sin normAngle} \cdot normAngle\right) \cdot n1\_i + n0\_i \cdot \left(1 - u\right)
\end{array}
Derivation
  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. Add Preprocessing
  3. Taylor expanded in u around 0

    \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\frac{normAngle \cdot u}{\sin normAngle}} \cdot n1\_i \]
  4. Step-by-step derivation
    1. associate-*l/N/A

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(1 - u\right)} \cdot n0\_i + \left(\frac{normAngle}{\sin normAngle} \cdot u\right) \cdot n1\_i \]
  9. Step-by-step derivation
    1. Applied rewrites99.2%

      \[\leadsto \left(1 - u\right) \cdot n0\_i + \left(normAngle \cdot \color{blue}{\frac{u}{\sin normAngle}}\right) \cdot n1\_i \]
    2. Final simplification99.2%

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

    Alternative 3: 70.7% accurate, 21.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := n0\_i \cdot \left(1 - u\right)\\ \mathbf{if}\;n0\_i \leq -1.999999936531045 \cdot 10^{-21}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n0\_i \leq 1.9999999774532045 \cdot 10^{-26}:\\ \;\;\;\;\left(n1\_i - n0\_i\right) \cdot u\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (normAngle u n0_i n1_i)
     :precision binary32
     (let* ((t_0 (* n0_i (- 1.0 u))))
       (if (<= n0_i -1.999999936531045e-21)
         t_0
         (if (<= n0_i 1.9999999774532045e-26) (* (- n1_i n0_i) u) t_0))))
    float code(float normAngle, float u, float n0_i, float n1_i) {
    	float t_0 = n0_i * (1.0f - u);
    	float tmp;
    	if (n0_i <= -1.999999936531045e-21f) {
    		tmp = t_0;
    	} else if (n0_i <= 1.9999999774532045e-26f) {
    		tmp = (n1_i - n0_i) * u;
    	} else {
    		tmp = t_0;
    	}
    	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) :: t_0
        real(4) :: tmp
        t_0 = n0_i * (1.0e0 - u)
        if (n0_i <= (-1.999999936531045e-21)) then
            tmp = t_0
        else if (n0_i <= 1.9999999774532045e-26) then
            tmp = (n1_i - n0_i) * u
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    function code(normAngle, u, n0_i, n1_i)
    	t_0 = Float32(n0_i * Float32(Float32(1.0) - u))
    	tmp = Float32(0.0)
    	if (n0_i <= Float32(-1.999999936531045e-21))
    		tmp = t_0;
    	elseif (n0_i <= Float32(1.9999999774532045e-26))
    		tmp = Float32(Float32(n1_i - n0_i) * u);
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(normAngle, u, n0_i, n1_i)
    	t_0 = n0_i * (single(1.0) - u);
    	tmp = single(0.0);
    	if (n0_i <= single(-1.999999936531045e-21))
    		tmp = t_0;
    	elseif (n0_i <= single(1.9999999774532045e-26))
    		tmp = (n1_i - n0_i) * u;
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := n0\_i \cdot \left(1 - u\right)\\
    \mathbf{if}\;n0\_i \leq -1.999999936531045 \cdot 10^{-21}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;n0\_i \leq 1.9999999774532045 \cdot 10^{-26}:\\
    \;\;\;\;\left(n1\_i - n0\_i\right) \cdot u\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if n0_i < -1.9999999e-21 or 1.99999998e-26 < n0_i

      1. Initial program 98.5%

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

        \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\frac{normAngle \cdot u}{\sin normAngle}} \cdot n1\_i \]
      4. Step-by-step derivation
        1. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
      10. Step-by-step derivation
        1. sub-negN/A

          \[\leadsto n0\_i \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(u\right)\right)\right)} + n1\_i \cdot u \]
        2. distribute-lft-inN/A

          \[\leadsto \color{blue}{\left(n0\_i \cdot 1 + n0\_i \cdot \left(\mathsf{neg}\left(u\right)\right)\right)} + n1\_i \cdot u \]
        3. *-rgt-identityN/A

          \[\leadsto \left(\color{blue}{n0\_i} + n0\_i \cdot \left(\mathsf{neg}\left(u\right)\right)\right) + n1\_i \cdot u \]
        4. distribute-rgt-neg-inN/A

          \[\leadsto \left(n0\_i + \color{blue}{\left(\mathsf{neg}\left(n0\_i \cdot u\right)\right)}\right) + n1\_i \cdot u \]
        5. mul-1-negN/A

          \[\leadsto \left(n0\_i + \color{blue}{-1 \cdot \left(n0\_i \cdot u\right)}\right) + n1\_i \cdot u \]
        6. associate-+r+N/A

          \[\leadsto \color{blue}{n0\_i + \left(-1 \cdot \left(n0\_i \cdot u\right) + n1\_i \cdot u\right)} \]
        7. +-commutativeN/A

          \[\leadsto n0\_i + \color{blue}{\left(n1\_i \cdot u + -1 \cdot \left(n0\_i \cdot u\right)\right)} \]
        8. associate-*r*N/A

          \[\leadsto n0\_i + \left(n1\_i \cdot u + \color{blue}{\left(-1 \cdot n0\_i\right) \cdot u}\right) \]
        9. distribute-rgt-inN/A

          \[\leadsto n0\_i + \color{blue}{u \cdot \left(n1\_i + -1 \cdot n0\_i\right)} \]
        10. +-commutativeN/A

          \[\leadsto \color{blue}{u \cdot \left(n1\_i + -1 \cdot n0\_i\right) + n0\_i} \]
        11. *-commutativeN/A

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(n1\_i + -1 \cdot n0\_i, u, n0\_i\right)} \]
        13. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(n1\_i + \color{blue}{\left(\mathsf{neg}\left(n0\_i\right)\right)}, u, n0\_i\right) \]
        14. sub-negN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{n1\_i - n0\_i}, u, n0\_i\right) \]
        15. lower--.f3258.0

          \[\leadsto \mathsf{fma}\left(\color{blue}{n1\_i - n0\_i}, u, n0\_i\right) \]
      11. Applied rewrites58.0%

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

        \[\leadsto n0\_i \cdot \color{blue}{\left(1 + -1 \cdot u\right)} \]
      13. Step-by-step derivation
        1. Applied rewrites76.2%

          \[\leadsto n0\_i \cdot \color{blue}{\left(1 - u\right)} \]

        if -1.9999999e-21 < n0_i < 1.99999998e-26

        1. Initial program 96.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. Add Preprocessing
        3. Taylor expanded in normAngle around 0

          \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

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

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

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

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

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

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

            \[\leadsto \left(n1\_i - n0\_i\right) \cdot \color{blue}{u} \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 4: 98.0% accurate, 38.3× speedup?

        \[\begin{array}{l} \\ \left(n1\_i - n0\_i\right) \cdot u + n0\_i \end{array} \]
        (FPCore (normAngle u n0_i n1_i)
         :precision binary32
         (+ (* (- n1_i n0_i) u) n0_i))
        float code(float normAngle, float u, float n0_i, float n1_i) {
        	return ((n1_i - n0_i) * u) + 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 = ((n1_i - n0_i) * u) + n0_i
        end function
        
        function code(normAngle, u, n0_i, n1_i)
        	return Float32(Float32(Float32(n1_i - n0_i) * u) + n0_i)
        end
        
        function tmp = code(normAngle, u, n0_i, n1_i)
        	tmp = ((n1_i - n0_i) * u) + n0_i;
        end
        
        \begin{array}{l}
        
        \\
        \left(n1\_i - n0\_i\right) \cdot u + n0\_i
        \end{array}
        
        Derivation
        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. Add Preprocessing
        3. Taylor expanded in u around 0

          \[\leadsto \left(\sin \left(\left(1 - u\right) \cdot normAngle\right) \cdot \frac{1}{\sin normAngle}\right) \cdot n0\_i + \color{blue}{\frac{normAngle \cdot u}{\sin normAngle}} \cdot n1\_i \]
        4. Step-by-step derivation
          1. associate-*l/N/A

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
        10. Step-by-step derivation
          1. sub-negN/A

            \[\leadsto n0\_i \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(u\right)\right)\right)} + n1\_i \cdot u \]
          2. distribute-lft-inN/A

            \[\leadsto \color{blue}{\left(n0\_i \cdot 1 + n0\_i \cdot \left(\mathsf{neg}\left(u\right)\right)\right)} + n1\_i \cdot u \]
          3. *-rgt-identityN/A

            \[\leadsto \left(\color{blue}{n0\_i} + n0\_i \cdot \left(\mathsf{neg}\left(u\right)\right)\right) + n1\_i \cdot u \]
          4. distribute-rgt-neg-inN/A

            \[\leadsto \left(n0\_i + \color{blue}{\left(\mathsf{neg}\left(n0\_i \cdot u\right)\right)}\right) + n1\_i \cdot u \]
          5. mul-1-negN/A

            \[\leadsto \left(n0\_i + \color{blue}{-1 \cdot \left(n0\_i \cdot u\right)}\right) + n1\_i \cdot u \]
          6. associate-+r+N/A

            \[\leadsto \color{blue}{n0\_i + \left(-1 \cdot \left(n0\_i \cdot u\right) + n1\_i \cdot u\right)} \]
          7. +-commutativeN/A

            \[\leadsto n0\_i + \color{blue}{\left(n1\_i \cdot u + -1 \cdot \left(n0\_i \cdot u\right)\right)} \]
          8. associate-*r*N/A

            \[\leadsto n0\_i + \left(n1\_i \cdot u + \color{blue}{\left(-1 \cdot n0\_i\right) \cdot u}\right) \]
          9. distribute-rgt-inN/A

            \[\leadsto n0\_i + \color{blue}{u \cdot \left(n1\_i + -1 \cdot n0\_i\right)} \]
          10. +-commutativeN/A

            \[\leadsto \color{blue}{u \cdot \left(n1\_i + -1 \cdot n0\_i\right) + n0\_i} \]
          11. *-commutativeN/A

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(n1\_i + -1 \cdot n0\_i, u, n0\_i\right)} \]
          13. mul-1-negN/A

            \[\leadsto \mathsf{fma}\left(n1\_i + \color{blue}{\left(\mathsf{neg}\left(n0\_i\right)\right)}, u, n0\_i\right) \]
          14. sub-negN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{n1\_i - n0\_i}, u, n0\_i\right) \]
          15. lower--.f3243.8

            \[\leadsto \mathsf{fma}\left(\color{blue}{n1\_i - n0\_i}, u, n0\_i\right) \]
        11. Applied rewrites43.8%

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

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

          Alternative 5: 37.0% accurate, 51.0× speedup?

          \[\begin{array}{l} \\ \left(n1\_i - n0\_i\right) \cdot u \end{array} \]
          (FPCore (normAngle u n0_i n1_i) :precision binary32 (* (- n1_i n0_i) u))
          float code(float normAngle, float u, float n0_i, float n1_i) {
          	return (n1_i - n0_i) * u;
          }
          
          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 - n0_i) * u
          end function
          
          function code(normAngle, u, n0_i, n1_i)
          	return Float32(Float32(n1_i - n0_i) * u)
          end
          
          function tmp = code(normAngle, u, n0_i, n1_i)
          	tmp = (n1_i - n0_i) * u;
          end
          
          \begin{array}{l}
          
          \\
          \left(n1\_i - n0\_i\right) \cdot u
          \end{array}
          
          Derivation
          1. Initial program 97.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. Add Preprocessing
          3. Taylor expanded in normAngle around 0

            \[\leadsto \color{blue}{n0\_i \cdot \left(1 - u\right) + n1\_i \cdot u} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

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

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

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

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

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

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

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

            Reproduce

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