
(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)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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)
(FPCore (F l)
:precision binary64
(*
(copysign 1.0 l)
(if (<= (fabs l) 3.75e-10)
(- (* PI (fabs l)) (/ (* PI (/ (fabs l) F)) F))
(* (fabs l) PI))))double code(double F, double l) {
double tmp;
if (fabs(l) <= 3.75e-10) {
tmp = (((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;
}
public static double code(double F, double l) {
double tmp;
if (Math.abs(l) <= 3.75e-10) {
tmp = (Math.PI * Math.abs(l)) - ((Math.PI * (Math.abs(l) / F)) / F);
} else {
tmp = Math.abs(l) * Math.PI;
}
return Math.copySign(1.0, l) * tmp;
}
def code(F, l): tmp = 0 if math.fabs(l) <= 3.75e-10: tmp = (math.pi * math.fabs(l)) - ((math.pi * (math.fabs(l) / F)) / F) else: tmp = math.fabs(l) * math.pi return math.copysign(1.0, l) * tmp
function code(F, l) tmp = 0.0 if (abs(l) <= 3.75e-10) tmp = Float64(Float64(pi * abs(l)) - Float64(Float64(pi * Float64(abs(l) / F)) / F)); else tmp = Float64(abs(l) * pi); end return Float64(copysign(1.0, l) * tmp) end
function tmp_2 = code(F, l) tmp = 0.0; if (abs(l) <= 3.75e-10) tmp = (pi * abs(l)) - ((pi * (abs(l) / F)) / F); else tmp = abs(l) * pi; end tmp_2 = (sign(l) * abs(1.0)) * 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], 3.75e-10], N[(N[(Pi * N[Abs[l], $MachinePrecision]), $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 3.75 \cdot 10^{-10}:\\
\;\;\;\;\pi \cdot \left|\ell\right| - \frac{\pi \cdot \frac{\left|\ell\right|}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;\left|\ell\right| \cdot \pi\\
\end{array}
if l < 3.74999999999999998e-10Initial program 76.5%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.4
Applied rewrites82.4%
Taylor expanded in l around 0
lower-/.f64N/A
lower-*.f64N/A
lower-PI.f6474.5
Applied rewrites74.5%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6474.5
Applied rewrites74.5%
if 3.74999999999999998e-10 < l Initial program 76.5%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6473.8
Applied rewrites73.8%
(FPCore (F l)
:precision binary64
(*
(copysign 1.0 l)
(if (<= (fabs l) 3.75e-10)
(fma PI (fabs l) (/ (* (- (fabs l)) PI) (* F F)))
(* (fabs l) PI))))double code(double F, double l) {
double tmp;
if (fabs(l) <= 3.75e-10) {
tmp = fma(((double) M_PI), fabs(l), ((-fabs(l) * ((double) M_PI)) / (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) <= 3.75e-10) tmp = fma(pi, abs(l), Float64(Float64(Float64(-abs(l)) * pi) / Float64(F * 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], 3.75e-10], N[(Pi * N[Abs[l], $MachinePrecision] + N[(N[((-N[Abs[l], $MachinePrecision]) * Pi), $MachinePrecision] / N[(F * F), $MachinePrecision]), $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 3.75 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\pi, \left|\ell\right|, \frac{\left(-\left|\ell\right|\right) \cdot \pi}{F \cdot F}\right)\\
\mathbf{else}:\\
\;\;\;\;\left|\ell\right| \cdot \pi\\
\end{array}
if l < 3.74999999999999998e-10Initial program 76.5%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
Applied rewrites40.8%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6428.4
Applied rewrites28.4%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6438.8
Applied rewrites38.8%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6469.0
Applied rewrites69.0%
if 3.74999999999999998e-10 < l Initial program 76.5%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6473.8
Applied rewrites73.8%
(FPCore (F l)
:precision binary64
(let* ((t_0 (* (fabs l) PI)) (t_1 (* PI (fabs l))))
(*
(copysign 1.0 l)
(if (<= (- t_1 (* (/ 1.0 (* F F)) (tan t_1))) -1e-248)
(/ (* -1.0 (/ t_0 F)) F)
t_0))))double code(double F, double l) {
double t_0 = fabs(l) * ((double) M_PI);
double t_1 = ((double) M_PI) * fabs(l);
double tmp;
if ((t_1 - ((1.0 / (F * F)) * tan(t_1))) <= -1e-248) {
tmp = (-1.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 t_1 = Math.PI * Math.abs(l);
double tmp;
if ((t_1 - ((1.0 / (F * F)) * Math.tan(t_1))) <= -1e-248) {
tmp = (-1.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 t_1 = math.pi * math.fabs(l) tmp = 0 if (t_1 - ((1.0 / (F * F)) * math.tan(t_1))) <= -1e-248: tmp = (-1.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) t_1 = Float64(pi * abs(l)) tmp = 0.0 if (Float64(t_1 - Float64(Float64(1.0 / Float64(F * F)) * tan(t_1))) <= -1e-248) tmp = Float64(Float64(-1.0 * 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; t_1 = pi * abs(l); tmp = 0.0; if ((t_1 - ((1.0 / (F * F)) * tan(t_1))) <= -1e-248) tmp = (-1.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]}, Block[{t$95$1 = N[(Pi * N[Abs[l], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1e-248], N[(N[(-1.0 * N[(t$95$0 / F), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision], t$95$0]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \left|\ell\right| \cdot \pi\\
t_1 := \pi \cdot \left|\ell\right|\\
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_1 - \frac{1}{F \cdot F} \cdot \tan t\_1 \leq -1 \cdot 10^{-248}:\\
\;\;\;\;\frac{-1 \cdot \frac{t\_0}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) < -9.9999999999999998e-249Initial program 76.5%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
sub-to-fractionN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites58.2%
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
sub-to-fraction-revN/A
lift-/.f64N/A
sub-flipN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
Applied rewrites70.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-PI.f6462.8
Applied rewrites62.8%
Taylor expanded in F around 0
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-PI.f6426.6
Applied rewrites26.6%
if -9.9999999999999998e-249 < (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) Initial program 76.5%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6473.8
Applied rewrites73.8%
(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
Initial program 76.5%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6473.8
Applied rewrites73.8%
herbie shell --seed 2025175
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))