
(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 7 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
(if (or (<= (* PI l) -5e+36) (not (<= (* PI l) 2e-6)))
(* PI l)
(fma
PI
l
(/
(-
(fma
(pow l 3.0)
(* (/ (pow PI 3.0) F) 0.3333333333333333)
(* PI (/ l F))))
F))))
double code(double F, double l) {
double tmp;
if (((((double) M_PI) * l) <= -5e+36) || !((((double) M_PI) * l) <= 2e-6)) {
tmp = ((double) M_PI) * l;
} else {
tmp = fma(((double) M_PI), l, (-fma(pow(l, 3.0), ((pow(((double) M_PI), 3.0) / F) * 0.3333333333333333), (((double) M_PI) * (l / F))) / F));
}
return tmp;
}
function code(F, l) tmp = 0.0 if ((Float64(pi * l) <= -5e+36) || !(Float64(pi * l) <= 2e-6)) tmp = Float64(pi * l); else tmp = fma(pi, l, Float64(Float64(-fma((l ^ 3.0), Float64(Float64((pi ^ 3.0) / F) * 0.3333333333333333), Float64(pi * Float64(l / F)))) / F)); end return tmp end
code[F_, l_] := If[Or[LessEqual[N[(Pi * l), $MachinePrecision], -5e+36], N[Not[LessEqual[N[(Pi * l), $MachinePrecision], 2e-6]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(Pi * l + N[((-N[(N[Power[l, 3.0], $MachinePrecision] * N[(N[(N[Power[Pi, 3.0], $MachinePrecision] / F), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(Pi * N[(l / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) / F), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+36} \lor \neg \left(\pi \cdot \ell \leq 2 \cdot 10^{-6}\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\pi, \ell, \frac{-\mathsf{fma}\left({\ell}^{3}, \frac{{\pi}^{3}}{F} \cdot 0.3333333333333333, \pi \cdot \frac{\ell}{F}\right)}{F}\right)\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < -4.99999999999999977e36 or 1.99999999999999991e-6 < (*.f64 (PI.f64) l) Initial program 63.5%
sqr-neg63.5%
associate-*l/63.5%
*-lft-identity63.5%
sqr-neg63.5%
Simplified63.5%
Taylor expanded in l around 0 48.7%
Taylor expanded in F around inf 99.7%
if -4.99999999999999977e36 < (*.f64 (PI.f64) l) < 1.99999999999999991e-6Initial program 90.3%
*-commutative90.3%
sqr-neg90.3%
*-commutative90.3%
fma-neg90.3%
associate-*l/90.3%
times-frac99.5%
distribute-lft-neg-in99.5%
neg-mul-199.5%
associate-/r*99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
times-frac90.3%
Simplified99.6%
Taylor expanded in l around 0 99.6%
distribute-lft-out99.6%
mul-1-neg99.6%
fma-def99.6%
distribute-rgt-out--99.6%
metadata-eval99.6%
associate-/l*99.6%
associate-/r/99.6%
Simplified99.6%
Final simplification99.7%
(FPCore (F l) :precision binary64 (if (or (<= (* PI l) -5e+36) (not (<= (* PI l) 2e-6))) (* PI l) (- (* PI l) (/ (* PI (/ l F)) F))))
double code(double F, double l) {
double tmp;
if (((((double) M_PI) * l) <= -5e+36) || !((((double) M_PI) * l) <= 2e-6)) {
tmp = ((double) M_PI) * l;
} else {
tmp = (((double) M_PI) * l) - ((((double) M_PI) * (l / F)) / F);
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if (((Math.PI * l) <= -5e+36) || !((Math.PI * l) <= 2e-6)) {
tmp = Math.PI * l;
} else {
tmp = (Math.PI * l) - ((Math.PI * (l / F)) / F);
}
return tmp;
}
def code(F, l): tmp = 0 if ((math.pi * l) <= -5e+36) or not ((math.pi * l) <= 2e-6): tmp = math.pi * l else: tmp = (math.pi * l) - ((math.pi * (l / F)) / F) return tmp
function code(F, l) tmp = 0.0 if ((Float64(pi * l) <= -5e+36) || !(Float64(pi * l) <= 2e-6)) tmp = Float64(pi * l); else tmp = Float64(Float64(pi * l) - Float64(Float64(pi * Float64(l / F)) / F)); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if (((pi * l) <= -5e+36) || ~(((pi * l) <= 2e-6))) tmp = pi * l; else tmp = (pi * l) - ((pi * (l / F)) / F); end tmp_2 = tmp; end
code[F_, l_] := If[Or[LessEqual[N[(Pi * l), $MachinePrecision], -5e+36], N[Not[LessEqual[N[(Pi * l), $MachinePrecision], 2e-6]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] - N[(N[(Pi * N[(l / F), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+36} \lor \neg \left(\pi \cdot \ell \leq 2 \cdot 10^{-6}\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{\pi \cdot \frac{\ell}{F}}{F}\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < -4.99999999999999977e36 or 1.99999999999999991e-6 < (*.f64 (PI.f64) l) Initial program 63.5%
sqr-neg63.5%
associate-*l/63.5%
*-lft-identity63.5%
sqr-neg63.5%
Simplified63.5%
Taylor expanded in l around 0 48.7%
Taylor expanded in F around inf 99.7%
if -4.99999999999999977e36 < (*.f64 (PI.f64) l) < 1.99999999999999991e-6Initial program 90.3%
sqr-neg90.3%
associate-*l/90.3%
*-lft-identity90.3%
sqr-neg90.3%
Simplified90.3%
Taylor expanded in l around 0 90.3%
*-commutative90.3%
times-frac99.6%
Applied egg-rr99.6%
associate-*l/99.6%
Applied egg-rr99.6%
Final simplification99.7%
(FPCore (F l) :precision binary64 (if (or (<= l -3.6e+33) (not (<= l 290000000000.0))) (* PI l) (- (* PI l) (* (/ l F) (/ PI F)))))
double code(double F, double l) {
double tmp;
if ((l <= -3.6e+33) || !(l <= 290000000000.0)) {
tmp = ((double) M_PI) * l;
} else {
tmp = (((double) M_PI) * l) - ((l / F) * (((double) M_PI) / F));
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if ((l <= -3.6e+33) || !(l <= 290000000000.0)) {
tmp = Math.PI * l;
} else {
tmp = (Math.PI * l) - ((l / F) * (Math.PI / F));
}
return tmp;
}
def code(F, l): tmp = 0 if (l <= -3.6e+33) or not (l <= 290000000000.0): tmp = math.pi * l else: tmp = (math.pi * l) - ((l / F) * (math.pi / F)) return tmp
function code(F, l) tmp = 0.0 if ((l <= -3.6e+33) || !(l <= 290000000000.0)) tmp = Float64(pi * l); else tmp = Float64(Float64(pi * l) - Float64(Float64(l / F) * Float64(pi / F))); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if ((l <= -3.6e+33) || ~((l <= 290000000000.0))) tmp = pi * l; else tmp = (pi * l) - ((l / F) * (pi / F)); end tmp_2 = tmp; end
code[F_, l_] := If[Or[LessEqual[l, -3.6e+33], N[Not[LessEqual[l, 290000000000.0]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] - N[(N[(l / F), $MachinePrecision] * N[(Pi / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.6 \cdot 10^{+33} \lor \neg \left(\ell \leq 290000000000\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{\ell}{F} \cdot \frac{\pi}{F}\\
\end{array}
\end{array}
if l < -3.6000000000000003e33 or 2.9e11 < l Initial program 63.5%
sqr-neg63.5%
associate-*l/63.5%
*-lft-identity63.5%
sqr-neg63.5%
Simplified63.5%
Taylor expanded in l around 0 48.7%
Taylor expanded in F around inf 99.7%
if -3.6000000000000003e33 < l < 2.9e11Initial program 90.3%
sqr-neg90.3%
associate-*l/90.3%
*-lft-identity90.3%
sqr-neg90.3%
Simplified90.3%
Taylor expanded in l around 0 90.3%
*-commutative90.3%
times-frac99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (F l) :precision binary64 (if (or (<= l -3.6e+33) (not (<= l 290000000000.0))) (* PI l) (* (* PI l) (- 1.0 (pow F -2.0)))))
double code(double F, double l) {
double tmp;
if ((l <= -3.6e+33) || !(l <= 290000000000.0)) {
tmp = ((double) M_PI) * l;
} else {
tmp = (((double) M_PI) * l) * (1.0 - pow(F, -2.0));
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if ((l <= -3.6e+33) || !(l <= 290000000000.0)) {
tmp = Math.PI * l;
} else {
tmp = (Math.PI * l) * (1.0 - Math.pow(F, -2.0));
}
return tmp;
}
def code(F, l): tmp = 0 if (l <= -3.6e+33) or not (l <= 290000000000.0): tmp = math.pi * l else: tmp = (math.pi * l) * (1.0 - math.pow(F, -2.0)) return tmp
function code(F, l) tmp = 0.0 if ((l <= -3.6e+33) || !(l <= 290000000000.0)) tmp = Float64(pi * l); else tmp = Float64(Float64(pi * l) * Float64(1.0 - (F ^ -2.0))); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if ((l <= -3.6e+33) || ~((l <= 290000000000.0))) tmp = pi * l; else tmp = (pi * l) * (1.0 - (F ^ -2.0)); end tmp_2 = tmp; end
code[F_, l_] := If[Or[LessEqual[l, -3.6e+33], N[Not[LessEqual[l, 290000000000.0]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] * N[(1.0 - N[Power[F, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.6 \cdot 10^{+33} \lor \neg \left(\ell \leq 290000000000\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\left(\pi \cdot \ell\right) \cdot \left(1 - {F}^{-2}\right)\\
\end{array}
\end{array}
if l < -3.6000000000000003e33 or 2.9e11 < l Initial program 63.5%
sqr-neg63.5%
associate-*l/63.5%
*-lft-identity63.5%
sqr-neg63.5%
Simplified63.5%
Taylor expanded in l around 0 48.7%
Taylor expanded in F around inf 99.7%
if -3.6000000000000003e33 < l < 2.9e11Initial program 90.3%
sqr-neg90.3%
associate-*l/90.3%
*-lft-identity90.3%
sqr-neg90.3%
Simplified90.3%
Taylor expanded in l around 0 90.3%
Taylor expanded in l around 0 90.3%
*-lft-identity90.3%
associate-*l/90.3%
/-rgt-identity90.3%
unpow290.3%
associate-/l*90.3%
associate-/r/90.2%
unpow-190.2%
unpow-190.2%
pow-sqr90.3%
metadata-eval90.3%
*-commutative90.3%
distribute-lft-out--90.3%
associate-*r*90.3%
*-commutative90.3%
*-commutative90.3%
*-rgt-identity90.3%
distribute-lft-out--90.3%
Simplified90.3%
Final simplification94.6%
(FPCore (F l) :precision binary64 (if (or (<= l -4.5e-36) (not (<= l -1.8e-157))) (* PI l) (/ (* l (- PI)) (pow F 2.0))))
double code(double F, double l) {
double tmp;
if ((l <= -4.5e-36) || !(l <= -1.8e-157)) {
tmp = ((double) M_PI) * l;
} else {
tmp = (l * -((double) M_PI)) / pow(F, 2.0);
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if ((l <= -4.5e-36) || !(l <= -1.8e-157)) {
tmp = Math.PI * l;
} else {
tmp = (l * -Math.PI) / Math.pow(F, 2.0);
}
return tmp;
}
def code(F, l): tmp = 0 if (l <= -4.5e-36) or not (l <= -1.8e-157): tmp = math.pi * l else: tmp = (l * -math.pi) / math.pow(F, 2.0) return tmp
function code(F, l) tmp = 0.0 if ((l <= -4.5e-36) || !(l <= -1.8e-157)) tmp = Float64(pi * l); else tmp = Float64(Float64(l * Float64(-pi)) / (F ^ 2.0)); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if ((l <= -4.5e-36) || ~((l <= -1.8e-157))) tmp = pi * l; else tmp = (l * -pi) / (F ^ 2.0); end tmp_2 = tmp; end
code[F_, l_] := If[Or[LessEqual[l, -4.5e-36], N[Not[LessEqual[l, -1.8e-157]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(N[(l * (-Pi)), $MachinePrecision] / N[Power[F, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.5 \cdot 10^{-36} \lor \neg \left(\ell \leq -1.8 \cdot 10^{-157}\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\frac{\ell \cdot \left(-\pi\right)}{{F}^{2}}\\
\end{array}
\end{array}
if l < -4.50000000000000024e-36 or -1.8e-157 < l Initial program 76.6%
sqr-neg76.6%
associate-*l/76.6%
*-lft-identity76.6%
sqr-neg76.6%
Simplified76.6%
Taylor expanded in l around 0 69.0%
Taylor expanded in F around inf 80.4%
if -4.50000000000000024e-36 < l < -1.8e-157Initial program 90.6%
sqr-neg90.6%
associate-*l/90.6%
*-lft-identity90.6%
sqr-neg90.6%
Simplified90.6%
Taylor expanded in l around 0 90.6%
Taylor expanded in F around 0 57.5%
mul-1-neg57.5%
Simplified57.5%
Final simplification77.8%
(FPCore (F l) :precision binary64 (if (or (<= l -1.65e-40) (not (<= l -6.6e-158))) (* PI l) (* PI (* l (- (pow F -2.0))))))
double code(double F, double l) {
double tmp;
if ((l <= -1.65e-40) || !(l <= -6.6e-158)) {
tmp = ((double) M_PI) * l;
} else {
tmp = ((double) M_PI) * (l * -pow(F, -2.0));
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if ((l <= -1.65e-40) || !(l <= -6.6e-158)) {
tmp = Math.PI * l;
} else {
tmp = Math.PI * (l * -Math.pow(F, -2.0));
}
return tmp;
}
def code(F, l): tmp = 0 if (l <= -1.65e-40) or not (l <= -6.6e-158): tmp = math.pi * l else: tmp = math.pi * (l * -math.pow(F, -2.0)) return tmp
function code(F, l) tmp = 0.0 if ((l <= -1.65e-40) || !(l <= -6.6e-158)) tmp = Float64(pi * l); else tmp = Float64(pi * Float64(l * Float64(-(F ^ -2.0)))); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if ((l <= -1.65e-40) || ~((l <= -6.6e-158))) tmp = pi * l; else tmp = pi * (l * -(F ^ -2.0)); end tmp_2 = tmp; end
code[F_, l_] := If[Or[LessEqual[l, -1.65e-40], N[Not[LessEqual[l, -6.6e-158]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(Pi * N[(l * (-N[Power[F, -2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.65 \cdot 10^{-40} \lor \neg \left(\ell \leq -6.6 \cdot 10^{-158}\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \left(\ell \cdot \left(-{F}^{-2}\right)\right)\\
\end{array}
\end{array}
if l < -1.64999999999999996e-40 or -6.6000000000000003e-158 < l Initial program 76.6%
sqr-neg76.6%
associate-*l/76.6%
*-lft-identity76.6%
sqr-neg76.6%
Simplified76.6%
Taylor expanded in l around 0 69.0%
Taylor expanded in F around inf 80.4%
if -1.64999999999999996e-40 < l < -6.6000000000000003e-158Initial program 90.6%
sqr-neg90.6%
associate-*l/90.6%
*-lft-identity90.6%
sqr-neg90.6%
Simplified90.6%
Taylor expanded in l around 0 90.6%
*-commutative90.6%
times-frac99.8%
Applied egg-rr99.8%
associate-*l/99.8%
Applied egg-rr99.8%
Taylor expanded in F around 0 57.5%
associate-*r/57.5%
*-commutative57.5%
unpow257.5%
times-frac66.6%
metadata-eval66.6%
distribute-neg-frac66.6%
distribute-lft-neg-out66.6%
associate-*r/66.5%
*-lft-identity66.5%
associate-*l/66.4%
associate-*r*57.4%
unpow-157.4%
unpow-157.4%
pow-sqr57.4%
metadata-eval57.4%
*-commutative57.4%
associate-*r*57.5%
distribute-rgt-neg-in57.5%
distribute-rgt-neg-in57.5%
Simplified57.5%
Final simplification77.8%
(FPCore (F l) :precision binary64 (* PI l))
double code(double F, double l) {
return ((double) M_PI) * l;
}
public static double code(double F, double l) {
return Math.PI * l;
}
def code(F, l): return math.pi * l
function code(F, l) return Float64(pi * l) end
function tmp = code(F, l) tmp = pi * l; end
code[F_, l_] := N[(Pi * l), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell
\end{array}
Initial program 78.2%
sqr-neg78.2%
associate-*l/78.2%
*-lft-identity78.2%
sqr-neg78.2%
Simplified78.2%
Taylor expanded in l around 0 71.4%
Taylor expanded in F around inf 75.3%
Final simplification75.3%
herbie shell --seed 2023333
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))