
(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 10 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}
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
:precision binary64
(*
l_s
(if (<= (* l_m PI) 1e+15)
(fma (/ (tan (* l_m PI)) F) (/ -1.0 F) (* l_m PI))
(* l_m PI))))l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
double tmp;
if ((l_m * ((double) M_PI)) <= 1e+15) {
tmp = fma((tan((l_m * ((double) M_PI))) / F), (-1.0 / F), (l_m * ((double) M_PI)));
} else {
tmp = l_m * ((double) M_PI);
}
return l_s * tmp;
}
l\_m = abs(l) l\_s = copysign(1.0, l) function code(l_s, F, l_m) tmp = 0.0 if (Float64(l_m * pi) <= 1e+15) tmp = fma(Float64(tan(Float64(l_m * pi)) / F), Float64(-1.0 / F), Float64(l_m * pi)); else tmp = Float64(l_m * pi); end return Float64(l_s * tmp) end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[N[(l$95$m * Pi), $MachinePrecision], 1e+15], N[(N[(N[Tan[N[(l$95$m * Pi), $MachinePrecision]], $MachinePrecision] / F), $MachinePrecision] * N[(-1.0 / F), $MachinePrecision] + N[(l$95$m * Pi), $MachinePrecision]), $MachinePrecision], N[(l$95$m * Pi), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \cdot \pi \leq 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\tan \left(l\_m \cdot \pi\right)}{F}, \frac{-1}{F}, l\_m \cdot \pi\right)\\
\mathbf{else}:\\
\;\;\;\;l\_m \cdot \pi\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < 1e15Initial program 86.9%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
distribute-neg-frac2N/A
*-rgt-identityN/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
times-fracN/A
distribute-neg-frac2N/A
lower-fma.f64N/A
Applied rewrites97.6%
if 1e15 < (*.f64 (PI.f64) l) Initial program 63.1%
Taylor expanded in l around inf
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6499.7
Applied rewrites99.7%
Final simplification98.5%
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
:precision binary64
(*
l_s
(if (<= (- (* l_m PI) (* (tan (* l_m PI)) (/ 1.0 (* F F)))) -5e-292)
(/ (* (- l_m) PI) (* F F))
(* l_m PI))))l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
double tmp;
if (((l_m * ((double) M_PI)) - (tan((l_m * ((double) M_PI))) * (1.0 / (F * F)))) <= -5e-292) {
tmp = (-l_m * ((double) M_PI)) / (F * F);
} else {
tmp = l_m * ((double) M_PI);
}
return l_s * tmp;
}
l\_m = Math.abs(l);
l\_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
double tmp;
if (((l_m * Math.PI) - (Math.tan((l_m * Math.PI)) * (1.0 / (F * F)))) <= -5e-292) {
tmp = (-l_m * Math.PI) / (F * F);
} else {
tmp = l_m * Math.PI;
}
return l_s * tmp;
}
l\_m = math.fabs(l) l\_s = math.copysign(1.0, l) def code(l_s, F, l_m): tmp = 0 if ((l_m * math.pi) - (math.tan((l_m * math.pi)) * (1.0 / (F * F)))) <= -5e-292: tmp = (-l_m * math.pi) / (F * F) else: tmp = l_m * math.pi return l_s * tmp
l\_m = abs(l) l\_s = copysign(1.0, l) function code(l_s, F, l_m) tmp = 0.0 if (Float64(Float64(l_m * pi) - Float64(tan(Float64(l_m * pi)) * Float64(1.0 / Float64(F * F)))) <= -5e-292) tmp = Float64(Float64(Float64(-l_m) * pi) / Float64(F * F)); else tmp = Float64(l_m * pi); end return Float64(l_s * tmp) end
l\_m = abs(l); l\_s = sign(l) * abs(1.0); function tmp_2 = code(l_s, F, l_m) tmp = 0.0; if (((l_m * pi) - (tan((l_m * pi)) * (1.0 / (F * F)))) <= -5e-292) tmp = (-l_m * pi) / (F * F); else tmp = l_m * pi; end tmp_2 = l_s * tmp; end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[N[(N[(l$95$m * Pi), $MachinePrecision] - N[(N[Tan[N[(l$95$m * Pi), $MachinePrecision]], $MachinePrecision] * N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -5e-292], N[(N[((-l$95$m) * Pi), $MachinePrecision] / N[(F * F), $MachinePrecision]), $MachinePrecision], N[(l$95$m * Pi), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \cdot \pi - \tan \left(l\_m \cdot \pi\right) \cdot \frac{1}{F \cdot F} \leq -5 \cdot 10^{-292}:\\
\;\;\;\;\frac{\left(-l\_m\right) \cdot \pi}{F \cdot F}\\
\mathbf{else}:\\
\;\;\;\;l\_m \cdot \pi\\
\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)))) < -4.99999999999999981e-292Initial program 55.8%
Taylor expanded in F around 0
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
unpow2N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6456.2
Applied rewrites56.2%
Taylor expanded in l around 0
Applied rewrites54.4%
Applied rewrites55.5%
if -4.99999999999999981e-292 < (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) Initial program 86.0%
Taylor expanded in l around inf
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6498.0
Applied rewrites98.0%
Final simplification83.1%
herbie shell --seed 2024234
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))