Average Error: 16.7 → 0.7
Time: 12.7s
Precision: binary64
Cost: 32968
\[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
\[\begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -1 \cdot 10^{+15}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;\pi \cdot \ell \leq 0.02:\\ \;\;\;\;\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, \pi, -1\right) + 1\\ \end{array} \]
(FPCore (F l)
 :precision binary64
 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
(FPCore (F l)
 :precision binary64
 (if (<= (* PI l) -1e+15)
   (* PI l)
   (if (<= (* PI l) 0.02)
     (- (* PI l) (/ (/ (tan (* PI l)) F) F))
     (+ (fma l PI -1.0) 1.0))))
double code(double F, double l) {
	return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
double code(double F, double l) {
	double tmp;
	if ((((double) M_PI) * l) <= -1e+15) {
		tmp = ((double) M_PI) * l;
	} else if ((((double) M_PI) * l) <= 0.02) {
		tmp = (((double) M_PI) * l) - ((tan((((double) M_PI) * l)) / F) / F);
	} else {
		tmp = fma(l, ((double) M_PI), -1.0) + 1.0;
	}
	return tmp;
}
function code(F, l)
	return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l))))
end
function code(F, l)
	tmp = 0.0
	if (Float64(pi * l) <= -1e+15)
		tmp = Float64(pi * l);
	elseif (Float64(pi * l) <= 0.02)
		tmp = Float64(Float64(pi * l) - Float64(Float64(tan(Float64(pi * l)) / F) / F));
	else
		tmp = Float64(fma(l, pi, -1.0) + 1.0);
	end
	return tmp
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]
code[F_, l_] := If[LessEqual[N[(Pi * l), $MachinePrecision], -1e+15], N[(Pi * l), $MachinePrecision], If[LessEqual[N[(Pi * l), $MachinePrecision], 0.02], N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], N[(N[(l * Pi + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]]]
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -1 \cdot 10^{+15}:\\
\;\;\;\;\pi \cdot \ell\\

\mathbf{elif}\;\pi \cdot \ell \leq 0.02:\\
\;\;\;\;\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\ell, \pi, -1\right) + 1\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 (PI.f64) l) < -1e15

    1. Initial program 24.2

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Simplified24.2

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

      \[\leadsto \color{blue}{\ell \cdot \pi} \]

    if -1e15 < (*.f64 (PI.f64) l) < 0.0200000000000000004

    1. Initial program 9.4

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied egg-rr0.6

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

    if 0.0200000000000000004 < (*.f64 (PI.f64) l)

    1. Initial program 22.5

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Simplified22.5

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

      \[\leadsto \color{blue}{\ell \cdot \pi} \]
    4. Applied egg-rr1.1

      \[\leadsto \color{blue}{\left(1 + \ell \cdot \pi\right) - 1} \]
    5. Applied egg-rr1.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(\ell, \pi, -1\right) + 1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -1 \cdot 10^{+15}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;\pi \cdot \ell \leq 0.02:\\ \;\;\;\;\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, \pi, -1\right) + 1\\ \end{array} \]

Alternatives

Alternative 1
Error0.9
Cost26568
\[\begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -1 \cdot 10^{+15}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;\pi \cdot \ell \leq 0.02:\\ \;\;\;\;\pi \cdot \ell - \frac{\frac{\pi \cdot \ell}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, \pi, -1\right) + 1\\ \end{array} \]
Alternative 2
Error4.9
Cost13320
\[\begin{array}{l} \mathbf{if}\;\ell \leq -3.8:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;\ell \leq 0.0059:\\ \;\;\;\;\pi \cdot \left(\ell - \frac{\ell}{F \cdot F}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, \pi, -1\right) + 1\\ \end{array} \]
Alternative 3
Error13.3
Cost7640
\[\begin{array}{l} t_0 := -1 + \left(\pi \cdot \ell + 1\right)\\ t_1 := \ell \cdot \frac{\frac{-\pi}{F}}{F}\\ \mathbf{if}\;F \leq -4.675860782316854 \cdot 10^{-102}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;F \leq -5.4 \cdot 10^{-199}:\\ \;\;\;\;\pi \cdot \frac{-\frac{\ell}{F}}{F}\\ \mathbf{elif}\;F \leq 5.731130462967596 \cdot 10^{-159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 6.6180432152346266 \cdot 10^{-121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;F \leq 1.4939116397832601 \cdot 10^{-62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 1.306601849189003 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 4
Error13.3
Cost7640
\[\begin{array}{l} t_0 := -1 + \left(\pi \cdot \ell + 1\right)\\ \mathbf{if}\;F \leq -4.675860782316854 \cdot 10^{-102}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;F \leq -5.4 \cdot 10^{-199}:\\ \;\;\;\;\pi \cdot \frac{-\frac{\ell}{F}}{F}\\ \mathbf{elif}\;F \leq 5.731130462967596 \cdot 10^{-159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 6.6180432152346266 \cdot 10^{-121}:\\ \;\;\;\;\ell \cdot \frac{-\pi}{F \cdot F}\\ \mathbf{elif}\;F \leq 1.4939116397832601 \cdot 10^{-62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 1.306601849189003 \cdot 10^{-17}:\\ \;\;\;\;\ell \cdot \frac{\frac{-\pi}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 5
Error13.2
Cost7376
\[\begin{array}{l} t_0 := \ell \cdot \frac{\frac{-\pi}{F}}{F}\\ \mathbf{if}\;F \leq 5.731130462967596 \cdot 10^{-159}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;F \leq 6.6180432152346266 \cdot 10^{-121}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 1.4939116397832601 \cdot 10^{-62}:\\ \;\;\;\;-1 + \left(\pi \cdot \ell + 1\right)\\ \mathbf{elif}\;F \leq 1.306601849189003 \cdot 10^{-17}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 6
Error4.9
Cost7176
\[\begin{array}{l} \mathbf{if}\;\ell \leq -3.8:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;\ell \leq 0.0059:\\ \;\;\;\;\pi \cdot \left(\ell - \frac{\ell}{F \cdot F}\right)\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 7
Error13.2
Cost6528
\[\pi \cdot \ell \]

Error

Reproduce

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