
(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}
Sampling outcomes in binary64 precision:
Herbie found 5 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]
\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
(let* ((t_0 (tan (* PI l))))
(if (<= (- (* PI l) (* (/ 1.0 (* F F)) t_0)) 5e+287)
(- (* PI l) (/ (/ t_0 F) F))
(- (* PI l) (/ (* F F) t_0)))))
double code(double F, double l) {
double t_0 = tan((((double) M_PI) * l));
double tmp;
if (((((double) M_PI) * l) - ((1.0 / (F * F)) * t_0)) <= 5e+287) {
tmp = (((double) M_PI) * l) - ((t_0 / F) / F);
} else {
tmp = (((double) M_PI) * l) - ((F * F) / t_0);
}
return tmp;
}
public static double code(double F, double l) {
double t_0 = Math.tan((Math.PI * l));
double tmp;
if (((Math.PI * l) - ((1.0 / (F * F)) * t_0)) <= 5e+287) {
tmp = (Math.PI * l) - ((t_0 / F) / F);
} else {
tmp = (Math.PI * l) - ((F * F) / t_0);
}
return tmp;
}
def code(F, l): t_0 = math.tan((math.pi * l)) tmp = 0 if ((math.pi * l) - ((1.0 / (F * F)) * t_0)) <= 5e+287: tmp = (math.pi * l) - ((t_0 / F) / F) else: tmp = (math.pi * l) - ((F * F) / t_0) return tmp
function code(F, l) t_0 = tan(Float64(pi * l)) tmp = 0.0 if (Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * t_0)) <= 5e+287) tmp = Float64(Float64(pi * l) - Float64(Float64(t_0 / F) / F)); else tmp = Float64(Float64(pi * l) - Float64(Float64(F * F) / t_0)); end return tmp end
function tmp_2 = code(F, l) t_0 = tan((pi * l)); tmp = 0.0; if (((pi * l) - ((1.0 / (F * F)) * t_0)) <= 5e+287) tmp = (pi * l) - ((t_0 / F) / F); else tmp = (pi * l) - ((F * F) / t_0); end tmp_2 = tmp; end
code[F_, l_] := Block[{t$95$0 = N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 5e+287], N[(N[(Pi * l), $MachinePrecision] - N[(N[(t$95$0 / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] - N[(N[(F * F), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(\pi \cdot \ell\right)\\
\mathbf{if}\;\pi \cdot \ell - \frac{1}{F \cdot F} \cdot t_0 \leq 5 \cdot 10^{+287}:\\
\;\;\;\;\pi \cdot \ell - \frac{\frac{t_0}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{F \cdot F}{t_0}\\
\end{array}
\end{array}
if (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 1 (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) < 5e287Initial program 86.8%
associate-*l/86.9%
*-un-lft-identity86.9%
associate-/r*89.0%
Applied egg-rr89.0%
if 5e287 < (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 1 (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) Initial program 28.8%
associate-/r/28.8%
inv-pow28.8%
pow-to-exp1.6%
diff-log0.0%
diff-log1.6%
associate-/l*1.6%
Applied egg-rr1.6%
add-sqr-sqrt1.6%
sqrt-unprod1.6%
*-commutative1.6%
*-commutative1.6%
swap-sqr1.6%
metadata-eval1.6%
*-un-lft-identity1.6%
sqrt-unprod0.0%
Applied egg-rr59.7%
Final simplification84.5%
(FPCore (F l) :precision binary64 (if (<= (* F F) 2e-305) (- (* PI l) (* PI (/ (/ l F) F))) (- (* PI l) (/ (tan (* PI l)) (* F F)))))
double code(double F, double l) {
double tmp;
if ((F * F) <= 2e-305) {
tmp = (((double) M_PI) * l) - (((double) M_PI) * ((l / F) / F));
} else {
tmp = (((double) M_PI) * l) - (tan((((double) M_PI) * l)) / (F * F));
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if ((F * F) <= 2e-305) {
tmp = (Math.PI * l) - (Math.PI * ((l / F) / F));
} else {
tmp = (Math.PI * l) - (Math.tan((Math.PI * l)) / (F * F));
}
return tmp;
}
def code(F, l): tmp = 0 if (F * F) <= 2e-305: tmp = (math.pi * l) - (math.pi * ((l / F) / F)) else: tmp = (math.pi * l) - (math.tan((math.pi * l)) / (F * F)) return tmp
function code(F, l) tmp = 0.0 if (Float64(F * F) <= 2e-305) tmp = Float64(Float64(pi * l) - Float64(pi * Float64(Float64(l / F) / F))); else tmp = Float64(Float64(pi * l) - Float64(tan(Float64(pi * l)) / Float64(F * F))); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if ((F * F) <= 2e-305) tmp = (pi * l) - (pi * ((l / F) / F)); else tmp = (pi * l) - (tan((pi * l)) / (F * F)); end tmp_2 = tmp; end
code[F_, l_] := If[LessEqual[N[(F * F), $MachinePrecision], 2e-305], N[(N[(Pi * l), $MachinePrecision] - N[(Pi * N[(N[(l / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] - N[(N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;F \cdot F \leq 2 \cdot 10^{-305}:\\
\;\;\;\;\pi \cdot \ell - \pi \cdot \frac{\frac{\ell}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{\tan \left(\pi \cdot \ell\right)}{F \cdot F}\\
\end{array}
\end{array}
if (*.f64 F F) < 1.99999999999999999e-305Initial program 30.4%
Taylor expanded in l around 0 27.8%
unpow227.8%
times-frac46.8%
Simplified46.8%
clear-num46.8%
frac-times46.8%
*-un-lft-identity46.8%
Applied egg-rr46.8%
clear-num46.7%
associate-/r/46.7%
associate-/r*46.8%
clear-num46.8%
Applied egg-rr46.8%
if 1.99999999999999999e-305 < (*.f64 F F) Initial program 93.2%
associate-*l/93.2%
*-lft-identity93.2%
Simplified93.2%
Final simplification82.0%
(FPCore (F l)
:precision binary64
(let* ((t_0 (tan (* PI l))))
(if (<= (* F F) 0.0)
(- (* PI l) (/ (* F F) t_0))
(- (* PI l) (/ t_0 (* F F))))))
double code(double F, double l) {
double t_0 = tan((((double) M_PI) * l));
double tmp;
if ((F * F) <= 0.0) {
tmp = (((double) M_PI) * l) - ((F * F) / t_0);
} else {
tmp = (((double) M_PI) * l) - (t_0 / (F * F));
}
return tmp;
}
public static double code(double F, double l) {
double t_0 = Math.tan((Math.PI * l));
double tmp;
if ((F * F) <= 0.0) {
tmp = (Math.PI * l) - ((F * F) / t_0);
} else {
tmp = (Math.PI * l) - (t_0 / (F * F));
}
return tmp;
}
def code(F, l): t_0 = math.tan((math.pi * l)) tmp = 0 if (F * F) <= 0.0: tmp = (math.pi * l) - ((F * F) / t_0) else: tmp = (math.pi * l) - (t_0 / (F * F)) return tmp
function code(F, l) t_0 = tan(Float64(pi * l)) tmp = 0.0 if (Float64(F * F) <= 0.0) tmp = Float64(Float64(pi * l) - Float64(Float64(F * F) / t_0)); else tmp = Float64(Float64(pi * l) - Float64(t_0 / Float64(F * F))); end return tmp end
function tmp_2 = code(F, l) t_0 = tan((pi * l)); tmp = 0.0; if ((F * F) <= 0.0) tmp = (pi * l) - ((F * F) / t_0); else tmp = (pi * l) - (t_0 / (F * F)); end tmp_2 = tmp; end
code[F_, l_] := Block[{t$95$0 = N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(F * F), $MachinePrecision], 0.0], N[(N[(Pi * l), $MachinePrecision] - N[(N[(F * F), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] - N[(t$95$0 / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(\pi \cdot \ell\right)\\
\mathbf{if}\;F \cdot F \leq 0:\\
\;\;\;\;\pi \cdot \ell - \frac{F \cdot F}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{t_0}{F \cdot F}\\
\end{array}
\end{array}
if (*.f64 F F) < 0.0Initial program 29.0%
associate-/r/29.0%
inv-pow29.0%
pow-to-exp16.0%
diff-log14.9%
diff-log16.0%
associate-/l*21.7%
Applied egg-rr21.7%
add-sqr-sqrt21.5%
sqrt-unprod21.7%
*-commutative21.7%
*-commutative21.7%
swap-sqr21.7%
metadata-eval21.7%
*-un-lft-identity21.7%
sqrt-unprod0.0%
Applied egg-rr53.8%
if 0.0 < (*.f64 F F) Initial program 92.3%
associate-*l/92.4%
*-lft-identity92.4%
Simplified92.4%
Final simplification83.7%
(FPCore (F l) :precision binary64 (- (* PI l) (* (/ l F) (/ PI F))))
double code(double F, double l) {
return (((double) M_PI) * l) - ((l / F) * (((double) M_PI) / F));
}
public static double code(double F, double l) {
return (Math.PI * l) - ((l / F) * (Math.PI / F));
}
def code(F, l): return (math.pi * l) - ((l / F) * (math.pi / F))
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(l / F) * Float64(pi / F))) end
function tmp = code(F, l) tmp = (pi * l) - ((l / F) * (pi / F)); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(l / F), $MachinePrecision] * N[(Pi / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\ell}{F} \cdot \frac{\pi}{F}
\end{array}
Initial program 78.0%
Taylor expanded in l around 0 72.1%
unpow272.1%
times-frac76.7%
Simplified76.7%
Final simplification76.7%
(FPCore (F l) :precision binary64 (- (* PI l) (* PI (/ (/ l F) F))))
double code(double F, double l) {
return (((double) M_PI) * l) - (((double) M_PI) * ((l / F) / F));
}
public static double code(double F, double l) {
return (Math.PI * l) - (Math.PI * ((l / F) / F));
}
def code(F, l): return (math.pi * l) - (math.pi * ((l / F) / F))
function code(F, l) return Float64(Float64(pi * l) - Float64(pi * Float64(Float64(l / F) / F))) end
function tmp = code(F, l) tmp = (pi * l) - (pi * ((l / F) / F)); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(Pi * N[(N[(l / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \pi \cdot \frac{\frac{\ell}{F}}{F}
\end{array}
Initial program 78.0%
Taylor expanded in l around 0 72.1%
unpow272.1%
times-frac76.7%
Simplified76.7%
clear-num76.6%
frac-times76.7%
*-un-lft-identity76.7%
Applied egg-rr76.7%
clear-num76.6%
associate-/r/76.6%
associate-/r*76.6%
clear-num76.7%
Applied egg-rr76.7%
Final simplification76.7%
herbie shell --seed 2023252
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))