| Alternative 1 | |
|---|---|
| Accuracy | 97.6% |
| Cost | 45712 |

(FPCore (F l) :precision binary64 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
(FPCore (F l)
:precision binary64
(if (<= (* PI l) -5e+84)
(log (/ 1.0 (pow (exp l) PI)))
(if (<= (* PI l) -5e+26)
(* PI l)
(if (<= (* PI l) 200000000000.0)
(- (* PI l) (/ (/ (tan (* PI l)) F) F))
(if (<= (* PI l) 2e+75) (* PI l) (log1p (expm1 (* PI l))))))))double code(double F, double l) {
return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
double code(double F, double l) {
double tmp;
if ((((double) M_PI) * l) <= -5e+84) {
tmp = log((1.0 / pow(exp(l), ((double) M_PI))));
} else if ((((double) M_PI) * l) <= -5e+26) {
tmp = ((double) M_PI) * l;
} else if ((((double) M_PI) * l) <= 200000000000.0) {
tmp = (((double) M_PI) * l) - ((tan((((double) M_PI) * l)) / F) / F);
} else if ((((double) M_PI) * l) <= 2e+75) {
tmp = ((double) M_PI) * l;
} else {
tmp = log1p(expm1((((double) M_PI) * l)));
}
return tmp;
}
public static double code(double F, double l) {
return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
public static double code(double F, double l) {
double tmp;
if ((Math.PI * l) <= -5e+84) {
tmp = Math.log((1.0 / Math.pow(Math.exp(l), Math.PI)));
} else if ((Math.PI * l) <= -5e+26) {
tmp = Math.PI * l;
} else if ((Math.PI * l) <= 200000000000.0) {
tmp = (Math.PI * l) - ((Math.tan((Math.PI * l)) / F) / F);
} else if ((Math.PI * l) <= 2e+75) {
tmp = Math.PI * l;
} else {
tmp = Math.log1p(Math.expm1((Math.PI * l)));
}
return tmp;
}
def code(F, l): return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
def code(F, l): tmp = 0 if (math.pi * l) <= -5e+84: tmp = math.log((1.0 / math.pow(math.exp(l), math.pi))) elif (math.pi * l) <= -5e+26: tmp = math.pi * l elif (math.pi * l) <= 200000000000.0: tmp = (math.pi * l) - ((math.tan((math.pi * l)) / F) / F) elif (math.pi * l) <= 2e+75: tmp = math.pi * l else: tmp = math.log1p(math.expm1((math.pi * l))) return tmp
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l)))) end
function code(F, l) tmp = 0.0 if (Float64(pi * l) <= -5e+84) tmp = log(Float64(1.0 / (exp(l) ^ pi))); elseif (Float64(pi * l) <= -5e+26) tmp = Float64(pi * l); elseif (Float64(pi * l) <= 200000000000.0) tmp = Float64(Float64(pi * l) - Float64(Float64(tan(Float64(pi * l)) / F) / F)); elseif (Float64(pi * l) <= 2e+75) tmp = Float64(pi * l); else tmp = log1p(expm1(Float64(pi * l))); end return tmp 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]
code[F_, l_] := If[LessEqual[N[(Pi * l), $MachinePrecision], -5e+84], N[Log[N[(1.0 / N[Power[N[Exp[l], $MachinePrecision], Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[(Pi * l), $MachinePrecision], -5e+26], N[(Pi * l), $MachinePrecision], If[LessEqual[N[(Pi * l), $MachinePrecision], 200000000000.0], N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(Pi * l), $MachinePrecision], 2e+75], N[(Pi * l), $MachinePrecision], N[Log[1 + N[(Exp[N[(Pi * l), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]]]]]
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+84}:\\
\;\;\;\;\log \left(\frac{1}{{\left(e^{\ell}\right)}^{\pi}}\right)\\
\mathbf{elif}\;\pi \cdot \ell \leq -5 \cdot 10^{+26}:\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{elif}\;\pi \cdot \ell \leq 200000000000:\\
\;\;\;\;\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}\\
\mathbf{elif}\;\pi \cdot \ell \leq 2 \cdot 10^{+75}:\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot \ell\right)\right)\\
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if (*.f64 (PI.f64) l) < -5.0000000000000001e84Initial program 15.8%
Taylor expanded in l around 0 50.7%
Simplified50.7%
[Start]50.7% | \[ \ell \cdot \left(\pi - \frac{\pi}{{F}^{2}}\right)
\] |
|---|---|
unpow2 [=>]50.7% | \[ \ell \cdot \left(\pi - \frac{\pi}{\color{blue}{F \cdot F}}\right)
\] |
Applied egg-rr50.7%
[Start]50.7% | \[ \ell \cdot \left(\pi - \frac{\pi}{F \cdot F}\right)
\] |
|---|---|
add-cbrt-cube [=>]50.7% | \[ \ell \cdot \color{blue}{\sqrt[3]{\left(\left(\pi - \frac{\pi}{F \cdot F}\right) \cdot \left(\pi - \frac{\pi}{F \cdot F}\right)\right) \cdot \left(\pi - \frac{\pi}{F \cdot F}\right)}}
\] |
pow3 [=>]50.7% | \[ \ell \cdot \sqrt[3]{\color{blue}{{\left(\pi - \frac{\pi}{F \cdot F}\right)}^{3}}}
\] |
div-inv [=>]50.7% | \[ \ell \cdot \sqrt[3]{{\left(\pi - \color{blue}{\pi \cdot \frac{1}{F \cdot F}}\right)}^{3}}
\] |
pow2 [=>]50.7% | \[ \ell \cdot \sqrt[3]{{\left(\pi - \pi \cdot \frac{1}{\color{blue}{{F}^{2}}}\right)}^{3}}
\] |
pow-flip [=>]50.7% | \[ \ell \cdot \sqrt[3]{{\left(\pi - \pi \cdot \color{blue}{{F}^{\left(-2\right)}}\right)}^{3}}
\] |
metadata-eval [=>]50.7% | \[ \ell \cdot \sqrt[3]{{\left(\pi - \pi \cdot {F}^{\color{blue}{-2}}\right)}^{3}}
\] |
Taylor expanded in F around inf 0.2%
Applied egg-rr100.0%
[Start]0.2% | \[ \ell \cdot \sqrt[3]{{\pi}^{3}}
\] |
|---|---|
rem-cbrt-cube [=>]0.2% | \[ \ell \cdot \color{blue}{\pi}
\] |
add-sqr-sqrt [=>]0.2% | \[ \ell \cdot \color{blue}{\left(\sqrt{\pi} \cdot \sqrt{\pi}\right)}
\] |
sqrt-unprod [=>]0.2% | \[ \ell \cdot \color{blue}{\sqrt{\pi \cdot \pi}}
\] |
sqr-neg [<=]0.2% | \[ \ell \cdot \sqrt{\color{blue}{\left(-\pi\right) \cdot \left(-\pi\right)}}
\] |
sqrt-unprod [<=]0.0% | \[ \ell \cdot \color{blue}{\left(\sqrt{-\pi} \cdot \sqrt{-\pi}\right)}
\] |
add-sqr-sqrt [<=]6.1% | \[ \ell \cdot \color{blue}{\left(-\pi\right)}
\] |
distribute-rgt-neg-in [<=]6.1% | \[ \color{blue}{-\ell \cdot \pi}
\] |
add-log-exp [=>]100.0% | \[ -\color{blue}{\log \left(e^{\ell \cdot \pi}\right)}
\] |
neg-log [=>]100.0% | \[ \color{blue}{\log \left(\frac{1}{e^{\ell \cdot \pi}}\right)}
\] |
exp-prod [=>]100.0% | \[ \log \left(\frac{1}{\color{blue}{{\left(e^{\ell}\right)}^{\pi}}}\right)
\] |
if -5.0000000000000001e84 < (*.f64 (PI.f64) l) < -5.0000000000000001e26 or 2e11 < (*.f64 (PI.f64) l) < 1.99999999999999985e75Initial program 44.8%
Taylor expanded in l around 0 32.7%
Simplified32.7%
[Start]32.7% | \[ \pi \cdot \ell - \frac{\ell \cdot \pi}{{F}^{2}}
\] |
|---|---|
unpow2 [=>]32.7% | \[ \pi \cdot \ell - \frac{\ell \cdot \pi}{\color{blue}{F \cdot F}}
\] |
times-frac [=>]32.7% | \[ \pi \cdot \ell - \color{blue}{\frac{\ell}{F} \cdot \frac{\pi}{F}}
\] |
Taylor expanded in F around inf 85.5%
if -5.0000000000000001e26 < (*.f64 (PI.f64) l) < 2e11Initial program 91.4%
Applied egg-rr99.6%
[Start]91.4% | \[ \pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\] |
|---|---|
associate-*l/ [=>]91.4% | \[ \pi \cdot \ell - \color{blue}{\frac{1 \cdot \tan \left(\pi \cdot \ell\right)}{F \cdot F}}
\] |
*-un-lft-identity [<=]91.4% | \[ \pi \cdot \ell - \frac{\color{blue}{\tan \left(\pi \cdot \ell\right)}}{F \cdot F}
\] |
associate-/r* [=>]99.6% | \[ \pi \cdot \ell - \color{blue}{\frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}}
\] |
if 1.99999999999999985e75 < (*.f64 (PI.f64) l) Initial program 12.4%
Taylor expanded in l around 0 3.6%
Simplified3.6%
[Start]3.6% | \[ \pi \cdot \ell - \frac{\ell \cdot \pi}{{F}^{2}}
\] |
|---|---|
unpow2 [=>]3.6% | \[ \pi \cdot \ell - \frac{\ell \cdot \pi}{\color{blue}{F \cdot F}}
\] |
times-frac [=>]3.6% | \[ \pi \cdot \ell - \color{blue}{\frac{\ell}{F} \cdot \frac{\pi}{F}}
\] |
Taylor expanded in F around inf 6.2%
Applied egg-rr100.0%
[Start]6.2% | \[ \ell \cdot \pi
\] |
|---|---|
*-commutative [=>]6.2% | \[ \color{blue}{\pi \cdot \ell}
\] |
log1p-expm1-u [=>]100.0% | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot \ell\right)\right)}
\] |
Final simplification97.9%
| Alternative 1 | |
|---|---|
| Accuracy | 97.6% |
| Cost | 45712 |
| Alternative 2 | |
|---|---|
| Accuracy | 92.9% |
| Cost | 52308 |
| Alternative 3 | |
|---|---|
| Accuracy | 86.3% |
| Cost | 45712 |
| Alternative 4 | |
|---|---|
| Accuracy | 94.0% |
| Cost | 39116 |
| Alternative 5 | |
|---|---|
| Accuracy | 94.8% |
| Cost | 39116 |
| Alternative 6 | |
|---|---|
| Accuracy | 70.8% |
| Cost | 13776 |
| Alternative 7 | |
|---|---|
| Accuracy | 71.2% |
| Cost | 13776 |
| Alternative 8 | |
|---|---|
| Accuracy | 76.9% |
| Cost | 13776 |
| Alternative 9 | |
|---|---|
| Accuracy | 57.8% |
| Cost | 7108 |
| Alternative 10 | |
|---|---|
| Accuracy | 63.5% |
| Cost | 7108 |
| Alternative 11 | |
|---|---|
| Accuracy | 44.0% |
| Cost | 6916 |
| Alternative 12 | |
|---|---|
| Accuracy | 44.0% |
| Cost | 6916 |
| Alternative 13 | |
|---|---|
| Accuracy | 37.8% |
| Cost | 6528 |
herbie shell --seed 2023255
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))