
(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 6 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
(let* ((t_0 (* (fabs l) PI)))
(*
(copysign 1.0 l)
(if (<= (fabs l) 1.05e+15)
(- (* 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) <= 1.05e+15) {
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) <= 1.05e+15) {
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) <= 1.05e+15: 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) <= 1.05e+15) 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) <= 1.05e+15) 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], 1.05e+15], 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 1.05 \cdot 10^{+15}:\\
\;\;\;\;\pi \cdot \left|\ell\right| - \frac{\frac{\tan t\_0}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if l < 1.05e15Initial program 76.4%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.2%
Applied rewrites82.2%
if 1.05e15 < l Initial program 76.4%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6474.0%
Applied rewrites74.0%
(FPCore (F l)
:precision binary64
(let* ((t_0 (* PI (fabs l))) (t_1 (* (fabs l) PI)))
(*
(copysign 1.0 l)
(if (<= (fabs l) 2e-22)
(- t_0 (/ (/ t_1 F) F))
(if (<= (fabs l) 1.05e+15) (- t_0 (/ (tan t_1) (* F F))) t_1)))))double code(double F, double l) {
double t_0 = ((double) M_PI) * fabs(l);
double t_1 = fabs(l) * ((double) M_PI);
double tmp;
if (fabs(l) <= 2e-22) {
tmp = t_0 - ((t_1 / F) / F);
} else if (fabs(l) <= 1.05e+15) {
tmp = t_0 - (tan(t_1) / (F * F));
} else {
tmp = t_1;
}
return copysign(1.0, l) * tmp;
}
public static double code(double F, double l) {
double t_0 = Math.PI * Math.abs(l);
double t_1 = Math.abs(l) * Math.PI;
double tmp;
if (Math.abs(l) <= 2e-22) {
tmp = t_0 - ((t_1 / F) / F);
} else if (Math.abs(l) <= 1.05e+15) {
tmp = t_0 - (Math.tan(t_1) / (F * F));
} else {
tmp = t_1;
}
return Math.copySign(1.0, l) * tmp;
}
def code(F, l): t_0 = math.pi * math.fabs(l) t_1 = math.fabs(l) * math.pi tmp = 0 if math.fabs(l) <= 2e-22: tmp = t_0 - ((t_1 / F) / F) elif math.fabs(l) <= 1.05e+15: tmp = t_0 - (math.tan(t_1) / (F * F)) else: tmp = t_1 return math.copysign(1.0, l) * tmp
function code(F, l) t_0 = Float64(pi * abs(l)) t_1 = Float64(abs(l) * pi) tmp = 0.0 if (abs(l) <= 2e-22) tmp = Float64(t_0 - Float64(Float64(t_1 / F) / F)); elseif (abs(l) <= 1.05e+15) tmp = Float64(t_0 - Float64(tan(t_1) / Float64(F * F))); else tmp = t_1; end return Float64(copysign(1.0, l) * tmp) end
function tmp_2 = code(F, l) t_0 = pi * abs(l); t_1 = abs(l) * pi; tmp = 0.0; if (abs(l) <= 2e-22) tmp = t_0 - ((t_1 / F) / F); elseif (abs(l) <= 1.05e+15) tmp = t_0 - (tan(t_1) / (F * F)); else tmp = t_1; end tmp_2 = (sign(l) * abs(1.0)) * tmp; end
code[F_, l_] := Block[{t$95$0 = N[(Pi * N[Abs[l], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = 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], 2e-22], N[(t$95$0 - N[(N[(t$95$1 / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[l], $MachinePrecision], 1.05e+15], N[(t$95$0 - N[(N[Tan[t$95$1], $MachinePrecision] / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \pi \cdot \left|\ell\right|\\
t_1 := \left|\ell\right| \cdot \pi\\
\mathsf{copysign}\left(1, \ell\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|\ell\right| \leq 2 \cdot 10^{-22}:\\
\;\;\;\;t\_0 - \frac{\frac{t\_1}{F}}{F}\\
\mathbf{elif}\;\left|\ell\right| \leq 1.05 \cdot 10^{+15}:\\
\;\;\;\;t\_0 - \frac{\tan t\_1}{F \cdot F}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if l < 2.0000000000000001e-22Initial program 76.4%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.2%
Applied rewrites82.2%
Taylor expanded in l around 0
lower-/.f64N/A
lower-*.f64N/A
lower-PI.f6475.1%
Applied rewrites75.1%
if 2.0000000000000001e-22 < l < 1.05e15Initial program 76.4%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.2%
Applied rewrites82.2%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6482.2%
Applied rewrites82.2%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
lift-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
mult-flipN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-tan.f64N/A
associate-/l/N/A
pow2N/A
lift-pow.f64N/A
lower-/.f6476.7%
lift-pow.f64N/A
pow2N/A
lower-*.f6476.7%
Applied rewrites76.7%
if 1.05e15 < l Initial program 76.4%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6474.0%
Applied rewrites74.0%
(FPCore (F l)
:precision binary64
(let* ((t_0 (* (fabs l) PI)))
(*
(copysign 1.0 l)
(if (<= (fabs l) 3.5e+16)
(- (* PI (fabs l)) (/ (/ 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) <= 3.5e+16) {
tmp = (((double) M_PI) * fabs(l)) - ((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) <= 3.5e+16) {
tmp = (Math.PI * Math.abs(l)) - ((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) <= 3.5e+16: tmp = (math.pi * math.fabs(l)) - ((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) <= 3.5e+16) tmp = Float64(Float64(pi * abs(l)) - 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) <= 3.5e+16) tmp = (pi * abs(l)) - ((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], 3.5e+16], N[(N[(Pi * N[Abs[l], $MachinePrecision]), $MachinePrecision] - 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 3.5 \cdot 10^{+16}:\\
\;\;\;\;\pi \cdot \left|\ell\right| - \frac{\frac{t\_0}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if l < 3.5e16Initial program 76.4%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.2%
Applied rewrites82.2%
Taylor expanded in l around 0
lower-/.f64N/A
lower-*.f64N/A
lower-PI.f6475.1%
Applied rewrites75.1%
if 3.5e16 < l Initial program 76.4%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6474.0%
Applied rewrites74.0%
(FPCore (F l) :precision binary64 (* (copysign 1.0 l) (if (<= (fabs l) 3.5e+16) (* (fabs l) (- PI (* (/ 1.0 (* F F)) PI))) (* (fabs l) PI))))
double code(double F, double l) {
double tmp;
if (fabs(l) <= 3.5e+16) {
tmp = fabs(l) * (((double) M_PI) - ((1.0 / (F * F)) * ((double) M_PI)));
} 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.5e+16) {
tmp = Math.abs(l) * (Math.PI - ((1.0 / (F * F)) * Math.PI));
} 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.5e+16: tmp = math.fabs(l) * (math.pi - ((1.0 / (F * F)) * math.pi)) 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.5e+16) tmp = Float64(abs(l) * Float64(pi - Float64(Float64(1.0 / Float64(F * F)) * pi))); 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.5e+16) tmp = abs(l) * (pi - ((1.0 / (F * F)) * pi)); 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.5e+16], N[(N[Abs[l], $MachinePrecision] * N[(Pi - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * Pi), $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.5 \cdot 10^{+16}:\\
\;\;\;\;\left|\ell\right| \cdot \left(\pi - \frac{1}{F \cdot F} \cdot \pi\right)\\
\mathbf{else}:\\
\;\;\;\;\left|\ell\right| \cdot \pi\\
\end{array}
if l < 3.5e16Initial program 76.4%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.2%
Applied rewrites82.2%
Taylor expanded in l around 0
lower-*.f64N/A
lower--.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-pow.f6469.4%
Applied rewrites69.4%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6469.4%
lift-pow.f64N/A
pow2N/A
lower-*.f6469.4%
Applied rewrites69.4%
if 3.5e16 < l Initial program 76.4%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6474.0%
Applied rewrites74.0%
(FPCore (F l) :precision binary64 (* (copysign 1.0 l) (if (<= (fabs l) 3.5e+16) (* (- PI (/ PI (* F F))) (fabs l)) (* (fabs l) PI))))
double code(double F, double l) {
double tmp;
if (fabs(l) <= 3.5e+16) {
tmp = (((double) M_PI) - (((double) M_PI) / (F * F))) * fabs(l);
} 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.5e+16) {
tmp = (Math.PI - (Math.PI / (F * F))) * Math.abs(l);
} 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.5e+16: tmp = (math.pi - (math.pi / (F * F))) * math.fabs(l) 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.5e+16) tmp = Float64(Float64(pi - Float64(pi / Float64(F * F))) * abs(l)); 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.5e+16) tmp = (pi - (pi / (F * F))) * abs(l); 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.5e+16], N[(N[(Pi - N[(Pi / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Abs[l], $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.5 \cdot 10^{+16}:\\
\;\;\;\;\left(\pi - \frac{\pi}{F \cdot F}\right) \cdot \left|\ell\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\ell\right| \cdot \pi\\
\end{array}
if l < 3.5e16Initial program 76.4%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flip-revN/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.2%
Applied rewrites82.2%
Taylor expanded in l around 0
lower-*.f64N/A
lower--.f64N/A
lower-PI.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-pow.f6469.4%
Applied rewrites69.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6469.4%
lift-pow.f64N/A
pow2N/A
lower-*.f6469.4%
Applied rewrites69.4%
if 3.5e16 < l Initial program 76.4%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6474.0%
Applied rewrites74.0%
(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.4%
Taylor expanded in F around inf
lower-*.f64N/A
lower-PI.f6474.0%
Applied rewrites74.0%
herbie shell --seed 2025258
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))