VandenBroeck and Keller, Equation (6)

Percentage Accurate: 76.5% → 99.2%
Time: 3.5s
Alternatives: 7
Speedup: 1.8×

Specification

?
\[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
(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]
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)

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 7 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.5% accurate, 1.0× speedup?

\[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
(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]
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)

Alternative 1: 99.2% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \left|\ell\right| \cdot \pi\\ \mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l} \mathbf{if}\;\left|\ell\right| \leq 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(\pi, \left|\ell\right|, \frac{\pi \cdot \frac{\left|\ell\right|}{F}}{-F}\right)\\ \mathbf{elif}\;\left|\ell\right| \leq 9200000000000:\\ \;\;\;\;\pi \cdot \left|\ell\right| - \frac{\tan t\_0}{F \cdot F}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (F l)
 :precision binary64
 (let* ((t_0 (* (fabs l) PI)))
   (*
    (copysign 1.0 l)
    (if (<= (fabs l) 1e-9)
      (fma PI (fabs l) (/ (* PI (/ (fabs l) F)) (- F)))
      (if (<= (fabs l) 9200000000000.0)
        (- (* PI (fabs l)) (/ (tan t_0) (* F F)))
        t_0)))))
double code(double F, double l) {
	double t_0 = fabs(l) * ((double) M_PI);
	double tmp;
	if (fabs(l) <= 1e-9) {
		tmp = fma(((double) M_PI), fabs(l), ((((double) M_PI) * (fabs(l) / F)) / -F));
	} else if (fabs(l) <= 9200000000000.0) {
		tmp = (((double) M_PI) * fabs(l)) - (tan(t_0) / (F * F));
	} else {
		tmp = t_0;
	}
	return copysign(1.0, l) * tmp;
}
function code(F, l)
	t_0 = Float64(abs(l) * pi)
	tmp = 0.0
	if (abs(l) <= 1e-9)
		tmp = fma(pi, abs(l), Float64(Float64(pi * Float64(abs(l) / F)) / Float64(-F)));
	elseif (abs(l) <= 9200000000000.0)
		tmp = Float64(Float64(pi * abs(l)) - Float64(tan(t_0) / Float64(F * F)));
	else
		tmp = t_0;
	end
	return Float64(copysign(1.0, l) * tmp)
end
code[F_, l_] := Block[{t$95$0 = N[(N[Abs[l], $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[l], $MachinePrecision], 1e-9], N[(Pi * N[Abs[l], $MachinePrecision] + N[(N[(Pi * N[(N[Abs[l], $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision] / (-F)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[l], $MachinePrecision], 9200000000000.0], N[(N[(Pi * N[Abs[l], $MachinePrecision]), $MachinePrecision] - N[(N[Tan[t$95$0], $MachinePrecision] / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|\ell\right| \cdot \pi\\
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|\ell\right| \leq 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(\pi, \left|\ell\right|, \frac{\pi \cdot \frac{\left|\ell\right|}{F}}{-F}\right)\\

\mathbf{elif}\;\left|\ell\right| \leq 9200000000000:\\
\;\;\;\;\pi \cdot \left|\ell\right| - \frac{\tan t\_0}{F \cdot F}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 1.0000000000000001e-9

    1. Initial program 76.5%

      \[\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. lift-*.f64N/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)} \]
      3. fp-cancel-sub-sign-invN/A

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{1}{F \cdot F}}\right)\right) \cdot \tan \left(\pi \cdot \ell\right) + \pi \cdot \ell \]
      6. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{1}{\mathsf{neg}\left(F \cdot F\right)}} \cdot \tan \left(\pi \cdot \ell\right) + \pi \cdot \ell \]
      7. associate-*l/N/A

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

        \[\leadsto \frac{\color{blue}{\tan \left(\pi \cdot \ell\right) \cdot 1}}{\mathsf{neg}\left(F \cdot F\right)} + \pi \cdot \ell \]
      9. lift-*.f64N/A

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

        \[\leadsto \frac{\tan \left(\pi \cdot \ell\right) \cdot 1}{\color{blue}{F \cdot \left(\mathsf{neg}\left(F\right)\right)}} + \pi \cdot \ell \]
      11. times-fracN/A

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \pi}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    5. 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.f6475.2%

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

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

        \[\leadsto \color{blue}{\frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} + \ell \cdot \pi} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\ell \cdot \pi + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F}} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\ell \cdot \pi} + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\pi \cdot \ell} + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} \]
      5. lower-fma.f64N/A

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

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

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\ell \cdot \pi}{F} \cdot \color{blue}{\frac{\mathsf{neg}\left(-1\right)}{\mathsf{neg}\left(F\right)}}\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\ell \cdot \pi}{F} \cdot \frac{\color{blue}{1}}{\mathsf{neg}\left(F\right)}\right) \]
      9. mult-flip-revN/A

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

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \color{blue}{\frac{\frac{\ell \cdot \pi}{F}}{\mathsf{neg}\left(F\right)}}\right) \]
      11. lower-neg.f6475.2%

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\frac{\ell \cdot \pi}{F}}{\color{blue}{-F}}\right) \]
    8. Applied rewrites75.2%

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-9 < l < 9.2e12

    1. Initial program 76.5%

      \[\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 \pi \cdot \ell - \color{blue}{\frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)} \]
      2. *-commutativeN/A

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

        \[\leadsto \pi \cdot \ell - \tan \left(\pi \cdot \ell\right) \cdot \color{blue}{\frac{1}{F \cdot F}} \]
      4. mult-flip-revN/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\tan \left(\pi \cdot \ell\right)}{F \cdot F}} \]
      5. lower-/.f6476.9%

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

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

        \[\leadsto \pi \cdot \ell - \frac{\tan \color{blue}{\left(\ell \cdot \pi\right)}}{F \cdot F} \]
      8. lower-*.f6476.9%

        \[\leadsto \pi \cdot \ell - \frac{\tan \color{blue}{\left(\ell \cdot \pi\right)}}{F \cdot F} \]
    3. Applied rewrites76.9%

      \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\tan \left(\ell \cdot \pi\right)}{F \cdot F}} \]

    if 9.2e12 < l

    1. Initial program 76.5%

      \[\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 \pi} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

Alternative 2: 99.2% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \left|\ell\right| \cdot \pi\\ \mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l} \mathbf{if}\;\left|\ell\right| \leq 9200000000000:\\ \;\;\;\;\pi \cdot \left|\ell\right| - \frac{1}{\frac{F}{\frac{\tan t\_0}{F}}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (F l)
 :precision binary64
 (let* ((t_0 (* (fabs l) PI)))
   (*
    (copysign 1.0 l)
    (if (<= (fabs l) 9200000000000.0)
      (- (* PI (fabs l)) (/ 1.0 (/ F (/ (tan t_0) F))))
      t_0))))
double code(double F, double l) {
	double t_0 = fabs(l) * ((double) M_PI);
	double tmp;
	if (fabs(l) <= 9200000000000.0) {
		tmp = (((double) M_PI) * fabs(l)) - (1.0 / (F / (tan(t_0) / F)));
	} else {
		tmp = t_0;
	}
	return copysign(1.0, l) * tmp;
}
public static double code(double F, double l) {
	double t_0 = Math.abs(l) * Math.PI;
	double tmp;
	if (Math.abs(l) <= 9200000000000.0) {
		tmp = (Math.PI * Math.abs(l)) - (1.0 / (F / (Math.tan(t_0) / F)));
	} else {
		tmp = t_0;
	}
	return Math.copySign(1.0, l) * tmp;
}
def code(F, l):
	t_0 = math.fabs(l) * math.pi
	tmp = 0
	if math.fabs(l) <= 9200000000000.0:
		tmp = (math.pi * math.fabs(l)) - (1.0 / (F / (math.tan(t_0) / F)))
	else:
		tmp = t_0
	return math.copysign(1.0, l) * tmp
function code(F, l)
	t_0 = Float64(abs(l) * pi)
	tmp = 0.0
	if (abs(l) <= 9200000000000.0)
		tmp = Float64(Float64(pi * abs(l)) - Float64(1.0 / Float64(F / Float64(tan(t_0) / F))));
	else
		tmp = t_0;
	end
	return Float64(copysign(1.0, l) * tmp)
end
function tmp_2 = code(F, l)
	t_0 = abs(l) * pi;
	tmp = 0.0;
	if (abs(l) <= 9200000000000.0)
		tmp = (pi * abs(l)) - (1.0 / (F / (tan(t_0) / F)));
	else
		tmp = t_0;
	end
	tmp_2 = (sign(l) * abs(1.0)) * tmp;
end
code[F_, l_] := Block[{t$95$0 = N[(N[Abs[l], $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[l], $MachinePrecision], 9200000000000.0], N[(N[(Pi * N[Abs[l], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(F / N[(N[Tan[t$95$0], $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|\ell\right| \cdot \pi\\
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|\ell\right| \leq 9200000000000:\\
\;\;\;\;\pi \cdot \left|\ell\right| - \frac{1}{\frac{F}{\frac{\tan t\_0}{F}}}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 76.5%

      \[\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 \pi \cdot \ell - \color{blue}{\frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)} \]
      2. *-commutativeN/A

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

        \[\leadsto \pi \cdot \ell - \tan \left(\pi \cdot \ell\right) \cdot \color{blue}{\frac{1}{F \cdot F}} \]
      4. mult-flip-revN/A

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

        \[\leadsto \pi \cdot \ell - \frac{\tan \left(\pi \cdot \ell\right)}{\color{blue}{F \cdot F}} \]
      6. associate-/r*N/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}} \]
      7. div-flipN/A

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

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

        \[\leadsto \pi \cdot \ell - \frac{1}{\color{blue}{\frac{F}{\frac{\tan \left(\pi \cdot \ell\right)}{F}}}} \]
      10. lower-/.f6482.6%

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

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

        \[\leadsto \pi \cdot \ell - \frac{1}{\frac{F}{\frac{\tan \color{blue}{\left(\ell \cdot \pi\right)}}{F}}} \]
      13. lower-*.f6482.6%

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

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

    if 9.2e12 < l

    1. Initial program 76.5%

      \[\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 \pi} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

Alternative 3: 99.2% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \left|\ell\right| \cdot \pi\\ \mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l} \mathbf{if}\;\left|\ell\right| \leq 9200000000000:\\ \;\;\;\;\pi \cdot \left|\ell\right| - \frac{1}{\frac{F}{\tan t\_0} \cdot F}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (F l)
 :precision binary64
 (let* ((t_0 (* (fabs l) PI)))
   (*
    (copysign 1.0 l)
    (if (<= (fabs l) 9200000000000.0)
      (- (* PI (fabs l)) (/ 1.0 (* (/ F (tan t_0)) F)))
      t_0))))
double code(double F, double l) {
	double t_0 = fabs(l) * ((double) M_PI);
	double tmp;
	if (fabs(l) <= 9200000000000.0) {
		tmp = (((double) M_PI) * fabs(l)) - (1.0 / ((F / tan(t_0)) * F));
	} else {
		tmp = t_0;
	}
	return copysign(1.0, l) * tmp;
}
public static double code(double F, double l) {
	double t_0 = Math.abs(l) * Math.PI;
	double tmp;
	if (Math.abs(l) <= 9200000000000.0) {
		tmp = (Math.PI * Math.abs(l)) - (1.0 / ((F / Math.tan(t_0)) * F));
	} else {
		tmp = t_0;
	}
	return Math.copySign(1.0, l) * tmp;
}
def code(F, l):
	t_0 = math.fabs(l) * math.pi
	tmp = 0
	if math.fabs(l) <= 9200000000000.0:
		tmp = (math.pi * math.fabs(l)) - (1.0 / ((F / math.tan(t_0)) * F))
	else:
		tmp = t_0
	return math.copysign(1.0, l) * tmp
function code(F, l)
	t_0 = Float64(abs(l) * pi)
	tmp = 0.0
	if (abs(l) <= 9200000000000.0)
		tmp = Float64(Float64(pi * abs(l)) - Float64(1.0 / Float64(Float64(F / tan(t_0)) * F)));
	else
		tmp = t_0;
	end
	return Float64(copysign(1.0, l) * tmp)
end
function tmp_2 = code(F, l)
	t_0 = abs(l) * pi;
	tmp = 0.0;
	if (abs(l) <= 9200000000000.0)
		tmp = (pi * abs(l)) - (1.0 / ((F / tan(t_0)) * F));
	else
		tmp = t_0;
	end
	tmp_2 = (sign(l) * abs(1.0)) * tmp;
end
code[F_, l_] := Block[{t$95$0 = N[(N[Abs[l], $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[l], $MachinePrecision], 9200000000000.0], N[(N[(Pi * N[Abs[l], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(N[(F / N[Tan[t$95$0], $MachinePrecision]), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|\ell\right| \cdot \pi\\
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|\ell\right| \leq 9200000000000:\\
\;\;\;\;\pi \cdot \left|\ell\right| - \frac{1}{\frac{F}{\tan t\_0} \cdot F}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 76.5%

      \[\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 \pi \cdot \ell - \color{blue}{\frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)} \]
      2. *-commutativeN/A

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

        \[\leadsto \pi \cdot \ell - \tan \left(\pi \cdot \ell\right) \cdot \color{blue}{\frac{1}{F \cdot F}} \]
      4. mult-flip-revN/A

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

        \[\leadsto \pi \cdot \ell - \frac{\tan \left(\pi \cdot \ell\right)}{\color{blue}{F \cdot F}} \]
      6. associate-/r*N/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}} \]
      7. div-flipN/A

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

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

        \[\leadsto \pi \cdot \ell - \frac{1}{\color{blue}{\frac{F}{\frac{\tan \left(\pi \cdot \ell\right)}{F}}}} \]
      10. lower-/.f6482.6%

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

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

        \[\leadsto \pi \cdot \ell - \frac{1}{\frac{F}{\frac{\tan \color{blue}{\left(\ell \cdot \pi\right)}}{F}}} \]
      13. lower-*.f6482.6%

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

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

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

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

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

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

        \[\leadsto \pi \cdot \ell - \frac{1}{\frac{1}{\color{blue}{\frac{\tan \left(\ell \cdot \pi\right)}{F}}} \cdot F} \]
      6. div-flip-revN/A

        \[\leadsto \pi \cdot \ell - \frac{1}{\color{blue}{\frac{F}{\tan \left(\ell \cdot \pi\right)}} \cdot F} \]
      7. lower-/.f6482.6%

        \[\leadsto \pi \cdot \ell - \frac{1}{\color{blue}{\frac{F}{\tan \left(\ell \cdot \pi\right)}} \cdot F} \]
    5. Applied rewrites82.6%

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

    if 9.2e12 < l

    1. Initial program 76.5%

      \[\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 \pi} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

Alternative 4: 99.2% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \left|\ell\right| \cdot \pi\\ \mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l} \mathbf{if}\;\left|\ell\right| \leq 9200000000000:\\ \;\;\;\;\pi \cdot \left|\ell\right| - \frac{\frac{\tan t\_0}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (F l)
 :precision binary64
 (let* ((t_0 (* (fabs l) PI)))
   (*
    (copysign 1.0 l)
    (if (<= (fabs l) 9200000000000.0)
      (- (* PI (fabs l)) (/ (/ (tan t_0) F) F))
      t_0))))
double code(double F, double l) {
	double t_0 = fabs(l) * ((double) M_PI);
	double tmp;
	if (fabs(l) <= 9200000000000.0) {
		tmp = (((double) M_PI) * fabs(l)) - ((tan(t_0) / F) / F);
	} else {
		tmp = t_0;
	}
	return copysign(1.0, l) * tmp;
}
public static double code(double F, double l) {
	double t_0 = Math.abs(l) * Math.PI;
	double tmp;
	if (Math.abs(l) <= 9200000000000.0) {
		tmp = (Math.PI * Math.abs(l)) - ((Math.tan(t_0) / F) / F);
	} else {
		tmp = t_0;
	}
	return Math.copySign(1.0, l) * tmp;
}
def code(F, l):
	t_0 = math.fabs(l) * math.pi
	tmp = 0
	if math.fabs(l) <= 9200000000000.0:
		tmp = (math.pi * math.fabs(l)) - ((math.tan(t_0) / F) / F)
	else:
		tmp = t_0
	return math.copysign(1.0, l) * tmp
function code(F, l)
	t_0 = Float64(abs(l) * pi)
	tmp = 0.0
	if (abs(l) <= 9200000000000.0)
		tmp = Float64(Float64(pi * abs(l)) - Float64(Float64(tan(t_0) / F) / F));
	else
		tmp = t_0;
	end
	return Float64(copysign(1.0, l) * tmp)
end
function tmp_2 = code(F, l)
	t_0 = abs(l) * pi;
	tmp = 0.0;
	if (abs(l) <= 9200000000000.0)
		tmp = (pi * abs(l)) - ((tan(t_0) / F) / F);
	else
		tmp = t_0;
	end
	tmp_2 = (sign(l) * abs(1.0)) * tmp;
end
code[F_, l_] := Block[{t$95$0 = N[(N[Abs[l], $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[l], $MachinePrecision], 9200000000000.0], N[(N[(Pi * N[Abs[l], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Tan[t$95$0], $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|\ell\right| \cdot \pi\\
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|\ell\right| \leq 9200000000000:\\
\;\;\;\;\pi \cdot \left|\ell\right| - \frac{\frac{\tan t\_0}{F}}{F}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 76.5%

      \[\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 \pi \cdot \ell - \color{blue}{\frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)} \]
      2. *-commutativeN/A

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

        \[\leadsto \pi \cdot \ell - \tan \left(\pi \cdot \ell\right) \cdot \color{blue}{\frac{1}{F \cdot F}} \]
      4. mult-flip-revN/A

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

        \[\leadsto \pi \cdot \ell - \frac{\tan \left(\pi \cdot \ell\right)}{\color{blue}{F \cdot F}} \]
      6. associate-/r*N/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}} \]
      7. lower-/.f64N/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}} \]
      8. lower-/.f6482.7%

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

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

        \[\leadsto \pi \cdot \ell - \frac{\frac{\tan \color{blue}{\left(\ell \cdot \pi\right)}}{F}}{F} \]
      11. lower-*.f6482.7%

        \[\leadsto \pi \cdot \ell - \frac{\frac{\tan \color{blue}{\left(\ell \cdot \pi\right)}}{F}}{F} \]
    3. Applied rewrites82.7%

      \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{\tan \left(\ell \cdot \pi\right)}{F}}{F}} \]

    if 9.2e12 < l

    1. Initial program 76.5%

      \[\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 \pi} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

Alternative 5: 98.4% accurate, 1.8× speedup?

\[\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l} \mathbf{if}\;\left|\ell\right| \leq 235000000000:\\ \;\;\;\;\mathsf{fma}\left(\pi, \left|\ell\right|, \frac{\pi \cdot \frac{\left|\ell\right|}{F}}{-F}\right)\\ \mathbf{else}:\\ \;\;\;\;\left|\ell\right| \cdot \pi\\ \end{array} \]
(FPCore (F l)
 :precision binary64
 (*
  (copysign 1.0 l)
  (if (<= (fabs l) 235000000000.0)
    (fma PI (fabs l) (/ (* PI (/ (fabs l) F)) (- F)))
    (* (fabs l) PI))))
double code(double F, double l) {
	double tmp;
	if (fabs(l) <= 235000000000.0) {
		tmp = fma(((double) M_PI), fabs(l), ((((double) M_PI) * (fabs(l) / F)) / -F));
	} else {
		tmp = fabs(l) * ((double) M_PI);
	}
	return copysign(1.0, l) * tmp;
}
function code(F, l)
	tmp = 0.0
	if (abs(l) <= 235000000000.0)
		tmp = fma(pi, abs(l), Float64(Float64(pi * Float64(abs(l) / F)) / Float64(-F)));
	else
		tmp = Float64(abs(l) * pi);
	end
	return Float64(copysign(1.0, l) * tmp)
end
code[F_, l_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[l], $MachinePrecision], 235000000000.0], N[(Pi * N[Abs[l], $MachinePrecision] + N[(N[(Pi * N[(N[Abs[l], $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision] / (-F)), $MachinePrecision]), $MachinePrecision], N[(N[Abs[l], $MachinePrecision] * Pi), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|\ell\right| \leq 235000000000:\\
\;\;\;\;\mathsf{fma}\left(\pi, \left|\ell\right|, \frac{\pi \cdot \frac{\left|\ell\right|}{F}}{-F}\right)\\

\mathbf{else}:\\
\;\;\;\;\left|\ell\right| \cdot \pi\\


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

    1. Initial program 76.5%

      \[\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. lift-*.f64N/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)} \]
      3. fp-cancel-sub-sign-invN/A

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{1}{F \cdot F}}\right)\right) \cdot \tan \left(\pi \cdot \ell\right) + \pi \cdot \ell \]
      6. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{1}{\mathsf{neg}\left(F \cdot F\right)}} \cdot \tan \left(\pi \cdot \ell\right) + \pi \cdot \ell \]
      7. associate-*l/N/A

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

        \[\leadsto \frac{\color{blue}{\tan \left(\pi \cdot \ell\right) \cdot 1}}{\mathsf{neg}\left(F \cdot F\right)} + \pi \cdot \ell \]
      9. lift-*.f64N/A

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

        \[\leadsto \frac{\tan \left(\pi \cdot \ell\right) \cdot 1}{\color{blue}{F \cdot \left(\mathsf{neg}\left(F\right)\right)}} + \pi \cdot \ell \]
      11. times-fracN/A

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \pi}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    5. 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.f6475.2%

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

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

        \[\leadsto \color{blue}{\frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} + \ell \cdot \pi} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\ell \cdot \pi + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F}} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\ell \cdot \pi} + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\pi \cdot \ell} + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} \]
      5. lower-fma.f64N/A

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

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

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\ell \cdot \pi}{F} \cdot \color{blue}{\frac{\mathsf{neg}\left(-1\right)}{\mathsf{neg}\left(F\right)}}\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\ell \cdot \pi}{F} \cdot \frac{\color{blue}{1}}{\mathsf{neg}\left(F\right)}\right) \]
      9. mult-flip-revN/A

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

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \color{blue}{\frac{\frac{\ell \cdot \pi}{F}}{\mathsf{neg}\left(F\right)}}\right) \]
      11. lower-neg.f6475.2%

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\frac{\ell \cdot \pi}{F}}{\color{blue}{-F}}\right) \]
    8. Applied rewrites75.2%

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

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

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

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

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

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

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

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

    if 2.35e11 < l

    1. Initial program 76.5%

      \[\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 \pi} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

Alternative 6: 98.4% accurate, 1.8× speedup?

\[\begin{array}{l} t_0 := \left|\ell\right| \cdot \pi\\ \mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l} \mathbf{if}\;\left|\ell\right| \leq 235000000000:\\ \;\;\;\;t\_0 - \frac{\frac{t\_0}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (F l)
 :precision binary64
 (let* ((t_0 (* (fabs l) PI)))
   (*
    (copysign 1.0 l)
    (if (<= (fabs l) 235000000000.0) (- t_0 (/ (/ t_0 F) F)) t_0))))
double code(double F, double l) {
	double t_0 = fabs(l) * ((double) M_PI);
	double tmp;
	if (fabs(l) <= 235000000000.0) {
		tmp = t_0 - ((t_0 / F) / F);
	} else {
		tmp = t_0;
	}
	return copysign(1.0, l) * tmp;
}
public static double code(double F, double l) {
	double t_0 = Math.abs(l) * Math.PI;
	double tmp;
	if (Math.abs(l) <= 235000000000.0) {
		tmp = t_0 - ((t_0 / F) / F);
	} else {
		tmp = t_0;
	}
	return Math.copySign(1.0, l) * tmp;
}
def code(F, l):
	t_0 = math.fabs(l) * math.pi
	tmp = 0
	if math.fabs(l) <= 235000000000.0:
		tmp = t_0 - ((t_0 / F) / F)
	else:
		tmp = t_0
	return math.copysign(1.0, l) * tmp
function code(F, l)
	t_0 = Float64(abs(l) * pi)
	tmp = 0.0
	if (abs(l) <= 235000000000.0)
		tmp = Float64(t_0 - Float64(Float64(t_0 / F) / F));
	else
		tmp = t_0;
	end
	return Float64(copysign(1.0, l) * tmp)
end
function tmp_2 = code(F, l)
	t_0 = abs(l) * pi;
	tmp = 0.0;
	if (abs(l) <= 235000000000.0)
		tmp = t_0 - ((t_0 / F) / F);
	else
		tmp = t_0;
	end
	tmp_2 = (sign(l) * abs(1.0)) * tmp;
end
code[F_, l_] := Block[{t$95$0 = N[(N[Abs[l], $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[l], $MachinePrecision], 235000000000.0], N[(t$95$0 - N[(N[(t$95$0 / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|\ell\right| \cdot \pi\\
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|\ell\right| \leq 235000000000:\\
\;\;\;\;t\_0 - \frac{\frac{t\_0}{F}}{F}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 76.5%

      \[\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. lift-*.f64N/A

        \[\leadsto \pi \cdot \ell - \color{blue}{\frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)} \]
      3. fp-cancel-sub-sign-invN/A

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{1}{F \cdot F}}\right)\right) \cdot \tan \left(\pi \cdot \ell\right) + \pi \cdot \ell \]
      6. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{1}{\mathsf{neg}\left(F \cdot F\right)}} \cdot \tan \left(\pi \cdot \ell\right) + \pi \cdot \ell \]
      7. associate-*l/N/A

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

        \[\leadsto \frac{\color{blue}{\tan \left(\pi \cdot \ell\right) \cdot 1}}{\mathsf{neg}\left(F \cdot F\right)} + \pi \cdot \ell \]
      9. lift-*.f64N/A

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

        \[\leadsto \frac{\tan \left(\pi \cdot \ell\right) \cdot 1}{\color{blue}{F \cdot \left(\mathsf{neg}\left(F\right)\right)}} + \pi \cdot \ell \]
      11. times-fracN/A

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\ell \cdot \pi}{F}}, \frac{-1}{F}, \ell \cdot \pi\right) \]
    5. 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.f6475.2%

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

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

        \[\leadsto \color{blue}{\frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} + \ell \cdot \pi} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\ell \cdot \pi + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F}} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\ell \cdot \pi} + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\pi \cdot \ell} + \frac{\ell \cdot \pi}{F} \cdot \frac{-1}{F} \]
      5. lower-fma.f64N/A

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

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

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\ell \cdot \pi}{F} \cdot \color{blue}{\frac{\mathsf{neg}\left(-1\right)}{\mathsf{neg}\left(F\right)}}\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\ell \cdot \pi}{F} \cdot \frac{\color{blue}{1}}{\mathsf{neg}\left(F\right)}\right) \]
      9. mult-flip-revN/A

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

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \color{blue}{\frac{\frac{\ell \cdot \pi}{F}}{\mathsf{neg}\left(F\right)}}\right) \]
      11. lower-neg.f6475.2%

        \[\leadsto \mathsf{fma}\left(\pi, \ell, \frac{\frac{\ell \cdot \pi}{F}}{\color{blue}{-F}}\right) \]
    8. Applied rewrites75.2%

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

        \[\leadsto \color{blue}{\pi \cdot \ell + \frac{\frac{\ell \cdot \pi}{F}}{-F}} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\pi \cdot \ell} + \frac{\frac{\ell \cdot \pi}{F}}{-F} \]
      3. add-flipN/A

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

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

        \[\leadsto \color{blue}{\pi \cdot \ell} - \left(\mathsf{neg}\left(\frac{\frac{\ell \cdot \pi}{F}}{-F}\right)\right) \]
      6. *-commutativeN/A

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

        \[\leadsto \color{blue}{\ell \cdot \pi} - \left(\mathsf{neg}\left(\frac{\frac{\ell \cdot \pi}{F}}{-F}\right)\right) \]
      8. lift-/.f64N/A

        \[\leadsto \ell \cdot \pi - \left(\mathsf{neg}\left(\color{blue}{\frac{\frac{\ell \cdot \pi}{F}}{-F}}\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \ell \cdot \pi - \color{blue}{\frac{\mathsf{neg}\left(\frac{\ell \cdot \pi}{F}\right)}{-F}} \]
      10. lift-neg.f64N/A

        \[\leadsto \ell \cdot \pi - \frac{\mathsf{neg}\left(\frac{\ell \cdot \pi}{F}\right)}{\color{blue}{\mathsf{neg}\left(F\right)}} \]
      11. frac-2negN/A

        \[\leadsto \ell \cdot \pi - \color{blue}{\frac{\frac{\ell \cdot \pi}{F}}{F}} \]
      12. lower-/.f6475.2%

        \[\leadsto \ell \cdot \pi - \color{blue}{\frac{\frac{\ell \cdot \pi}{F}}{F}} \]
    10. Applied rewrites75.2%

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

    if 2.35e11 < l

    1. Initial program 76.5%

      \[\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 \pi} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

Alternative 7: 73.5% accurate, 13.6× speedup?

\[\ell \cdot \pi \]
(FPCore (F l) :precision binary64 (* l PI))
double code(double F, double l) {
	return l * ((double) M_PI);
}
public static double code(double F, double l) {
	return l * Math.PI;
}
def code(F, l):
	return l * math.pi
function code(F, l)
	return Float64(l * pi)
end
function tmp = code(F, l)
	tmp = l * pi;
end
code[F_, l_] := N[(l * Pi), $MachinePrecision]
\ell \cdot \pi
Derivation
  1. Initial program 76.5%

    \[\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 \pi} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

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

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

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

Reproduce

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