VandenBroeck and Keller, Equation (6)

Percentage Accurate: 76.1% → 98.2%
Time: 4.4s
Alternatives: 6
Speedup: 2.7×

Specification

?
\[\begin{array}{l} \\ \pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \end{array} \]
(FPCore (F l)
 :precision binary64
 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
double code(double F, double l) {
	return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
public static double code(double F, double l) {
	return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
def code(F, l):
	return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
function code(F, l)
	return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l))))
end
function tmp = code(F, l)
	tmp = (pi * l) - ((1.0 / (F * F)) * tan((pi * l)));
end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\end{array}

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 6 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: 76.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \end{array} \]
(FPCore (F l)
 :precision binary64
 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
double code(double F, double l) {
	return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
public static double code(double F, double l) {
	return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
def code(F, l):
	return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
function code(F, l)
	return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l))))
end
function tmp = code(F, l)
	tmp = (pi * l) - ((1.0 / (F * F)) * tan((pi * l)));
end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\end{array}

Alternative 1: 98.2% accurate, 0.6× speedup?

\[\begin{array}{l} l\_m = \left|\ell\right| \\ l\_s = \mathsf{copysign}\left(1, \ell\right) \\ \begin{array}{l} t_0 := \frac{{\pi}^{3}}{F}\\ l\_s \cdot \begin{array}{l} \mathbf{if}\;l\_m \leq 19000:\\ \;\;\;\;\pi \cdot l\_m - \frac{l\_m \cdot \mathsf{fma}\left(-1, {l\_m}^{2} \cdot \left(0.16666666666666666 \cdot t\_0 - 0.5 \cdot t\_0\right), \frac{\pi}{F}\right)}{F}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi - \frac{1}{\pi}, 0.5 \cdot l\_m, \mathsf{fma}\left(l\_m, \pi, \frac{l\_m}{\pi}\right) \cdot 0.5\right)\\ \end{array} \end{array} \end{array} \]
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
 :precision binary64
 (let* ((t_0 (/ (pow PI 3.0) F)))
   (*
    l_s
    (if (<= l_m 19000.0)
      (-
       (* PI l_m)
       (/
        (*
         l_m
         (fma
          -1.0
          (* (pow l_m 2.0) (- (* 0.16666666666666666 t_0) (* 0.5 t_0)))
          (/ PI F)))
        F))
      (fma (- PI (/ 1.0 PI)) (* 0.5 l_m) (* (fma l_m PI (/ l_m PI)) 0.5))))))
l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double t_0 = pow(((double) M_PI), 3.0) / F;
	double tmp;
	if (l_m <= 19000.0) {
		tmp = (((double) M_PI) * l_m) - ((l_m * fma(-1.0, (pow(l_m, 2.0) * ((0.16666666666666666 * t_0) - (0.5 * t_0))), (((double) M_PI) / F))) / F);
	} else {
		tmp = fma((((double) M_PI) - (1.0 / ((double) M_PI))), (0.5 * l_m), (fma(l_m, ((double) M_PI), (l_m / ((double) M_PI))) * 0.5));
	}
	return l_s * tmp;
}
l\_m = abs(l)
l\_s = copysign(1.0, l)
function code(l_s, F, l_m)
	t_0 = Float64((pi ^ 3.0) / F)
	tmp = 0.0
	if (l_m <= 19000.0)
		tmp = Float64(Float64(pi * l_m) - Float64(Float64(l_m * fma(-1.0, Float64((l_m ^ 2.0) * Float64(Float64(0.16666666666666666 * t_0) - Float64(0.5 * t_0))), Float64(pi / F))) / F));
	else
		tmp = fma(Float64(pi - Float64(1.0 / pi)), Float64(0.5 * l_m), Float64(fma(l_m, pi, Float64(l_m / pi)) * 0.5));
	end
	return Float64(l_s * tmp)
end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := Block[{t$95$0 = N[(N[Power[Pi, 3.0], $MachinePrecision] / F), $MachinePrecision]}, N[(l$95$s * If[LessEqual[l$95$m, 19000.0], N[(N[(Pi * l$95$m), $MachinePrecision] - N[(N[(l$95$m * N[(-1.0 * N[(N[Power[l$95$m, 2.0], $MachinePrecision] * N[(N[(0.16666666666666666 * t$95$0), $MachinePrecision] - N[(0.5 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(Pi / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], N[(N[(Pi - N[(1.0 / Pi), $MachinePrecision]), $MachinePrecision] * N[(0.5 * l$95$m), $MachinePrecision] + N[(N[(l$95$m * Pi + N[(l$95$m / Pi), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)

\\
\begin{array}{l}
t_0 := \frac{{\pi}^{3}}{F}\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 19000:\\
\;\;\;\;\pi \cdot l\_m - \frac{l\_m \cdot \mathsf{fma}\left(-1, {l\_m}^{2} \cdot \left(0.16666666666666666 \cdot t\_0 - 0.5 \cdot t\_0\right), \frac{\pi}{F}\right)}{F}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\pi - \frac{1}{\pi}, 0.5 \cdot l\_m, \mathsf{fma}\left(l\_m, \pi, \frac{l\_m}{\pi}\right) \cdot 0.5\right)\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 19000

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied rewrites82.3%

      \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{-1}{F} \cdot \tan \left(\left(-\ell\right) \cdot \pi\right)}{F}} \]
    3. Taylor expanded in l around 0

      \[\leadsto \pi \cdot \ell - \frac{\color{blue}{\ell \cdot \left(-1 \cdot \left({\ell}^{2} \cdot \left(\frac{1}{6} \cdot \frac{{\mathsf{PI}\left(\right)}^{3}}{F} - \frac{1}{2} \cdot \frac{{\mathsf{PI}\left(\right)}^{3}}{F}\right)\right) + \frac{\mathsf{PI}\left(\right)}{F}\right)}}{F} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \pi \cdot \ell - \frac{\ell \cdot \color{blue}{\left(-1 \cdot \left({\ell}^{2} \cdot \left(\frac{1}{6} \cdot \frac{{\mathsf{PI}\left(\right)}^{3}}{F} - \frac{1}{2} \cdot \frac{{\mathsf{PI}\left(\right)}^{3}}{F}\right)\right) + \frac{\mathsf{PI}\left(\right)}{F}\right)}}{F} \]
      2. lower-fma.f64N/A

        \[\leadsto \pi \cdot \ell - \frac{\ell \cdot \mathsf{fma}\left(-1, \color{blue}{{\ell}^{2} \cdot \left(\frac{1}{6} \cdot \frac{{\mathsf{PI}\left(\right)}^{3}}{F} - \frac{1}{2} \cdot \frac{{\mathsf{PI}\left(\right)}^{3}}{F}\right)}, \frac{\mathsf{PI}\left(\right)}{F}\right)}{F} \]
    5. Applied rewrites59.3%

      \[\leadsto \pi \cdot \ell - \frac{\color{blue}{\ell \cdot \mathsf{fma}\left(-1, {\ell}^{2} \cdot \left(0.16666666666666666 \cdot \frac{{\pi}^{3}}{F} - 0.5 \cdot \frac{{\pi}^{3}}{F}\right), \frac{\pi}{F}\right)}}{F} \]

    if 19000 < l

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied rewrites44.8%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\ell \cdot \pi, F, \frac{\tan \left(\ell \cdot \pi\right)}{F}\right)}{F}} \]
    3. Applied rewrites56.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot 0.5, \ell, \mathsf{fma}\left(\left(\frac{1}{\pi} + \pi\right) \cdot 0.5, \ell, \frac{\tan \left(\ell \cdot \pi\right)}{F \cdot F}\right)\right)} \]
    4. Taylor expanded in F around inf

      \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \color{blue}{\frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)\right)}\right) \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \color{blue}{\left(\ell \cdot \left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)\right)}\right) \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \color{blue}{\left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)}\right)\right) \]
      3. lower-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) + \color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right) \]
      4. lower-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi + \frac{\color{blue}{1}}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi + \frac{1}{\color{blue}{\mathsf{PI}\left(\right)}}\right)\right)\right) \]
      6. lower-PI.f6473.4

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot 0.5, \ell, 0.5 \cdot \left(\ell \cdot \left(\pi + \frac{1}{\pi}\right)\right)\right) \]
    6. Applied rewrites73.4%

      \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot 0.5, \ell, \color{blue}{0.5 \cdot \left(\ell \cdot \left(\pi + \frac{1}{\pi}\right)\right)}\right) \]
    7. Applied rewrites73.5%

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

Alternative 2: 98.1% accurate, 1.8× speedup?

\[\begin{array}{l} l\_m = \left|\ell\right| \\ l\_s = \mathsf{copysign}\left(1, \ell\right) \\ l\_s \cdot \begin{array}{l} \mathbf{if}\;l\_m \leq 19000:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot \frac{l\_m}{F}, \frac{-1}{F}, l\_m \cdot \pi\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\pi - \frac{1}{\pi}, 0.5 \cdot l\_m, \mathsf{fma}\left(l\_m, \pi, \frac{l\_m}{\pi}\right) \cdot 0.5\right)\\ \end{array} \end{array} \]
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= l_m 19000.0)
    (fma (* PI (/ l_m F)) (/ -1.0 F) (* l_m PI))
    (fma (- PI (/ 1.0 PI)) (* 0.5 l_m) (* (fma l_m PI (/ l_m PI)) 0.5)))))
l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if (l_m <= 19000.0) {
		tmp = fma((((double) M_PI) * (l_m / F)), (-1.0 / F), (l_m * ((double) M_PI)));
	} else {
		tmp = fma((((double) M_PI) - (1.0 / ((double) M_PI))), (0.5 * l_m), (fma(l_m, ((double) M_PI), (l_m / ((double) M_PI))) * 0.5));
	}
	return l_s * tmp;
}
l\_m = abs(l)
l\_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (l_m <= 19000.0)
		tmp = fma(Float64(pi * Float64(l_m / F)), Float64(-1.0 / F), Float64(l_m * pi));
	else
		tmp = fma(Float64(pi - Float64(1.0 / pi)), Float64(0.5 * l_m), Float64(fma(l_m, pi, Float64(l_m / pi)) * 0.5));
	end
	return Float64(l_s * tmp)
end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[l$95$m, 19000.0], N[(N[(Pi * N[(l$95$m / F), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / F), $MachinePrecision] + N[(l$95$m * Pi), $MachinePrecision]), $MachinePrecision], N[(N[(Pi - N[(1.0 / Pi), $MachinePrecision]), $MachinePrecision] * N[(0.5 * l$95$m), $MachinePrecision] + N[(N[(l$95$m * Pi + N[(l$95$m / Pi), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)

\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 19000:\\
\;\;\;\;\mathsf{fma}\left(\pi \cdot \frac{l\_m}{F}, \frac{-1}{F}, l\_m \cdot \pi\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\pi - \frac{1}{\pi}, 0.5 \cdot l\_m, \mathsf{fma}\left(l\_m, \pi, \frac{l\_m}{\pi}\right) \cdot 0.5\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 19000

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied rewrites82.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\tan \left(\ell \cdot \pi\right)}{F}, \frac{-1}{F}, \ell \cdot \pi\right)} \]
    3. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \mathsf{PI}\left(\right)}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      3. lower-PI.f6474.6

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    5. Applied rewrites74.6%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \pi}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\pi \cdot \ell}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      4. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      6. lower-/.f6474.6

        \[\leadsto \mathsf{fma}\left(\pi \cdot \frac{\ell}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    7. Applied rewrites74.6%

      \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]

    if 19000 < l

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied rewrites44.8%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\ell \cdot \pi, F, \frac{\tan \left(\ell \cdot \pi\right)}{F}\right)}{F}} \]
    3. Applied rewrites56.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot 0.5, \ell, \mathsf{fma}\left(\left(\frac{1}{\pi} + \pi\right) \cdot 0.5, \ell, \frac{\tan \left(\ell \cdot \pi\right)}{F \cdot F}\right)\right)} \]
    4. Taylor expanded in F around inf

      \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \color{blue}{\frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)\right)}\right) \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \color{blue}{\left(\ell \cdot \left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)\right)}\right) \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \color{blue}{\left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)}\right)\right) \]
      3. lower-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) + \color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}\right)\right)\right) \]
      4. lower-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi + \frac{\color{blue}{1}}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot \frac{1}{2}, \ell, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi + \frac{1}{\color{blue}{\mathsf{PI}\left(\right)}}\right)\right)\right) \]
      6. lower-PI.f6473.4

        \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot 0.5, \ell, 0.5 \cdot \left(\ell \cdot \left(\pi + \frac{1}{\pi}\right)\right)\right) \]
    6. Applied rewrites73.4%

      \[\leadsto \mathsf{fma}\left(\left(\pi - \frac{1}{\pi}\right) \cdot 0.5, \ell, \color{blue}{0.5 \cdot \left(\ell \cdot \left(\pi + \frac{1}{\pi}\right)\right)}\right) \]
    7. Applied rewrites73.5%

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

Alternative 3: 98.1% accurate, 1.8× speedup?

\[\begin{array}{l} l\_m = \left|\ell\right| \\ l\_s = \mathsf{copysign}\left(1, \ell\right) \\ l\_s \cdot \begin{array}{l} \mathbf{if}\;l\_m \leq 19000:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot \frac{l\_m}{F}, \frac{-1}{F}, l\_m \cdot \pi\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \mathsf{fma}\left(\pi, l\_m, \frac{l\_m}{\pi}\right), 0.5 \cdot \left(l\_m \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right)\\ \end{array} \end{array} \]
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= l_m 19000.0)
    (fma (* PI (/ l_m F)) (/ -1.0 F) (* l_m PI))
    (fma 0.5 (fma PI l_m (/ l_m PI)) (* 0.5 (* l_m (- PI (/ 1.0 PI))))))))
l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if (l_m <= 19000.0) {
		tmp = fma((((double) M_PI) * (l_m / F)), (-1.0 / F), (l_m * ((double) M_PI)));
	} else {
		tmp = fma(0.5, fma(((double) M_PI), l_m, (l_m / ((double) M_PI))), (0.5 * (l_m * (((double) M_PI) - (1.0 / ((double) M_PI))))));
	}
	return l_s * tmp;
}
l\_m = abs(l)
l\_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (l_m <= 19000.0)
		tmp = fma(Float64(pi * Float64(l_m / F)), Float64(-1.0 / F), Float64(l_m * pi));
	else
		tmp = fma(0.5, fma(pi, l_m, Float64(l_m / pi)), Float64(0.5 * Float64(l_m * Float64(pi - Float64(1.0 / pi)))));
	end
	return Float64(l_s * tmp)
end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[l$95$m, 19000.0], N[(N[(Pi * N[(l$95$m / F), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / F), $MachinePrecision] + N[(l$95$m * Pi), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(Pi * l$95$m + N[(l$95$m / Pi), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(l$95$m * N[(Pi - N[(1.0 / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)

\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 19000:\\
\;\;\;\;\mathsf{fma}\left(\pi \cdot \frac{l\_m}{F}, \frac{-1}{F}, l\_m \cdot \pi\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \mathsf{fma}\left(\pi, l\_m, \frac{l\_m}{\pi}\right), 0.5 \cdot \left(l\_m \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 19000

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied rewrites82.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\tan \left(\ell \cdot \pi\right)}{F}, \frac{-1}{F}, \ell \cdot \pi\right)} \]
    3. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \mathsf{PI}\left(\right)}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      3. lower-PI.f6474.6

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    5. Applied rewrites74.6%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \pi}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\pi \cdot \ell}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      4. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      6. lower-/.f6474.6

        \[\leadsto \mathsf{fma}\left(\pi \cdot \frac{\ell}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    7. Applied rewrites74.6%

      \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]

    if 19000 < l

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\pi \cdot \ell} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\ell \cdot \pi} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      3. lift-PI.f64N/A

        \[\leadsto \ell \cdot \color{blue}{\mathsf{PI}\left(\right)} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      4. add-exp-logN/A

        \[\leadsto \ell \cdot \color{blue}{e^{\log \mathsf{PI}\left(\right)}} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      5. sinh-+-cosh-revN/A

        \[\leadsto \ell \cdot \color{blue}{\left(\cosh \log \mathsf{PI}\left(\right) + \sinh \log \mathsf{PI}\left(\right)\right)} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      6. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\left(\cosh \log \mathsf{PI}\left(\right) \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right)} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      7. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(\cosh \log \mathsf{PI}\left(\right) \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right)} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      8. lower-*.f64N/A

        \[\leadsto \left(\color{blue}{\cosh \log \mathsf{PI}\left(\right) \cdot \ell} + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      9. lower-cosh.f64N/A

        \[\leadsto \left(\color{blue}{\cosh \log \mathsf{PI}\left(\right)} \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      10. lift-PI.f64N/A

        \[\leadsto \left(\cosh \log \color{blue}{\pi} \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      11. lower-log.f64N/A

        \[\leadsto \left(\cosh \color{blue}{\log \pi} \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      12. lower-*.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \color{blue}{\sinh \log \mathsf{PI}\left(\right) \cdot \ell}\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      13. lower-sinh.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \color{blue}{\sinh \log \mathsf{PI}\left(\right)} \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      14. lift-PI.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \color{blue}{\pi} \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
      15. lower-log.f6476.0

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \color{blue}{\log \pi} \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    3. Applied rewrites76.0%

      \[\leadsto \color{blue}{\left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right)} - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    4. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \color{blue}{\left(\pi \cdot \ell\right)} \]
      2. *-commutativeN/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \color{blue}{\left(\ell \cdot \pi\right)} \]
      3. lift-PI.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\ell \cdot \color{blue}{\mathsf{PI}\left(\right)}\right) \]
      4. add-exp-logN/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\ell \cdot \color{blue}{e^{\log \mathsf{PI}\left(\right)}}\right) \]
      5. sinh-+-cosh-revN/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\ell \cdot \color{blue}{\left(\cosh \log \mathsf{PI}\left(\right) + \sinh \log \mathsf{PI}\left(\right)\right)}\right) \]
      6. distribute-rgt-inN/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \color{blue}{\left(\cosh \log \mathsf{PI}\left(\right) \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right)} \]
      7. lower-+.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \color{blue}{\left(\cosh \log \mathsf{PI}\left(\right) \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right)} \]
      8. lower-*.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\color{blue}{\cosh \log \mathsf{PI}\left(\right) \cdot \ell} + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) \]
      9. lower-cosh.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\color{blue}{\cosh \log \mathsf{PI}\left(\right)} \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) \]
      10. lift-PI.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\cosh \log \color{blue}{\pi} \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) \]
      11. lower-log.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\cosh \color{blue}{\log \pi} \cdot \ell + \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right) \]
      12. lower-*.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\cosh \log \pi \cdot \ell + \color{blue}{\sinh \log \mathsf{PI}\left(\right) \cdot \ell}\right) \]
      13. lower-sinh.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\cosh \log \pi \cdot \ell + \color{blue}{\sinh \log \mathsf{PI}\left(\right)} \cdot \ell\right) \]
      14. lift-PI.f64N/A

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\cosh \log \pi \cdot \ell + \sinh \log \color{blue}{\pi} \cdot \ell\right) \]
      15. lower-log.f6476.0

        \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \left(\cosh \log \pi \cdot \ell + \sinh \color{blue}{\log \pi} \cdot \ell\right) \]
    5. Applied rewrites76.0%

      \[\leadsto \left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right) - \frac{1}{F \cdot F} \cdot \tan \color{blue}{\left(\cosh \log \pi \cdot \ell + \sinh \log \pi \cdot \ell\right)} \]
    6. Taylor expanded in F around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)\right) + \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)} \]
    7. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{\ell \cdot \left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)}, \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \color{blue}{\left(\mathsf{PI}\left(\right) + \frac{1}{\mathsf{PI}\left(\right)}\right)}, \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      3. lower-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\mathsf{PI}\left(\right) + \color{blue}{\frac{1}{\mathsf{PI}\left(\right)}}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      4. lower-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{\color{blue}{1}}{\mathsf{PI}\left(\right)}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{1}{\color{blue}{\mathsf{PI}\left(\right)}}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      6. lower-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{1}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{1}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      8. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{1}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      9. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{1}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\mathsf{PI}\left(\right) - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      10. lower-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{1}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \frac{1}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
      12. lower-PI.f6473.3

        \[\leadsto \mathsf{fma}\left(0.5, \ell \cdot \left(\pi + \frac{1}{\pi}\right), 0.5 \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
    8. Applied rewrites73.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, \ell \cdot \left(\pi + \frac{1}{\pi}\right), 0.5 \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right)} \]
    9. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \color{blue}{\left(\pi + \frac{1}{\pi}\right)}, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      2. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \left(\pi + \color{blue}{\frac{1}{\pi}}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      3. distribute-lft-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \ell \cdot \pi + \color{blue}{\ell \cdot \frac{1}{\pi}}, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \pi \cdot \ell + \color{blue}{\ell} \cdot \frac{1}{\pi}, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      5. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \pi \cdot \ell + \ell \cdot \frac{1}{\color{blue}{\pi}}, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      6. lift-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \pi \cdot \ell + \ell \cdot \frac{1}{\mathsf{PI}\left(\right)}, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      7. add-exp-logN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \pi \cdot \ell + \ell \cdot \frac{1}{e^{\log \mathsf{PI}\left(\right)}}, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      8. rec-expN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \pi \cdot \ell + \ell \cdot e^{\mathsf{neg}\left(\log \mathsf{PI}\left(\right)\right)}, \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      9. sinh---cosh-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \pi \cdot \ell + \ell \cdot \left(\cosh \log \mathsf{PI}\left(\right) - \color{blue}{\sinh \log \mathsf{PI}\left(\right)}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      10. distribute-rgt-out--N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \pi \cdot \ell + \left(\cosh \log \mathsf{PI}\left(\right) \cdot \ell - \color{blue}{\sinh \log \mathsf{PI}\left(\right) \cdot \ell}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      11. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \mathsf{fma}\left(\pi, \color{blue}{\ell}, \cosh \log \mathsf{PI}\left(\right) \cdot \ell - \sinh \log \mathsf{PI}\left(\right) \cdot \ell\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      12. distribute-rgt-out--N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \mathsf{fma}\left(\pi, \ell, \ell \cdot \left(\cosh \log \mathsf{PI}\left(\right) - \sinh \log \mathsf{PI}\left(\right)\right)\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      13. sinh---cosh-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \mathsf{fma}\left(\pi, \ell, \ell \cdot e^{\mathsf{neg}\left(\log \mathsf{PI}\left(\right)\right)}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      14. rec-expN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \mathsf{fma}\left(\pi, \ell, \ell \cdot \frac{1}{e^{\log \mathsf{PI}\left(\right)}}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      15. add-exp-logN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \mathsf{fma}\left(\pi, \ell, \ell \cdot \frac{1}{\mathsf{PI}\left(\right)}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      16. lift-PI.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \mathsf{fma}\left(\pi, \ell, \ell \cdot \frac{1}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      17. mult-flip-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \mathsf{fma}\left(\pi, \ell, \frac{\ell}{\pi}\right), \frac{1}{2} \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
      18. lower-/.f6473.4

        \[\leadsto \mathsf{fma}\left(0.5, \mathsf{fma}\left(\pi, \ell, \frac{\ell}{\pi}\right), 0.5 \cdot \left(\ell \cdot \left(\pi - \frac{1}{\pi}\right)\right)\right) \]
    10. Applied rewrites73.4%

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

Alternative 4: 98.1% accurate, 2.4× speedup?

\[\begin{array}{l} l\_m = \left|\ell\right| \\ l\_s = \mathsf{copysign}\left(1, \ell\right) \\ l\_s \cdot \begin{array}{l} \mathbf{if}\;l\_m \leq 19000:\\ \;\;\;\;\mathsf{fma}\left(\pi \cdot \frac{l\_m}{F}, \frac{-1}{F}, l\_m \cdot \pi\right)\\ \mathbf{else}:\\ \;\;\;\;l\_m \cdot \pi\\ \end{array} \end{array} \]
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= l_m 19000.0)
    (fma (* PI (/ l_m F)) (/ -1.0 F) (* l_m PI))
    (* l_m PI))))
l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if (l_m <= 19000.0) {
		tmp = fma((((double) M_PI) * (l_m / F)), (-1.0 / F), (l_m * ((double) M_PI)));
	} else {
		tmp = l_m * ((double) M_PI);
	}
	return l_s * tmp;
}
l\_m = abs(l)
l\_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (l_m <= 19000.0)
		tmp = fma(Float64(pi * Float64(l_m / F)), Float64(-1.0 / F), Float64(l_m * pi));
	else
		tmp = Float64(l_m * pi);
	end
	return Float64(l_s * tmp)
end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[l$95$m, 19000.0], N[(N[(Pi * N[(l$95$m / F), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / F), $MachinePrecision] + N[(l$95$m * Pi), $MachinePrecision]), $MachinePrecision], N[(l$95$m * Pi), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)

\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 19000:\\
\;\;\;\;\mathsf{fma}\left(\pi \cdot \frac{l\_m}{F}, \frac{-1}{F}, l\_m \cdot \pi\right)\\

\mathbf{else}:\\
\;\;\;\;l\_m \cdot \pi\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 19000

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied rewrites82.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\tan \left(\ell \cdot \pi\right)}{F}, \frac{-1}{F}, \ell \cdot \pi\right)} \]
    3. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \mathsf{PI}\left(\right)}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      3. lower-PI.f6474.6

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    5. Applied rewrites74.6%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \pi}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\ell \cdot \pi}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\pi \cdot \ell}{F}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      4. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
      6. lower-/.f6474.6

        \[\leadsto \mathsf{fma}\left(\pi \cdot \frac{\ell}{\color{blue}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    7. Applied rewrites74.6%

      \[\leadsto \mathsf{fma}\left(\pi \cdot \color{blue}{\frac{\ell}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]

    if 19000 < l

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Taylor expanded in F around inf

      \[\leadsto \color{blue}{\ell \cdot \mathsf{PI}\left(\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \ell \cdot \color{blue}{\mathsf{PI}\left(\right)} \]
      2. lower-PI.f6473.4

        \[\leadsto \ell \cdot \pi \]
    4. Applied rewrites73.4%

      \[\leadsto \color{blue}{\ell \cdot \pi} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 98.1% accurate, 2.7× speedup?

\[\begin{array}{l} l\_m = \left|\ell\right| \\ l\_s = \mathsf{copysign}\left(1, \ell\right) \\ l\_s \cdot \begin{array}{l} \mathbf{if}\;l\_m \leq 19000:\\ \;\;\;\;\pi \cdot l\_m - \frac{\frac{l\_m \cdot \pi}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;l\_m \cdot \pi\\ \end{array} \end{array} \]
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= l_m 19000.0) (- (* PI l_m) (/ (/ (* l_m PI) F) F)) (* l_m PI))))
l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if (l_m <= 19000.0) {
		tmp = (((double) M_PI) * l_m) - (((l_m * ((double) M_PI)) / F) / F);
	} else {
		tmp = l_m * ((double) M_PI);
	}
	return l_s * tmp;
}
l\_m = Math.abs(l);
l\_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double tmp;
	if (l_m <= 19000.0) {
		tmp = (Math.PI * l_m) - (((l_m * Math.PI) / F) / F);
	} else {
		tmp = l_m * Math.PI;
	}
	return l_s * tmp;
}
l\_m = math.fabs(l)
l\_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	tmp = 0
	if l_m <= 19000.0:
		tmp = (math.pi * l_m) - (((l_m * math.pi) / F) / F)
	else:
		tmp = l_m * math.pi
	return l_s * tmp
l\_m = abs(l)
l\_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (l_m <= 19000.0)
		tmp = Float64(Float64(pi * l_m) - Float64(Float64(Float64(l_m * pi) / F) / F));
	else
		tmp = Float64(l_m * pi);
	end
	return Float64(l_s * tmp)
end
l\_m = abs(l);
l\_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	tmp = 0.0;
	if (l_m <= 19000.0)
		tmp = (pi * l_m) - (((l_m * pi) / F) / F);
	else
		tmp = l_m * pi;
	end
	tmp_2 = l_s * tmp;
end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[l$95$m, 19000.0], N[(N[(Pi * l$95$m), $MachinePrecision] - N[(N[(N[(l$95$m * Pi), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], N[(l$95$m * Pi), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)

\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 19000:\\
\;\;\;\;\pi \cdot l\_m - \frac{\frac{l\_m \cdot \pi}{F}}{F}\\

\mathbf{else}:\\
\;\;\;\;l\_m \cdot \pi\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 19000

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied rewrites82.3%

      \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{-1}{F} \cdot \tan \left(\left(-\ell\right) \cdot \pi\right)}{F}} \]
    3. Taylor expanded in l around 0

      \[\leadsto \pi \cdot \ell - \frac{\color{blue}{\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}}}{F} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \pi \cdot \ell - \frac{\frac{\ell \cdot \mathsf{PI}\left(\right)}{\color{blue}{F}}}{F} \]
      2. lower-*.f64N/A

        \[\leadsto \pi \cdot \ell - \frac{\frac{\ell \cdot \mathsf{PI}\left(\right)}{F}}{F} \]
      3. lower-PI.f6474.6

        \[\leadsto \pi \cdot \ell - \frac{\frac{\ell \cdot \pi}{F}}{F} \]
    5. Applied rewrites74.6%

      \[\leadsto \pi \cdot \ell - \frac{\color{blue}{\frac{\ell \cdot \pi}{F}}}{F} \]

    if 19000 < l

    1. Initial program 76.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Taylor expanded in F around inf

      \[\leadsto \color{blue}{\ell \cdot \mathsf{PI}\left(\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \ell \cdot \color{blue}{\mathsf{PI}\left(\right)} \]
      2. lower-PI.f6473.4

        \[\leadsto \ell \cdot \pi \]
    4. Applied rewrites73.4%

      \[\leadsto \color{blue}{\ell \cdot \pi} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 73.4% accurate, 13.6× speedup?

\[\begin{array}{l} l\_m = \left|\ell\right| \\ l\_s = \mathsf{copysign}\left(1, \ell\right) \\ l\_s \cdot \left(l\_m \cdot \pi\right) \end{array} \]
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m) :precision binary64 (* l_s (* l_m PI)))
l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	return l_s * (l_m * ((double) M_PI));
}
l\_m = Math.abs(l);
l\_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	return l_s * (l_m * Math.PI);
}
l\_m = math.fabs(l)
l\_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	return l_s * (l_m * math.pi)
l\_m = abs(l)
l\_s = copysign(1.0, l)
function code(l_s, F, l_m)
	return Float64(l_s * Float64(l_m * pi))
end
l\_m = abs(l);
l\_s = sign(l) * abs(1.0);
function tmp = code(l_s, F, l_m)
	tmp = l_s * (l_m * pi);
end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * N[(l$95$m * Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)

\\
l\_s \cdot \left(l\_m \cdot \pi\right)
\end{array}
Derivation
  1. Initial program 76.1%

    \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
  2. Taylor expanded in F around inf

    \[\leadsto \color{blue}{\ell \cdot \mathsf{PI}\left(\right)} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \ell \cdot \color{blue}{\mathsf{PI}\left(\right)} \]
    2. lower-PI.f6473.4

      \[\leadsto \ell \cdot \pi \]
  4. Applied rewrites73.4%

    \[\leadsto \color{blue}{\ell \cdot \pi} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2025148 
(FPCore (F l)
  :name "VandenBroeck and Keller, Equation (6)"
  :precision binary64
  (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))