Toniolo and Linder, Equation (10-)

Percentage Accurate: 36.1% → 97.0%
Time: 17.4s
Alternatives: 17
Speedup: 11.0×

Specification

?
\[\begin{array}{l} \\ \frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)} \end{array} \]
(FPCore (t l k)
 :precision binary64
 (/
  2.0
  (*
   (* (* (/ (pow t 3.0) (* l l)) (sin k)) (tan k))
   (- (+ 1.0 (pow (/ k t) 2.0)) 1.0))))
double code(double t, double l, double k) {
	return 2.0 / ((((pow(t, 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + pow((k / t), 2.0)) - 1.0));
}
real(8) function code(t, l, k)
    real(8), intent (in) :: t
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    code = 2.0d0 / (((((t ** 3.0d0) / (l * l)) * sin(k)) * tan(k)) * ((1.0d0 + ((k / t) ** 2.0d0)) - 1.0d0))
end function
public static double code(double t, double l, double k) {
	return 2.0 / ((((Math.pow(t, 3.0) / (l * l)) * Math.sin(k)) * Math.tan(k)) * ((1.0 + Math.pow((k / t), 2.0)) - 1.0));
}
def code(t, l, k):
	return 2.0 / ((((math.pow(t, 3.0) / (l * l)) * math.sin(k)) * math.tan(k)) * ((1.0 + math.pow((k / t), 2.0)) - 1.0))
function code(t, l, k)
	return Float64(2.0 / Float64(Float64(Float64(Float64((t ^ 3.0) / Float64(l * l)) * sin(k)) * tan(k)) * Float64(Float64(1.0 + (Float64(k / t) ^ 2.0)) - 1.0)))
end
function tmp = code(t, l, k)
	tmp = 2.0 / (((((t ^ 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + ((k / t) ^ 2.0)) - 1.0));
end
code[t_, l_, k_] := N[(2.0 / N[(N[(N[(N[(N[Power[t, 3.0], $MachinePrecision] / N[(l * l), $MachinePrecision]), $MachinePrecision] * N[Sin[k], $MachinePrecision]), $MachinePrecision] * N[Tan[k], $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 + N[Power[N[(k / t), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)}
\end{array}

Sampling outcomes in binary64 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 17 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: 36.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)} \end{array} \]
(FPCore (t l k)
 :precision binary64
 (/
  2.0
  (*
   (* (* (/ (pow t 3.0) (* l l)) (sin k)) (tan k))
   (- (+ 1.0 (pow (/ k t) 2.0)) 1.0))))
double code(double t, double l, double k) {
	return 2.0 / ((((pow(t, 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + pow((k / t), 2.0)) - 1.0));
}
real(8) function code(t, l, k)
    real(8), intent (in) :: t
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    code = 2.0d0 / (((((t ** 3.0d0) / (l * l)) * sin(k)) * tan(k)) * ((1.0d0 + ((k / t) ** 2.0d0)) - 1.0d0))
end function
public static double code(double t, double l, double k) {
	return 2.0 / ((((Math.pow(t, 3.0) / (l * l)) * Math.sin(k)) * Math.tan(k)) * ((1.0 + Math.pow((k / t), 2.0)) - 1.0));
}
def code(t, l, k):
	return 2.0 / ((((math.pow(t, 3.0) / (l * l)) * math.sin(k)) * math.tan(k)) * ((1.0 + math.pow((k / t), 2.0)) - 1.0))
function code(t, l, k)
	return Float64(2.0 / Float64(Float64(Float64(Float64((t ^ 3.0) / Float64(l * l)) * sin(k)) * tan(k)) * Float64(Float64(1.0 + (Float64(k / t) ^ 2.0)) - 1.0)))
end
function tmp = code(t, l, k)
	tmp = 2.0 / (((((t ^ 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + ((k / t) ^ 2.0)) - 1.0));
end
code[t_, l_, k_] := N[(2.0 / N[(N[(N[(N[(N[Power[t, 3.0], $MachinePrecision] / N[(l * l), $MachinePrecision]), $MachinePrecision] * N[Sin[k], $MachinePrecision]), $MachinePrecision] * N[Tan[k], $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 + N[Power[N[(k / t), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)}
\end{array}

Alternative 1: 97.0% accurate, 1.7× speedup?

\[\begin{array}{l} k_m = \left|k\right| \\ \begin{array}{l} \mathbf{if}\;k\_m \leq 9 \cdot 10^{-7}:\\ \;\;\;\;\frac{\frac{\ell \cdot \mathsf{fma}\left(k\_m \cdot k\_m, 0.6666666666666666, 2\right)}{k\_m \cdot k\_m}}{k\_m \cdot t} \cdot \frac{\ell \cdot \cos k\_m}{k\_m}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \ell}{k\_m \cdot \mathsf{fma}\left(\cos \left(k\_m + k\_m\right), -0.5, 0.5\right)} \cdot \frac{\ell \cdot \frac{\cos k\_m}{k\_m}}{t}\\ \end{array} \end{array} \]
k_m = (fabs.f64 k)
(FPCore (t l k_m)
 :precision binary64
 (if (<= k_m 9e-7)
   (*
    (/
     (/ (* l (fma (* k_m k_m) 0.6666666666666666 2.0)) (* k_m k_m))
     (* k_m t))
    (/ (* l (cos k_m)) k_m))
   (*
    (/ (* 2.0 l) (* k_m (fma (cos (+ k_m k_m)) -0.5 0.5)))
    (/ (* l (/ (cos k_m) k_m)) t))))
k_m = fabs(k);
double code(double t, double l, double k_m) {
	double tmp;
	if (k_m <= 9e-7) {
		tmp = (((l * fma((k_m * k_m), 0.6666666666666666, 2.0)) / (k_m * k_m)) / (k_m * t)) * ((l * cos(k_m)) / k_m);
	} else {
		tmp = ((2.0 * l) / (k_m * fma(cos((k_m + k_m)), -0.5, 0.5))) * ((l * (cos(k_m) / k_m)) / t);
	}
	return tmp;
}
k_m = abs(k)
function code(t, l, k_m)
	tmp = 0.0
	if (k_m <= 9e-7)
		tmp = Float64(Float64(Float64(Float64(l * fma(Float64(k_m * k_m), 0.6666666666666666, 2.0)) / Float64(k_m * k_m)) / Float64(k_m * t)) * Float64(Float64(l * cos(k_m)) / k_m));
	else
		tmp = Float64(Float64(Float64(2.0 * l) / Float64(k_m * fma(cos(Float64(k_m + k_m)), -0.5, 0.5))) * Float64(Float64(l * Float64(cos(k_m) / k_m)) / t));
	end
	return tmp
end
k_m = N[Abs[k], $MachinePrecision]
code[t_, l_, k$95$m_] := If[LessEqual[k$95$m, 9e-7], N[(N[(N[(N[(l * N[(N[(k$95$m * k$95$m), $MachinePrecision] * 0.6666666666666666 + 2.0), $MachinePrecision]), $MachinePrecision] / N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision] / N[(k$95$m * t), $MachinePrecision]), $MachinePrecision] * N[(N[(l * N[Cos[k$95$m], $MachinePrecision]), $MachinePrecision] / k$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 * l), $MachinePrecision] / N[(k$95$m * N[(N[Cos[N[(k$95$m + k$95$m), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(l * N[(N[Cos[k$95$m], $MachinePrecision] / k$95$m), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
k_m = \left|k\right|

\\
\begin{array}{l}
\mathbf{if}\;k\_m \leq 9 \cdot 10^{-7}:\\
\;\;\;\;\frac{\frac{\ell \cdot \mathsf{fma}\left(k\_m \cdot k\_m, 0.6666666666666666, 2\right)}{k\_m \cdot k\_m}}{k\_m \cdot t} \cdot \frac{\ell \cdot \cos k\_m}{k\_m}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \ell}{k\_m \cdot \mathsf{fma}\left(\cos \left(k\_m + k\_m\right), -0.5, 0.5\right)} \cdot \frac{\ell \cdot \frac{\cos k\_m}{k\_m}}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 8.99999999999999959e-7

    1. Initial program 36.8%

      \[\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in t around 0

      \[\leadsto \color{blue}{2 \cdot \frac{{\ell}^{2} \cdot \cos k}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
      2. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
      3. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      4. unpow2N/A

        \[\leadsto \frac{2 \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      5. associate-*l*N/A

        \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      6. *-commutativeN/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\cos k \cdot \ell\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\cos k \cdot \ell\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      8. *-commutativeN/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      10. lower-cos.f64N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \color{blue}{\cos k}\right)\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      11. unpow2N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{\left(k \cdot k\right)} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
      12. associate-*l*N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
      13. *-commutativeN/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
      14. lower-*.f64N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
      15. *-commutativeN/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
      16. lower-*.f64N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
      17. lower-*.f64N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \color{blue}{\left(t \cdot {\sin k}^{2}\right)}\right)} \]
      18. lower-pow.f64N/A

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot \color{blue}{{\sin k}^{2}}\right)\right)} \]
      19. lower-sin.f6471.2

        \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\color{blue}{\sin k}}^{2}\right)\right)} \]
    5. Applied rewrites71.2%

      \[\leadsto \color{blue}{\frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
    6. Step-by-step derivation
      1. Applied rewrites69.8%

        \[\leadsto \frac{2 \cdot \ell}{\left(0.5 - 0.5 \cdot \cos \left(k + k\right)\right) \cdot \left(t \cdot k\right)} \cdot \color{blue}{\frac{\ell \cdot \cos k}{k}} \]
      2. Step-by-step derivation
        1. Applied rewrites69.8%

          \[\leadsto \frac{\frac{2 \cdot \ell}{\mathsf{fma}\left(\cos \left(k + k\right), -0.5, 0.5\right)}}{k \cdot t} \cdot \frac{\color{blue}{\ell \cdot \cos k}}{k} \]
        2. Taylor expanded in k around 0

          \[\leadsto \frac{\frac{\frac{2}{3} \cdot \left({k}^{2} \cdot \ell\right) + 2 \cdot \ell}{{k}^{2}}}{k \cdot t} \cdot \frac{\color{blue}{\ell} \cdot \cos k}{k} \]
        3. Step-by-step derivation
          1. Applied rewrites93.0%

            \[\leadsto \frac{\frac{\ell \cdot \mathsf{fma}\left(k \cdot k, 0.6666666666666666, 2\right)}{k \cdot k}}{k \cdot t} \cdot \frac{\color{blue}{\ell} \cdot \cos k}{k} \]

          if 8.99999999999999959e-7 < k

          1. Initial program 34.2%

            \[\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in t around 0

            \[\leadsto \color{blue}{2 \cdot \frac{{\ell}^{2} \cdot \cos k}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
          4. Step-by-step derivation
            1. associate-*r/N/A

              \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
            2. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
            3. lower-*.f64N/A

              \[\leadsto \frac{\color{blue}{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            4. unpow2N/A

              \[\leadsto \frac{2 \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            5. associate-*l*N/A

              \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            6. *-commutativeN/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\cos k \cdot \ell\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            7. lower-*.f64N/A

              \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\cos k \cdot \ell\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            8. *-commutativeN/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            9. lower-*.f64N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            10. lower-cos.f64N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \color{blue}{\cos k}\right)\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            11. unpow2N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{\left(k \cdot k\right)} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
            12. associate-*l*N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
            13. *-commutativeN/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
            14. lower-*.f64N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
            15. *-commutativeN/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
            16. lower-*.f64N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
            17. lower-*.f64N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \color{blue}{\left(t \cdot {\sin k}^{2}\right)}\right)} \]
            18. lower-pow.f64N/A

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot \color{blue}{{\sin k}^{2}}\right)\right)} \]
            19. lower-sin.f6470.7

              \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\color{blue}{\sin k}}^{2}\right)\right)} \]
          5. Applied rewrites70.7%

            \[\leadsto \color{blue}{\frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
          6. Step-by-step derivation
            1. Applied rewrites91.8%

              \[\leadsto \frac{2 \cdot \ell}{\left(0.5 - 0.5 \cdot \cos \left(k + k\right)\right) \cdot \left(t \cdot k\right)} \cdot \color{blue}{\frac{\ell \cdot \cos k}{k}} \]
            2. Step-by-step derivation
              1. Applied rewrites70.6%

                \[\leadsto \frac{\ell \cdot \left(2 \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(\mathsf{fma}\left(\cos \left(k + k\right), -0.5, 0.5\right) \cdot \left(k \cdot t\right)\right)}} \]
              2. Step-by-step derivation
                1. Applied rewrites99.2%

                  \[\leadsto \frac{2 \cdot \ell}{k \cdot \mathsf{fma}\left(\cos \left(k + k\right), -0.5, 0.5\right)} \cdot \color{blue}{\frac{\ell \cdot \frac{\cos k}{k}}{t}} \]
              3. Recombined 2 regimes into one program.
              4. Add Preprocessing

              Alternative 2: 97.0% accurate, 1.7× speedup?

              \[\begin{array}{l} k_m = \left|k\right| \\ \begin{array}{l} t_1 := \frac{\ell \cdot \cos k\_m}{k\_m}\\ \mathbf{if}\;k\_m \leq 9 \cdot 10^{-7}:\\ \;\;\;\;\frac{\frac{\ell \cdot \mathsf{fma}\left(k\_m \cdot k\_m, 0.6666666666666666, 2\right)}{k\_m \cdot k\_m}}{k\_m \cdot t} \cdot t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \left(\frac{2}{t \cdot \mathsf{fma}\left(\cos \left(k\_m + k\_m\right), -0.5, 0.5\right)} \cdot \frac{\ell}{k\_m}\right)\\ \end{array} \end{array} \]
              k_m = (fabs.f64 k)
              (FPCore (t l k_m)
               :precision binary64
               (let* ((t_1 (/ (* l (cos k_m)) k_m)))
                 (if (<= k_m 9e-7)
                   (*
                    (/
                     (/ (* l (fma (* k_m k_m) 0.6666666666666666 2.0)) (* k_m k_m))
                     (* k_m t))
                    t_1)
                   (* t_1 (* (/ 2.0 (* t (fma (cos (+ k_m k_m)) -0.5 0.5))) (/ l k_m))))))
              k_m = fabs(k);
              double code(double t, double l, double k_m) {
              	double t_1 = (l * cos(k_m)) / k_m;
              	double tmp;
              	if (k_m <= 9e-7) {
              		tmp = (((l * fma((k_m * k_m), 0.6666666666666666, 2.0)) / (k_m * k_m)) / (k_m * t)) * t_1;
              	} else {
              		tmp = t_1 * ((2.0 / (t * fma(cos((k_m + k_m)), -0.5, 0.5))) * (l / k_m));
              	}
              	return tmp;
              }
              
              k_m = abs(k)
              function code(t, l, k_m)
              	t_1 = Float64(Float64(l * cos(k_m)) / k_m)
              	tmp = 0.0
              	if (k_m <= 9e-7)
              		tmp = Float64(Float64(Float64(Float64(l * fma(Float64(k_m * k_m), 0.6666666666666666, 2.0)) / Float64(k_m * k_m)) / Float64(k_m * t)) * t_1);
              	else
              		tmp = Float64(t_1 * Float64(Float64(2.0 / Float64(t * fma(cos(Float64(k_m + k_m)), -0.5, 0.5))) * Float64(l / k_m)));
              	end
              	return tmp
              end
              
              k_m = N[Abs[k], $MachinePrecision]
              code[t_, l_, k$95$m_] := Block[{t$95$1 = N[(N[(l * N[Cos[k$95$m], $MachinePrecision]), $MachinePrecision] / k$95$m), $MachinePrecision]}, If[LessEqual[k$95$m, 9e-7], N[(N[(N[(N[(l * N[(N[(k$95$m * k$95$m), $MachinePrecision] * 0.6666666666666666 + 2.0), $MachinePrecision]), $MachinePrecision] / N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision] / N[(k$95$m * t), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], N[(t$95$1 * N[(N[(2.0 / N[(t * N[(N[Cos[N[(k$95$m + k$95$m), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(l / k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
              
              \begin{array}{l}
              k_m = \left|k\right|
              
              \\
              \begin{array}{l}
              t_1 := \frac{\ell \cdot \cos k\_m}{k\_m}\\
              \mathbf{if}\;k\_m \leq 9 \cdot 10^{-7}:\\
              \;\;\;\;\frac{\frac{\ell \cdot \mathsf{fma}\left(k\_m \cdot k\_m, 0.6666666666666666, 2\right)}{k\_m \cdot k\_m}}{k\_m \cdot t} \cdot t\_1\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_1 \cdot \left(\frac{2}{t \cdot \mathsf{fma}\left(\cos \left(k\_m + k\_m\right), -0.5, 0.5\right)} \cdot \frac{\ell}{k\_m}\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if k < 8.99999999999999959e-7

                1. Initial program 41.1%

                  \[\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)} \]
                2. Add Preprocessing
                3. Taylor expanded in t around 0

                  \[\leadsto \color{blue}{2 \cdot \frac{{\ell}^{2} \cdot \cos k}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
                4. Step-by-step derivation
                  1. associate-*r/N/A

                    \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
                  2. lower-/.f64N/A

                    \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
                  3. lower-*.f64N/A

                    \[\leadsto \frac{\color{blue}{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  4. unpow2N/A

                    \[\leadsto \frac{2 \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  5. associate-*l*N/A

                    \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  6. *-commutativeN/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\cos k \cdot \ell\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  7. lower-*.f64N/A

                    \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\cos k \cdot \ell\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  8. *-commutativeN/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  9. lower-*.f64N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  10. lower-cos.f64N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \color{blue}{\cos k}\right)\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  11. unpow2N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{\left(k \cdot k\right)} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                  12. associate-*l*N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                  13. *-commutativeN/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
                  14. lower-*.f64N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
                  15. *-commutativeN/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                  16. lower-*.f64N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                  17. lower-*.f64N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \color{blue}{\left(t \cdot {\sin k}^{2}\right)}\right)} \]
                  18. lower-pow.f64N/A

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot \color{blue}{{\sin k}^{2}}\right)\right)} \]
                  19. lower-sin.f6475.6

                    \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\color{blue}{\sin k}}^{2}\right)\right)} \]
                5. Applied rewrites75.6%

                  \[\leadsto \color{blue}{\frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                6. Step-by-step derivation
                  1. Applied rewrites72.6%

                    \[\leadsto \frac{2 \cdot \ell}{\left(0.5 - 0.5 \cdot \cos \left(k + k\right)\right) \cdot \left(t \cdot k\right)} \cdot \color{blue}{\frac{\ell \cdot \cos k}{k}} \]
                  2. Step-by-step derivation
                    1. Applied rewrites72.6%

                      \[\leadsto \frac{\frac{2 \cdot \ell}{\mathsf{fma}\left(\cos \left(k + k\right), -0.5, 0.5\right)}}{k \cdot t} \cdot \frac{\color{blue}{\ell \cdot \cos k}}{k} \]
                    2. Taylor expanded in k around 0

                      \[\leadsto \frac{\frac{\frac{2}{3} \cdot \left({k}^{2} \cdot \ell\right) + 2 \cdot \ell}{{k}^{2}}}{k \cdot t} \cdot \frac{\color{blue}{\ell} \cdot \cos k}{k} \]
                    3. Step-by-step derivation
                      1. Applied rewrites95.0%

                        \[\leadsto \frac{\frac{\ell \cdot \mathsf{fma}\left(k \cdot k, 0.6666666666666666, 2\right)}{k \cdot k}}{k \cdot t} \cdot \frac{\color{blue}{\ell} \cdot \cos k}{k} \]

                      if 8.99999999999999959e-7 < k

                      1. Initial program 31.2%

                        \[\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) - 1\right)} \]
                      2. Add Preprocessing
                      3. Taylor expanded in t around 0

                        \[\leadsto \color{blue}{2 \cdot \frac{{\ell}^{2} \cdot \cos k}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
                      4. Step-by-step derivation
                        1. associate-*r/N/A

                          \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
                        2. lower-/.f64N/A

                          \[\leadsto \color{blue}{\frac{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)}} \]
                        3. lower-*.f64N/A

                          \[\leadsto \frac{\color{blue}{2 \cdot \left({\ell}^{2} \cdot \cos k\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        4. unpow2N/A

                          \[\leadsto \frac{2 \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \cos k\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        5. associate-*l*N/A

                          \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        6. *-commutativeN/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\cos k \cdot \ell\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        7. lower-*.f64N/A

                          \[\leadsto \frac{2 \cdot \color{blue}{\left(\ell \cdot \left(\cos k \cdot \ell\right)\right)}}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        8. *-commutativeN/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        9. lower-*.f64N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \color{blue}{\left(\ell \cdot \cos k\right)}\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        10. lower-cos.f64N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \color{blue}{\cos k}\right)\right)}{{k}^{2} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        11. unpow2N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{\left(k \cdot k\right)} \cdot \left(t \cdot {\sin k}^{2}\right)} \]
                        12. associate-*l*N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                        13. *-commutativeN/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
                        14. lower-*.f64N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{\color{blue}{k \cdot \left(\left(t \cdot {\sin k}^{2}\right) \cdot k\right)}} \]
                        15. *-commutativeN/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                        16. lower-*.f64N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \color{blue}{\left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                        17. lower-*.f64N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \color{blue}{\left(t \cdot {\sin k}^{2}\right)}\right)} \]
                        18. lower-pow.f64N/A

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot \color{blue}{{\sin k}^{2}}\right)\right)} \]
                        19. lower-sin.f6476.7

                          \[\leadsto \frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\color{blue}{\sin k}}^{2}\right)\right)} \]
                      5. Applied rewrites76.7%

                        \[\leadsto \color{blue}{\frac{2 \cdot \left(\ell \cdot \left(\ell \cdot \cos k\right)\right)}{k \cdot \left(k \cdot \left(t \cdot {\sin k}^{2}\right)\right)}} \]
                      6. Step-by-step derivation
                        1. Applied rewrites92.7%

                          \[\leadsto \frac{2 \cdot \ell}{\left(0.5 - 0.5 \cdot \cos \left(k + k\right)\right) \cdot \left(t \cdot k\right)} \cdot \color{blue}{\frac{\ell \cdot \cos k}{k}} \]
                        2. Step-by-step derivation
                          1. Applied rewrites98.9%

                            \[\leadsto \left(\frac{2}{\mathsf{fma}\left(\cos \left(k + k\right), -0.5, 0.5\right) \cdot t} \cdot \frac{\ell}{k}\right) \cdot \frac{\color{blue}{\ell \cdot \cos k}}{k} \]
                        3. Recombined 2 regimes into one program.
                        4. Final simplification97.0%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 9 \cdot 10^{-7}:\\ \;\;\;\;\frac{\frac{\ell \cdot \mathsf{fma}\left(k \cdot k, 0.6666666666666666, 2\right)}{k \cdot k}}{k \cdot t} \cdot \frac{\ell \cdot \cos k}{k}\\ \mathbf{else}:\\ \;\;\;\;\frac{\ell \cdot \cos k}{k} \cdot \left(\frac{2}{t \cdot \mathsf{fma}\left(\cos \left(k + k\right), -0.5, 0.5\right)} \cdot \frac{\ell}{k}\right)\\ \end{array} \]
                        5. Add Preprocessing

                        Reproduce

                        ?
                        herbie shell --seed 2024226 
                        (FPCore (t l k)
                          :name "Toniolo and Linder, Equation (10-)"
                          :precision binary64
                          (/ 2.0 (* (* (* (/ (pow t 3.0) (* l l)) (sin k)) (tan k)) (- (+ 1.0 (pow (/ k t) 2.0)) 1.0))))