Toniolo and Linder, Equation (10-)

Percentage Accurate: 35.0% → 93.8%
Time: 18.5s
Alternatives: 13
Speedup: 17.1×

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 13 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: 35.0% 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: 93.8% accurate, 1.3× speedup?

\[\begin{array}{l} k_m = \left|k\right| \\ \begin{array}{l} \mathbf{if}\;k\_m \leq 2.55 \cdot 10^{-21}:\\ \;\;\;\;\frac{\ell + \ell}{t \cdot \left(k\_m \cdot k\_m\right)} \cdot \frac{\ell}{k\_m \cdot k\_m}\\ \mathbf{else}:\\ \;\;\;\;\frac{\ell \cdot \cos k\_m}{k\_m} \cdot \frac{\ell + \ell}{\sin k\_m \cdot \left(\sin k\_m \cdot \left(k\_m \cdot t\right)\right)}\\ \end{array} \end{array} \]
k_m = (fabs.f64 k)
(FPCore (t l k_m)
 :precision binary64
 (if (<= k_m 2.55e-21)
   (* (/ (+ l l) (* t (* k_m k_m))) (/ l (* k_m k_m)))
   (*
    (/ (* l (cos k_m)) k_m)
    (/ (+ l l) (* (sin k_m) (* (sin k_m) (* k_m t)))))))
k_m = fabs(k);
double code(double t, double l, double k_m) {
	double tmp;
	if (k_m <= 2.55e-21) {
		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
	} else {
		tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (sin(k_m) * (sin(k_m) * (k_m * t))));
	}
	return tmp;
}
k_m = abs(k)
real(8) function code(t, l, k_m)
    real(8), intent (in) :: t
    real(8), intent (in) :: l
    real(8), intent (in) :: k_m
    real(8) :: tmp
    if (k_m <= 2.55d-21) then
        tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m))
    else
        tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (sin(k_m) * (sin(k_m) * (k_m * t))))
    end if
    code = tmp
end function
k_m = Math.abs(k);
public static double code(double t, double l, double k_m) {
	double tmp;
	if (k_m <= 2.55e-21) {
		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
	} else {
		tmp = ((l * Math.cos(k_m)) / k_m) * ((l + l) / (Math.sin(k_m) * (Math.sin(k_m) * (k_m * t))));
	}
	return tmp;
}
k_m = math.fabs(k)
def code(t, l, k_m):
	tmp = 0
	if k_m <= 2.55e-21:
		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m))
	else:
		tmp = ((l * math.cos(k_m)) / k_m) * ((l + l) / (math.sin(k_m) * (math.sin(k_m) * (k_m * t))))
	return tmp
k_m = abs(k)
function code(t, l, k_m)
	tmp = 0.0
	if (k_m <= 2.55e-21)
		tmp = Float64(Float64(Float64(l + l) / Float64(t * Float64(k_m * k_m))) * Float64(l / Float64(k_m * k_m)));
	else
		tmp = Float64(Float64(Float64(l * cos(k_m)) / k_m) * Float64(Float64(l + l) / Float64(sin(k_m) * Float64(sin(k_m) * Float64(k_m * t)))));
	end
	return tmp
end
k_m = abs(k);
function tmp_2 = code(t, l, k_m)
	tmp = 0.0;
	if (k_m <= 2.55e-21)
		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
	else
		tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (sin(k_m) * (sin(k_m) * (k_m * t))));
	end
	tmp_2 = tmp;
end
k_m = N[Abs[k], $MachinePrecision]
code[t_, l_, k$95$m_] := If[LessEqual[k$95$m, 2.55e-21], N[(N[(N[(l + l), $MachinePrecision] / N[(t * N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(l / N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(l * N[Cos[k$95$m], $MachinePrecision]), $MachinePrecision] / k$95$m), $MachinePrecision] * N[(N[(l + l), $MachinePrecision] / N[(N[Sin[k$95$m], $MachinePrecision] * N[(N[Sin[k$95$m], $MachinePrecision] * N[(k$95$m * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
k_m = \left|k\right|

\\
\begin{array}{l}
\mathbf{if}\;k\_m \leq 2.55 \cdot 10^{-21}:\\
\;\;\;\;\frac{\ell + \ell}{t \cdot \left(k\_m \cdot k\_m\right)} \cdot \frac{\ell}{k\_m \cdot k\_m}\\

\mathbf{else}:\\
\;\;\;\;\frac{\ell \cdot \cos k\_m}{k\_m} \cdot \frac{\ell + \ell}{\sin k\_m \cdot \left(\sin k\_m \cdot \left(k\_m \cdot t\right)\right)}\\


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

    1. Initial program 41.5%

      \[\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 k around 0

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

        \[\leadsto \color{blue}{\frac{2 \cdot {\ell}^{2}}{{k}^{4} \cdot t}} \]
      2. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{2 \cdot {\ell}^{2}}{{k}^{4} \cdot t}} \]
      3. unpow2N/A

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

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

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

        \[\leadsto \frac{\color{blue}{\ell \cdot \left(2 \cdot \ell\right)}}{{k}^{4} \cdot t} \]
      7. count-2N/A

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

        \[\leadsto \frac{\ell \cdot \color{blue}{\left(\ell + \ell\right)}}{{k}^{4} \cdot t} \]
      9. *-commutativeN/A

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

        \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{\color{blue}{t \cdot {k}^{4}}} \]
      11. metadata-evalN/A

        \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{t \cdot {k}^{\color{blue}{\left(2 \cdot 2\right)}}} \]
      12. pow-sqrN/A

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

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

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

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

        \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{t \cdot \left(\left(k \cdot k\right) \cdot \color{blue}{\left(k \cdot k\right)}\right)} \]
      17. lower-*.f6468.4

        \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{t \cdot \left(\left(k \cdot k\right) \cdot \color{blue}{\left(k \cdot k\right)}\right)} \]
    5. Applied rewrites68.4%

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

        \[\leadsto \frac{\ell + \ell}{t \cdot \left(k \cdot k\right)} \cdot \color{blue}{\frac{\ell}{k \cdot k}} \]

      if 2.55000000000000002e-21 < k

      1. Initial program 31.9%

        \[\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. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\cos k \cdot \left(\ell \cdot \left(\ell + \ell\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{\ell \cdot \cos k}{k} \cdot \color{blue}{\frac{\ell + \ell}{\left(0.5 - 0.5 \cdot \cos \left(k + k\right)\right) \cdot \left(t \cdot k\right)}} \]
        2. Step-by-step derivation
          1. Applied rewrites94.8%

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

              \[\leadsto \frac{\ell \cdot \cos k}{k} \cdot \frac{\ell + \ell}{\left(\left(k \cdot t\right) \cdot \sin k\right) \cdot \color{blue}{\sin k}} \]
          3. Recombined 2 regimes into one program.
          4. Final simplification92.6%

            \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 2.55 \cdot 10^{-21}:\\ \;\;\;\;\frac{\ell + \ell}{t \cdot \left(k \cdot k\right)} \cdot \frac{\ell}{k \cdot k}\\ \mathbf{else}:\\ \;\;\;\;\frac{\ell \cdot \cos k}{k} \cdot \frac{\ell + \ell}{\sin k \cdot \left(\sin k \cdot \left(k \cdot t\right)\right)}\\ \end{array} \]
          5. Add Preprocessing

          Alternative 2: 93.8% accurate, 1.3× speedup?

          \[\begin{array}{l} k_m = \left|k\right| \\ \begin{array}{l} \mathbf{if}\;k\_m \leq 7.5 \cdot 10^{-10}:\\ \;\;\;\;\frac{\ell + \ell}{t \cdot \left(k\_m \cdot k\_m\right)} \cdot \frac{\ell}{k\_m \cdot k\_m}\\ \mathbf{else}:\\ \;\;\;\;\frac{\ell \cdot \cos k\_m}{k\_m} \cdot \frac{\ell + \ell}{{\sin k\_m}^{2} \cdot \left(k\_m \cdot t\right)}\\ \end{array} \end{array} \]
          k_m = (fabs.f64 k)
          (FPCore (t l k_m)
           :precision binary64
           (if (<= k_m 7.5e-10)
             (* (/ (+ l l) (* t (* k_m k_m))) (/ l (* k_m k_m)))
             (* (/ (* l (cos k_m)) k_m) (/ (+ l l) (* (pow (sin k_m) 2.0) (* k_m t))))))
          k_m = fabs(k);
          double code(double t, double l, double k_m) {
          	double tmp;
          	if (k_m <= 7.5e-10) {
          		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
          	} else {
          		tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (pow(sin(k_m), 2.0) * (k_m * t)));
          	}
          	return tmp;
          }
          
          k_m = abs(k)
          real(8) function code(t, l, k_m)
              real(8), intent (in) :: t
              real(8), intent (in) :: l
              real(8), intent (in) :: k_m
              real(8) :: tmp
              if (k_m <= 7.5d-10) then
                  tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m))
              else
                  tmp = ((l * cos(k_m)) / k_m) * ((l + l) / ((sin(k_m) ** 2.0d0) * (k_m * t)))
              end if
              code = tmp
          end function
          
          k_m = Math.abs(k);
          public static double code(double t, double l, double k_m) {
          	double tmp;
          	if (k_m <= 7.5e-10) {
          		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
          	} else {
          		tmp = ((l * Math.cos(k_m)) / k_m) * ((l + l) / (Math.pow(Math.sin(k_m), 2.0) * (k_m * t)));
          	}
          	return tmp;
          }
          
          k_m = math.fabs(k)
          def code(t, l, k_m):
          	tmp = 0
          	if k_m <= 7.5e-10:
          		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m))
          	else:
          		tmp = ((l * math.cos(k_m)) / k_m) * ((l + l) / (math.pow(math.sin(k_m), 2.0) * (k_m * t)))
          	return tmp
          
          k_m = abs(k)
          function code(t, l, k_m)
          	tmp = 0.0
          	if (k_m <= 7.5e-10)
          		tmp = Float64(Float64(Float64(l + l) / Float64(t * Float64(k_m * k_m))) * Float64(l / Float64(k_m * k_m)));
          	else
          		tmp = Float64(Float64(Float64(l * cos(k_m)) / k_m) * Float64(Float64(l + l) / Float64((sin(k_m) ^ 2.0) * Float64(k_m * t))));
          	end
          	return tmp
          end
          
          k_m = abs(k);
          function tmp_2 = code(t, l, k_m)
          	tmp = 0.0;
          	if (k_m <= 7.5e-10)
          		tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
          	else
          		tmp = ((l * cos(k_m)) / k_m) * ((l + l) / ((sin(k_m) ^ 2.0) * (k_m * t)));
          	end
          	tmp_2 = tmp;
          end
          
          k_m = N[Abs[k], $MachinePrecision]
          code[t_, l_, k$95$m_] := If[LessEqual[k$95$m, 7.5e-10], N[(N[(N[(l + l), $MachinePrecision] / N[(t * N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(l / N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(l * N[Cos[k$95$m], $MachinePrecision]), $MachinePrecision] / k$95$m), $MachinePrecision] * N[(N[(l + l), $MachinePrecision] / N[(N[Power[N[Sin[k$95$m], $MachinePrecision], 2.0], $MachinePrecision] * N[(k$95$m * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          k_m = \left|k\right|
          
          \\
          \begin{array}{l}
          \mathbf{if}\;k\_m \leq 7.5 \cdot 10^{-10}:\\
          \;\;\;\;\frac{\ell + \ell}{t \cdot \left(k\_m \cdot k\_m\right)} \cdot \frac{\ell}{k\_m \cdot k\_m}\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{\ell \cdot \cos k\_m}{k\_m} \cdot \frac{\ell + \ell}{{\sin k\_m}^{2} \cdot \left(k\_m \cdot t\right)}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if k < 7.49999999999999995e-10

            1. Initial program 40.6%

              \[\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 k around 0

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

                \[\leadsto \color{blue}{\frac{2 \cdot {\ell}^{2}}{{k}^{4} \cdot t}} \]
              2. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{2 \cdot {\ell}^{2}}{{k}^{4} \cdot t}} \]
              3. unpow2N/A

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

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

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

                \[\leadsto \frac{\color{blue}{\ell \cdot \left(2 \cdot \ell\right)}}{{k}^{4} \cdot t} \]
              7. count-2N/A

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

                \[\leadsto \frac{\ell \cdot \color{blue}{\left(\ell + \ell\right)}}{{k}^{4} \cdot t} \]
              9. *-commutativeN/A

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

                \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{\color{blue}{t \cdot {k}^{4}}} \]
              11. metadata-evalN/A

                \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{t \cdot {k}^{\color{blue}{\left(2 \cdot 2\right)}}} \]
              12. pow-sqrN/A

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

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

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

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

                \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{t \cdot \left(\left(k \cdot k\right) \cdot \color{blue}{\left(k \cdot k\right)}\right)} \]
              17. lower-*.f6473.6

                \[\leadsto \frac{\ell \cdot \left(\ell + \ell\right)}{t \cdot \left(\left(k \cdot k\right) \cdot \color{blue}{\left(k \cdot k\right)}\right)} \]
            5. Applied rewrites73.6%

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

                \[\leadsto \frac{\ell + \ell}{t \cdot \left(k \cdot k\right)} \cdot \color{blue}{\frac{\ell}{k \cdot k}} \]

              if 7.49999999999999995e-10 < k

              1. Initial program 29.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. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \frac{\ell \cdot \cos k}{k} \cdot \frac{\ell + \ell}{{\sin k}^{2} \cdot \left(\color{blue}{t} \cdot k\right)} \]
                3. Recombined 2 regimes into one program.
                4. Final simplification93.8%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 7.5 \cdot 10^{-10}:\\ \;\;\;\;\frac{\ell + \ell}{t \cdot \left(k \cdot k\right)} \cdot \frac{\ell}{k \cdot k}\\ \mathbf{else}:\\ \;\;\;\;\frac{\ell \cdot \cos k}{k} \cdot \frac{\ell + \ell}{{\sin k}^{2} \cdot \left(k \cdot t\right)}\\ \end{array} \]
                5. Add Preprocessing

                Reproduce

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