
(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}
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
:precision binary64
(*
l_s
(if (<= (* PI l_m) 2e-6)
(fma
PI
l_m
(/
(-
(fma
(pow l_m 3.0)
(* (/ (pow PI 3.0) F) 0.3333333333333333)
(* PI (/ l_m F))))
F))
(* PI l_m))))l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
double tmp;
if ((((double) M_PI) * l_m) <= 2e-6) {
tmp = fma(((double) M_PI), l_m, (-fma(pow(l_m, 3.0), ((pow(((double) M_PI), 3.0) / F) * 0.3333333333333333), (((double) M_PI) * (l_m / F))) / F));
} else {
tmp = ((double) M_PI) * l_m;
}
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(pi * l_m) <= 2e-6) tmp = fma(pi, l_m, Float64(Float64(-fma((l_m ^ 3.0), Float64(Float64((pi ^ 3.0) / F) * 0.3333333333333333), Float64(pi * Float64(l_m / F)))) / F)); else tmp = Float64(pi * l_m); 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[(Pi * l$95$m), $MachinePrecision], 2e-6], N[(Pi * l$95$m + N[((-N[(N[Power[l$95$m, 3.0], $MachinePrecision] * N[(N[(N[Power[Pi, 3.0], $MachinePrecision] / F), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(Pi * N[(l$95$m / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) / F), $MachinePrecision]), $MachinePrecision], N[(Pi * l$95$m), $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}\;\pi \cdot l_m \leq 2 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\pi, l_m, \frac{-\mathsf{fma}\left({l_m}^{3}, \frac{{\pi}^{3}}{F} \cdot 0.3333333333333333, \pi \cdot \frac{l_m}{F}\right)}{F}\right)\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot l_m\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < 1.99999999999999991e-6Initial program 81.2%
fma-neg81.2%
distribute-lft-neg-in81.2%
sqr-neg81.2%
distribute-neg-frac81.2%
metadata-eval81.2%
distribute-lft-neg-out81.2%
neg-mul-181.2%
associate-/r*81.2%
metadata-eval81.2%
associate-*l/81.2%
*-lft-identity81.2%
associate-/l/87.7%
Simplified87.7%
Taylor expanded in l around 0 72.8%
distribute-lft-out72.8%
mul-1-neg72.8%
fma-def72.8%
distribute-rgt-out--72.8%
metadata-eval72.8%
associate-/l*72.8%
associate-/r/72.8%
Simplified72.8%
if 1.99999999999999991e-6 < (*.f64 (PI.f64) l) Initial program 67.1%
sqr-neg67.1%
associate-*l/67.1%
sqr-neg67.1%
*-lft-identity67.1%
Simplified67.1%
Taylor expanded in l around 0 54.4%
Taylor expanded in F around inf 99.7%
Final simplification78.7%
l_m = (fabs.f64 l) l_s = (copysign.f64 1 l) (FPCore (l_s F l_m) :precision binary64 (* l_s (if (<= (* PI l_m) 2e-6) (- (* PI l_m) (* (/ l_m F) (/ PI F))) (* PI l_m))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
double tmp;
if ((((double) M_PI) * l_m) <= 2e-6) {
tmp = (((double) M_PI) * l_m) - ((l_m / F) * (((double) M_PI) / F));
} else {
tmp = ((double) M_PI) * l_m;
}
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 ((Math.PI * l_m) <= 2e-6) {
tmp = (Math.PI * l_m) - ((l_m / F) * (Math.PI / F));
} else {
tmp = Math.PI * l_m;
}
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 (math.pi * l_m) <= 2e-6: tmp = (math.pi * l_m) - ((l_m / F) * (math.pi / F)) else: tmp = math.pi * l_m 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(pi * l_m) <= 2e-6) tmp = Float64(Float64(pi * l_m) - Float64(Float64(l_m / F) * Float64(pi / F))); else tmp = Float64(pi * l_m); 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 ((pi * l_m) <= 2e-6) tmp = (pi * l_m) - ((l_m / F) * (pi / F)); else tmp = pi * l_m; 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[(Pi * l$95$m), $MachinePrecision], 2e-6], N[(N[(Pi * l$95$m), $MachinePrecision] - N[(N[(l$95$m / F), $MachinePrecision] * N[(Pi / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Pi * l$95$m), $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}\;\pi \cdot l_m \leq 2 \cdot 10^{-6}:\\
\;\;\;\;\pi \cdot l_m - \frac{l_m}{F} \cdot \frac{\pi}{F}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot l_m\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < 1.99999999999999991e-6Initial program 81.2%
sqr-neg81.2%
associate-*l/81.2%
sqr-neg81.2%
*-lft-identity81.2%
Simplified81.2%
Taylor expanded in l around 0 76.2%
*-commutative76.2%
times-frac82.7%
Applied egg-rr82.7%
if 1.99999999999999991e-6 < (*.f64 (PI.f64) l) Initial program 67.1%
sqr-neg67.1%
associate-*l/67.1%
sqr-neg67.1%
*-lft-identity67.1%
Simplified67.1%
Taylor expanded in l around 0 54.4%
Taylor expanded in F around inf 99.7%
Final simplification86.4%
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
:precision binary64
(let* ((t_0 (* (/ l_m F) (/ (- PI) F))))
(*
l_s
(if (<= F 8e-222)
t_0
(if (<= F 1.36e-71)
(* PI l_m)
(if (<= F 5.1e-53)
(* (* l_m (pow F -2.0)) (- PI))
(if (or (<= F 1.22e-19) (not (<= F 4.8e-9))) (* PI l_m) t_0)))))))l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
double t_0 = (l_m / F) * (-((double) M_PI) / F);
double tmp;
if (F <= 8e-222) {
tmp = t_0;
} else if (F <= 1.36e-71) {
tmp = ((double) M_PI) * l_m;
} else if (F <= 5.1e-53) {
tmp = (l_m * pow(F, -2.0)) * -((double) M_PI);
} else if ((F <= 1.22e-19) || !(F <= 4.8e-9)) {
tmp = ((double) M_PI) * l_m;
} else {
tmp = t_0;
}
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 t_0 = (l_m / F) * (-Math.PI / F);
double tmp;
if (F <= 8e-222) {
tmp = t_0;
} else if (F <= 1.36e-71) {
tmp = Math.PI * l_m;
} else if (F <= 5.1e-53) {
tmp = (l_m * Math.pow(F, -2.0)) * -Math.PI;
} else if ((F <= 1.22e-19) || !(F <= 4.8e-9)) {
tmp = Math.PI * l_m;
} else {
tmp = t_0;
}
return l_s * tmp;
}
l_m = math.fabs(l) l_s = math.copysign(1.0, l) def code(l_s, F, l_m): t_0 = (l_m / F) * (-math.pi / F) tmp = 0 if F <= 8e-222: tmp = t_0 elif F <= 1.36e-71: tmp = math.pi * l_m elif F <= 5.1e-53: tmp = (l_m * math.pow(F, -2.0)) * -math.pi elif (F <= 1.22e-19) or not (F <= 4.8e-9): tmp = math.pi * l_m else: tmp = t_0 return l_s * tmp
l_m = abs(l) l_s = copysign(1.0, l) function code(l_s, F, l_m) t_0 = Float64(Float64(l_m / F) * Float64(Float64(-pi) / F)) tmp = 0.0 if (F <= 8e-222) tmp = t_0; elseif (F <= 1.36e-71) tmp = Float64(pi * l_m); elseif (F <= 5.1e-53) tmp = Float64(Float64(l_m * (F ^ -2.0)) * Float64(-pi)); elseif ((F <= 1.22e-19) || !(F <= 4.8e-9)) tmp = Float64(pi * l_m); else tmp = t_0; 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) t_0 = (l_m / F) * (-pi / F); tmp = 0.0; if (F <= 8e-222) tmp = t_0; elseif (F <= 1.36e-71) tmp = pi * l_m; elseif (F <= 5.1e-53) tmp = (l_m * (F ^ -2.0)) * -pi; elseif ((F <= 1.22e-19) || ~((F <= 4.8e-9))) tmp = pi * l_m; else tmp = t_0; 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_] := Block[{t$95$0 = N[(N[(l$95$m / F), $MachinePrecision] * N[((-Pi) / F), $MachinePrecision]), $MachinePrecision]}, N[(l$95$s * If[LessEqual[F, 8e-222], t$95$0, If[LessEqual[F, 1.36e-71], N[(Pi * l$95$m), $MachinePrecision], If[LessEqual[F, 5.1e-53], N[(N[(l$95$m * N[Power[F, -2.0], $MachinePrecision]), $MachinePrecision] * (-Pi)), $MachinePrecision], If[Or[LessEqual[F, 1.22e-19], N[Not[LessEqual[F, 4.8e-9]], $MachinePrecision]], N[(Pi * l$95$m), $MachinePrecision], t$95$0]]]]), $MachinePrecision]]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)
\\
\begin{array}{l}
t_0 := \frac{l_m}{F} \cdot \frac{-\pi}{F}\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;F \leq 8 \cdot 10^{-222}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;F \leq 1.36 \cdot 10^{-71}:\\
\;\;\;\;\pi \cdot l_m\\
\mathbf{elif}\;F \leq 5.1 \cdot 10^{-53}:\\
\;\;\;\;\left(l_m \cdot {F}^{-2}\right) \cdot \left(-\pi\right)\\
\mathbf{elif}\;F \leq 1.22 \cdot 10^{-19} \lor \neg \left(F \leq 4.8 \cdot 10^{-9}\right):\\
\;\;\;\;\pi \cdot l_m\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
\end{array}
if F < 8.00000000000000038e-222 or 1.2200000000000001e-19 < F < 4.8e-9Initial program 75.6%
sqr-neg75.6%
associate-*l/75.7%
sqr-neg75.7%
*-lft-identity75.7%
Simplified75.7%
Taylor expanded in l around 0 70.4%
Taylor expanded in F around 0 25.9%
mul-1-neg25.9%
Simplified25.9%
*-commutative25.9%
unpow225.9%
times-frac29.7%
Applied egg-rr29.7%
if 8.00000000000000038e-222 < F < 1.3599999999999999e-71 or 5.10000000000000045e-53 < F < 1.2200000000000001e-19 or 4.8e-9 < F Initial program 79.6%
sqr-neg79.6%
associate-*l/79.6%
sqr-neg79.6%
*-lft-identity79.6%
Simplified79.6%
Taylor expanded in l around 0 74.0%
Taylor expanded in F around inf 83.1%
if 1.3599999999999999e-71 < F < 5.10000000000000045e-53Initial program 99.5%
sqr-neg99.5%
associate-*l/99.2%
sqr-neg99.2%
*-lft-identity99.2%
Simplified99.2%
Taylor expanded in l around 0 59.4%
Taylor expanded in F around 0 59.4%
mul-1-neg59.4%
Simplified59.4%
add-log-exp2.3%
*-un-lft-identity2.3%
log-prod2.3%
metadata-eval2.3%
add-log-exp59.4%
div-inv59.7%
associate-*l*59.4%
pow-flip59.4%
metadata-eval59.4%
Applied egg-rr59.4%
+-lft-identity59.4%
*-commutative59.4%
associate-*r*59.7%
*-commutative59.7%
Simplified59.7%
Final simplification52.4%
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
:precision binary64
(*
l_s
(if (or (<= F 8e-221)
(and (not (<= F 3.6e-72))
(or (<= F 5.15e-54) (and (not (<= F 9.5e-20)) (<= F 6.5e-9)))))
(* (/ l_m F) (/ (- PI) F))
(* PI l_m))))l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
double tmp;
if ((F <= 8e-221) || (!(F <= 3.6e-72) && ((F <= 5.15e-54) || (!(F <= 9.5e-20) && (F <= 6.5e-9))))) {
tmp = (l_m / F) * (-((double) M_PI) / F);
} else {
tmp = ((double) M_PI) * l_m;
}
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 ((F <= 8e-221) || (!(F <= 3.6e-72) && ((F <= 5.15e-54) || (!(F <= 9.5e-20) && (F <= 6.5e-9))))) {
tmp = (l_m / F) * (-Math.PI / F);
} else {
tmp = Math.PI * l_m;
}
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 (F <= 8e-221) or (not (F <= 3.6e-72) and ((F <= 5.15e-54) or (not (F <= 9.5e-20) and (F <= 6.5e-9)))): tmp = (l_m / F) * (-math.pi / F) else: tmp = math.pi * l_m 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 ((F <= 8e-221) || (!(F <= 3.6e-72) && ((F <= 5.15e-54) || (!(F <= 9.5e-20) && (F <= 6.5e-9))))) tmp = Float64(Float64(l_m / F) * Float64(Float64(-pi) / F)); else tmp = Float64(pi * l_m); 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 ((F <= 8e-221) || (~((F <= 3.6e-72)) && ((F <= 5.15e-54) || (~((F <= 9.5e-20)) && (F <= 6.5e-9))))) tmp = (l_m / F) * (-pi / F); else tmp = pi * l_m; 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[Or[LessEqual[F, 8e-221], And[N[Not[LessEqual[F, 3.6e-72]], $MachinePrecision], Or[LessEqual[F, 5.15e-54], And[N[Not[LessEqual[F, 9.5e-20]], $MachinePrecision], LessEqual[F, 6.5e-9]]]]], N[(N[(l$95$m / F), $MachinePrecision] * N[((-Pi) / F), $MachinePrecision]), $MachinePrecision], N[(Pi * l$95$m), $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}\;F \leq 8 \cdot 10^{-221} \lor \neg \left(F \leq 3.6 \cdot 10^{-72}\right) \land \left(F \leq 5.15 \cdot 10^{-54} \lor \neg \left(F \leq 9.5 \cdot 10^{-20}\right) \land F \leq 6.5 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{l_m}{F} \cdot \frac{-\pi}{F}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot l_m\\
\end{array}
\end{array}
if F < 8.00000000000000014e-221 or 3.6e-72 < F < 5.15000000000000007e-54 or 9.5e-20 < F < 6.5000000000000003e-9Initial program 77.2%
sqr-neg77.2%
associate-*l/77.2%
sqr-neg77.2%
*-lft-identity77.2%
Simplified77.2%
Taylor expanded in l around 0 69.7%
Taylor expanded in F around 0 28.1%
mul-1-neg28.1%
Simplified28.1%
*-commutative28.1%
unpow228.1%
times-frac31.7%
Applied egg-rr31.7%
if 8.00000000000000014e-221 < F < 3.6e-72 or 5.15000000000000007e-54 < F < 9.5e-20 or 6.5000000000000003e-9 < F Initial program 79.6%
sqr-neg79.6%
associate-*l/79.6%
sqr-neg79.6%
*-lft-identity79.6%
Simplified79.6%
Taylor expanded in l around 0 74.0%
Taylor expanded in F around inf 83.1%
Final simplification52.4%
l_m = (fabs.f64 l) l_s = (copysign.f64 1 l) (FPCore (l_s F l_m) :precision binary64 (* l_s (* PI l_m)))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
return l_s * (((double) M_PI) * l_m);
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
return l_s * (Math.PI * l_m);
}
l_m = math.fabs(l) l_s = math.copysign(1.0, l) def code(l_s, F, l_m): return l_s * (math.pi * l_m)
l_m = abs(l) l_s = copysign(1.0, l) function code(l_s, F, l_m) return Float64(l_s * Float64(pi * l_m)) end
l_m = abs(l); l_s = sign(l) * abs(1.0); function tmp = code(l_s, F, l_m) tmp = l_s * (pi * l_m); 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 * N[(Pi * l$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)
\\
l_s \cdot \left(\pi \cdot l_m\right)
\end{array}
Initial program 78.2%
sqr-neg78.2%
associate-*l/78.2%
sqr-neg78.2%
*-lft-identity78.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)))))