
(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 12 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 (- (* PI l) (/ (/ (/ (sin (* PI l)) (fma -0.5 (pow (log1p (expm1 (* PI l))) 2.0) 1.0)) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - (((sin((((double) M_PI) * l)) / fma(-0.5, pow(log1p(expm1((((double) M_PI) * l))), 2.0), 1.0)) / F) / F);
}
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(Float64(sin(Float64(pi * l)) / fma(-0.5, (log1p(expm1(Float64(pi * l))) ^ 2.0), 1.0)) / F) / F)) end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[(N[Sin[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / N[(-0.5 * N[Power[N[Log[1 + N[(Exp[N[(Pi * l), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\frac{\sin \left(\pi \cdot \ell\right)}{\mathsf{fma}\left(-0.5, {\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot \ell\right)\right)\right)}^{2}, 1\right)}}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
tan-quot85.5%
Applied egg-rr85.5%
Taylor expanded in l around 0 92.5%
+-commutative92.5%
fma-define92.5%
*-commutative92.5%
unpow292.5%
unpow292.5%
swap-sqr92.5%
unpow292.5%
*-commutative92.5%
Simplified92.5%
*-commutative92.5%
log1p-expm1-u98.9%
Applied egg-rr98.9%
(FPCore (F l) :precision binary64 (- (* PI l) (/ (/ (/ (sin (* PI l)) (fma -0.5 (sqrt (pow (* PI l) 4.0)) 1.0)) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - (((sin((((double) M_PI) * l)) / fma(-0.5, sqrt(pow((((double) M_PI) * l), 4.0)), 1.0)) / F) / F);
}
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(Float64(sin(Float64(pi * l)) / fma(-0.5, sqrt((Float64(pi * l) ^ 4.0)), 1.0)) / F) / F)) end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[(N[Sin[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / N[(-0.5 * N[Sqrt[N[Power[N[(Pi * l), $MachinePrecision], 4.0], $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\frac{\sin \left(\pi \cdot \ell\right)}{\mathsf{fma}\left(-0.5, \sqrt{{\left(\pi \cdot \ell\right)}^{4}}, 1\right)}}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
tan-quot85.5%
Applied egg-rr85.5%
Taylor expanded in l around 0 92.5%
+-commutative92.5%
fma-define92.5%
*-commutative92.5%
unpow292.5%
unpow292.5%
swap-sqr92.5%
unpow292.5%
*-commutative92.5%
Simplified92.5%
add-sqr-sqrt92.5%
sqrt-unprod94.7%
*-commutative94.7%
*-commutative94.7%
pow-prod-up94.7%
metadata-eval94.7%
Applied egg-rr94.7%
(FPCore (F l) :precision binary64 (- (* PI l) (/ (/ (/ (fabs (sin (* PI l))) (fma -0.5 (pow (* PI l) 2.0) 1.0)) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - (((fabs(sin((((double) M_PI) * l))) / fma(-0.5, pow((((double) M_PI) * l), 2.0), 1.0)) / F) / F);
}
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(Float64(abs(sin(Float64(pi * l))) / fma(-0.5, (Float64(pi * l) ^ 2.0), 1.0)) / F) / F)) end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[(N[Abs[N[Sin[N[(Pi * l), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[(-0.5 * N[Power[N[(Pi * l), $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\frac{\left|\sin \left(\pi \cdot \ell\right)\right|}{\mathsf{fma}\left(-0.5, {\left(\pi \cdot \ell\right)}^{2}, 1\right)}}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
tan-quot85.5%
Applied egg-rr85.5%
Taylor expanded in l around 0 92.5%
+-commutative92.5%
fma-define92.5%
*-commutative92.5%
unpow292.5%
unpow292.5%
swap-sqr92.5%
unpow292.5%
*-commutative92.5%
Simplified92.5%
add-sqr-sqrt45.6%
sqrt-unprod73.4%
pow273.4%
Applied egg-rr73.4%
unpow273.4%
rem-sqrt-square77.9%
*-commutative77.9%
Simplified77.9%
Final simplification77.9%
(FPCore (F l) :precision binary64 (- (* PI l) (/ (/ (/ (sin (* PI l)) (fma -0.5 (* PI (* l (* PI l))) 1.0)) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - (((sin((((double) M_PI) * l)) / fma(-0.5, (((double) M_PI) * (l * (((double) M_PI) * l))), 1.0)) / F) / F);
}
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(Float64(sin(Float64(pi * l)) / fma(-0.5, Float64(pi * Float64(l * Float64(pi * l))), 1.0)) / F) / F)) end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[(N[Sin[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / N[(-0.5 * N[(Pi * N[(l * N[(Pi * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\frac{\sin \left(\pi \cdot \ell\right)}{\mathsf{fma}\left(-0.5, \pi \cdot \left(\ell \cdot \left(\pi \cdot \ell\right)\right), 1\right)}}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
tan-quot85.5%
Applied egg-rr85.5%
Taylor expanded in l around 0 92.5%
+-commutative92.5%
fma-define92.5%
*-commutative92.5%
unpow292.5%
unpow292.5%
swap-sqr92.5%
unpow292.5%
*-commutative92.5%
Simplified92.5%
unpow292.5%
*-commutative92.5%
associate-*r*92.5%
Applied egg-rr92.5%
Final simplification92.5%
(FPCore (F l) :precision binary64 (- (* PI l) (/ (/ (/ (* PI l) (fma -0.5 (pow (* PI l) 2.0) 1.0)) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - ((((((double) M_PI) * l) / fma(-0.5, pow((((double) M_PI) * l), 2.0), 1.0)) / F) / F);
}
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(Float64(Float64(pi * l) / fma(-0.5, (Float64(pi * l) ^ 2.0), 1.0)) / F) / F)) end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[(N[(Pi * l), $MachinePrecision] / N[(-0.5 * N[Power[N[(Pi * l), $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\frac{\pi \cdot \ell}{\mathsf{fma}\left(-0.5, {\left(\pi \cdot \ell\right)}^{2}, 1\right)}}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
tan-quot85.5%
Applied egg-rr85.5%
Taylor expanded in l around 0 92.5%
+-commutative92.5%
fma-define92.5%
*-commutative92.5%
unpow292.5%
unpow292.5%
swap-sqr92.5%
unpow292.5%
*-commutative92.5%
Simplified92.5%
Taylor expanded in l around 0 92.0%
Final simplification92.0%
(FPCore (F l) :precision binary64 (- (* PI l) (/ (/ (/ (sin (* PI l)) (cos (* PI l))) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - (((sin((((double) M_PI) * l)) / cos((((double) M_PI) * l))) / F) / F);
}
public static double code(double F, double l) {
return (Math.PI * l) - (((Math.sin((Math.PI * l)) / Math.cos((Math.PI * l))) / F) / F);
}
def code(F, l): return (math.pi * l) - (((math.sin((math.pi * l)) / math.cos((math.pi * l))) / F) / F)
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(Float64(sin(Float64(pi * l)) / cos(Float64(pi * l))) / F) / F)) end
function tmp = code(F, l) tmp = (pi * l) - (((sin((pi * l)) / cos((pi * l))) / F) / F); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[(N[Sin[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / N[Cos[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\frac{\sin \left(\pi \cdot \ell\right)}{\cos \left(\pi \cdot \ell\right)}}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
tan-quot85.5%
Applied egg-rr85.5%
(FPCore (F l) :precision binary64 (if (<= (* PI l) 1e-8) (- (* PI l) (/ PI (* F (/ F l)))) (- (* PI l) (/ (tan (* PI l)) (* F F)))))
double code(double F, double l) {
double tmp;
if ((((double) M_PI) * l) <= 1e-8) {
tmp = (((double) M_PI) * l) - (((double) M_PI) / (F * (F / l)));
} 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 ((Math.PI * l) <= 1e-8) {
tmp = (Math.PI * l) - (Math.PI / (F * (F / l)));
} else {
tmp = (Math.PI * l) - (Math.tan((Math.PI * l)) / (F * F));
}
return tmp;
}
def code(F, l): tmp = 0 if (math.pi * l) <= 1e-8: tmp = (math.pi * l) - (math.pi / (F * (F / l))) else: tmp = (math.pi * l) - (math.tan((math.pi * l)) / (F * F)) return tmp
function code(F, l) tmp = 0.0 if (Float64(pi * l) <= 1e-8) tmp = Float64(Float64(pi * l) - Float64(pi / Float64(F * Float64(F / l)))); 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 ((pi * l) <= 1e-8) tmp = (pi * l) - (pi / (F * (F / l))); else tmp = (pi * l) - (tan((pi * l)) / (F * F)); end tmp_2 = tmp; end
code[F_, l_] := If[LessEqual[N[(Pi * l), $MachinePrecision], 1e-8], N[(N[(Pi * l), $MachinePrecision] - N[(Pi / N[(F * N[(F / l), $MachinePrecision]), $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}\;\pi \cdot \ell \leq 10^{-8}:\\
\;\;\;\;\pi \cdot \ell - \frac{\pi}{F \cdot \frac{F}{\ell}}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{\tan \left(\pi \cdot \ell\right)}{F \cdot F}\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < 1e-8Initial program 86.1%
*-commutative86.1%
sqr-neg86.1%
associate-*r/86.8%
sqr-neg86.8%
*-rgt-identity86.8%
Simplified86.8%
Taylor expanded in l around 0 81.2%
*-commutative81.2%
times-frac86.4%
Applied egg-rr86.4%
*-commutative86.4%
clear-num86.4%
frac-times86.4%
*-un-lft-identity86.4%
Applied egg-rr86.4%
if 1e-8 < (*.f64 (PI.f64) l) Initial program 68.6%
*-commutative68.6%
sqr-neg68.6%
associate-*r/68.6%
sqr-neg68.6%
*-rgt-identity68.6%
Simplified68.6%
Final simplification81.5%
(FPCore (F l) :precision binary64 (- (* PI l) (/ (/ (tan (* PI l)) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - ((tan((((double) M_PI) * l)) / F) / F);
}
public static double code(double F, double l) {
return (Math.PI * l) - ((Math.tan((Math.PI * l)) / F) / F);
}
def code(F, l): return (math.pi * l) - ((math.tan((math.pi * l)) / F) / F)
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(tan(Float64(pi * l)) / F) / F)) end
function tmp = code(F, l) tmp = (pi * l) - ((tan((pi * l)) / F) / F); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
(FPCore (F l) :precision binary64 (- (* PI l) (/ (/ (sin (* PI l)) F) F)))
double code(double F, double l) {
return (((double) M_PI) * l) - ((sin((((double) M_PI) * l)) / F) / F);
}
public static double code(double F, double l) {
return (Math.PI * l) - ((Math.sin((Math.PI * l)) / F) / F);
}
def code(F, l): return (math.pi * l) - ((math.sin((math.pi * l)) / F) / F)
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(sin(Float64(pi * l)) / F) / F)) end
function tmp = code(F, l) tmp = (pi * l) - ((sin((pi * l)) / F) / F); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[Sin[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\sin \left(\pi \cdot \ell\right)}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
tan-quot85.5%
Applied egg-rr85.5%
Taylor expanded in l around 0 84.5%
Taylor expanded in l around inf 84.5%
Final simplification84.5%
(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(Float64(Float64(pi * 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[(N[(N[(Pi * l), $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\frac{\pi \cdot \ell}{F}}{F}
\end{array}
Initial program 81.2%
associate-*l/81.7%
*-un-lft-identity81.7%
associate-/r*85.5%
Applied egg-rr85.5%
Taylor expanded in l around 0 77.3%
Final simplification77.3%
(FPCore (F l) :precision binary64 (- (* PI l) (/ PI (* F (/ F l)))))
double code(double F, double l) {
return (((double) M_PI) * l) - (((double) M_PI) / (F * (F / l)));
}
public static double code(double F, double l) {
return (Math.PI * l) - (Math.PI / (F * (F / l)));
}
def code(F, l): return (math.pi * l) - (math.pi / (F * (F / l)))
function code(F, l) return Float64(Float64(pi * l) - Float64(pi / Float64(F * Float64(F / l)))) end
function tmp = code(F, l) tmp = (pi * l) - (pi / (F * (F / l))); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(Pi / N[(F * N[(F / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\pi}{F \cdot \frac{F}{\ell}}
\end{array}
Initial program 81.2%
*-commutative81.2%
sqr-neg81.2%
associate-*r/81.7%
sqr-neg81.7%
*-rgt-identity81.7%
Simplified81.7%
Taylor expanded in l around 0 73.5%
*-commutative73.5%
times-frac77.3%
Applied egg-rr77.3%
*-commutative77.3%
clear-num77.3%
frac-times77.3%
*-un-lft-identity77.3%
Applied egg-rr77.3%
Final simplification77.3%
(FPCore (F l) :precision binary64 (- (* PI l) (* (/ PI F) (/ l F))))
double code(double F, double l) {
return (((double) M_PI) * l) - ((((double) M_PI) / F) * (l / F));
}
public static double code(double F, double l) {
return (Math.PI * l) - ((Math.PI / F) * (l / F));
}
def code(F, l): return (math.pi * l) - ((math.pi / F) * (l / F))
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(pi / F) * Float64(l / F))) end
function tmp = code(F, l) tmp = (pi * l) - ((pi / F) * (l / F)); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(Pi / F), $MachinePrecision] * N[(l / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{\pi}{F} \cdot \frac{\ell}{F}
\end{array}
Initial program 81.2%
*-commutative81.2%
sqr-neg81.2%
associate-*r/81.7%
sqr-neg81.7%
*-rgt-identity81.7%
Simplified81.7%
Taylor expanded in l around 0 73.5%
*-commutative73.5%
times-frac77.3%
Applied egg-rr77.3%
herbie shell --seed 2024106
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))