| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 33160 |

(FPCore (F B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))
(FPCore (F B x)
:precision binary64
(let* ((t_0 (/ x (tan B))))
(if (<= F -5.2e+15)
(- (/ -1.0 (sin B)) t_0)
(if (<= F 14000000.0)
(fma (/ F (sin B)) (pow (fma x 2.0 (fma F F 2.0)) -0.5) (- t_0))
(- (+ (/ 1.0 (sin B)) (/ (- -1.0 x) (* F (* F (sin B))))) t_0)))))double code(double F, double B, double x) {
return -(x * (1.0 / tan(B))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
double code(double F, double B, double x) {
double t_0 = x / tan(B);
double tmp;
if (F <= -5.2e+15) {
tmp = (-1.0 / sin(B)) - t_0;
} else if (F <= 14000000.0) {
tmp = fma((F / sin(B)), pow(fma(x, 2.0, fma(F, F, 2.0)), -0.5), -t_0);
} else {
tmp = ((1.0 / sin(B)) + ((-1.0 - x) / (F * (F * sin(B))))) - t_0;
}
return tmp;
}
function code(F, B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-Float64(1.0 / 2.0))))) end
function code(F, B, x) t_0 = Float64(x / tan(B)) tmp = 0.0 if (F <= -5.2e+15) tmp = Float64(Float64(-1.0 / sin(B)) - t_0); elseif (F <= 14000000.0) tmp = fma(Float64(F / sin(B)), (fma(x, 2.0, fma(F, F, 2.0)) ^ -0.5), Float64(-t_0)); else tmp = Float64(Float64(Float64(1.0 / sin(B)) + Float64(Float64(-1.0 - x) / Float64(F * Float64(F * sin(B))))) - t_0); end return tmp end
code[F_, B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], (-N[(1.0 / 2.0), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[F_, B_, x_] := Block[{t$95$0 = N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[F, -5.2e+15], N[(N[(-1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[F, 14000000.0], N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(x * 2.0 + N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision] + (-t$95$0)), $MachinePrecision], N[(N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(F * N[(F * N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]]
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\begin{array}{l}
t_0 := \frac{x}{\tan B}\\
\mathbf{if}\;F \leq -5.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{-1}{\sin B} - t_0\\
\mathbf{elif}\;F \leq 14000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{F}{\sin B}, {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}, -t_0\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{1}{\sin B} + \frac{-1 - x}{F \cdot \left(F \cdot \sin B\right)}\right) - t_0\\
\end{array}
Herbie found 25 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if F < -5.2e15Initial program 59.5%
Simplified71.3%
[Start]59.5 | \[ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\] |
|---|---|
+-commutative [=>]59.5 | \[ \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)} + \left(-x \cdot \frac{1}{\tan B}\right)}
\] |
unsub-neg [=>]59.5 | \[ \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)} - x \cdot \frac{1}{\tan B}}
\] |
associate-*l/ [=>]71.4 | \[ \color{blue}{\frac{F \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}}{\sin B}} - x \cdot \frac{1}{\tan B}
\] |
associate-*r/ [<=]71.2 | \[ \color{blue}{F \cdot \frac{{\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}}{\sin B}} - x \cdot \frac{1}{\tan B}
\] |
*-commutative [<=]71.2 | \[ \color{blue}{\frac{{\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}}{\sin B} \cdot F} - x \cdot \frac{1}{\tan B}
\] |
Taylor expanded in F around -inf 99.9%
if -5.2e15 < F < 1.4e7Initial program 99.6%
Simplified99.6%
[Start]99.6 | \[ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\] |
|---|---|
+-commutative [=>]99.6 | \[ \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)} + \left(-x \cdot \frac{1}{\tan B}\right)}
\] |
fma-def [=>]99.6 | \[ \color{blue}{\mathsf{fma}\left(\frac{F}{\sin B}, {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}, -x \cdot \frac{1}{\tan B}\right)}
\] |
+-commutative [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\color{blue}{\left(2 \cdot x + \left(F \cdot F + 2\right)\right)}}^{\left(-\frac{1}{2}\right)}, -x \cdot \frac{1}{\tan B}\right)
\] |
*-commutative [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\left(\color{blue}{x \cdot 2} + \left(F \cdot F + 2\right)\right)}^{\left(-\frac{1}{2}\right)}, -x \cdot \frac{1}{\tan B}\right)
\] |
fma-def [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\color{blue}{\left(\mathsf{fma}\left(x, 2, F \cdot F + 2\right)\right)}}^{\left(-\frac{1}{2}\right)}, -x \cdot \frac{1}{\tan B}\right)
\] |
fma-def [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\left(\mathsf{fma}\left(x, 2, \color{blue}{\mathsf{fma}\left(F, F, 2\right)}\right)\right)}^{\left(-\frac{1}{2}\right)}, -x \cdot \frac{1}{\tan B}\right)
\] |
metadata-eval [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{\left(-\color{blue}{0.5}\right)}, -x \cdot \frac{1}{\tan B}\right)
\] |
metadata-eval [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{\color{blue}{-0.5}}, -x \cdot \frac{1}{\tan B}\right)
\] |
distribute-lft-neg-in [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}, \color{blue}{\left(-x\right) \cdot \frac{1}{\tan B}}\right)
\] |
associate-*r/ [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}, \color{blue}{\frac{\left(-x\right) \cdot 1}{\tan B}}\right)
\] |
*-rgt-identity [=>]99.6 | \[ \mathsf{fma}\left(\frac{F}{\sin B}, {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}, \frac{\color{blue}{-x}}{\tan B}\right)
\] |
if 1.4e7 < F Initial program 69.6%
Simplified81.0%
[Start]69.6 | \[ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\] |
|---|---|
+-commutative [=>]69.6 | \[ \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)} + \left(-x \cdot \frac{1}{\tan B}\right)}
\] |
unsub-neg [=>]69.6 | \[ \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)} - x \cdot \frac{1}{\tan B}}
\] |
associate-*l/ [=>]79.8 | \[ \color{blue}{\frac{F \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}}{\sin B}} - x \cdot \frac{1}{\tan B}
\] |
associate-*r/ [<=]79.7 | \[ \color{blue}{F \cdot \frac{{\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}}{\sin B}} - x \cdot \frac{1}{\tan B}
\] |
*-commutative [<=]79.7 | \[ \color{blue}{\frac{{\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}}{\sin B} \cdot F} - x \cdot \frac{1}{\tan B}
\] |
Applied egg-rr81.1%
[Start]81.0 | \[ F \cdot \frac{{\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}{\sin B} - \frac{x}{\tan B}
\] |
|---|---|
associate-*r/ [=>]81.1 | \[ \color{blue}{\frac{F \cdot {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}{\sin B}} - \frac{x}{\tan B}
\] |
Taylor expanded in F around inf 98.5%
Simplified99.8%
[Start]98.5 | \[ \left(-0.5 \cdot \frac{2 + 2 \cdot x}{\sin B \cdot {F}^{2}} + \frac{1}{\sin B}\right) - \frac{x}{\tan B}
\] |
|---|---|
+-commutative [=>]98.5 | \[ \color{blue}{\left(\frac{1}{\sin B} + -0.5 \cdot \frac{2 + 2 \cdot x}{\sin B \cdot {F}^{2}}\right)} - \frac{x}{\tan B}
\] |
associate-*r/ [=>]98.5 | \[ \left(\frac{1}{\sin B} + \color{blue}{\frac{-0.5 \cdot \left(2 + 2 \cdot x\right)}{\sin B \cdot {F}^{2}}}\right) - \frac{x}{\tan B}
\] |
distribute-lft-in [=>]98.5 | \[ \left(\frac{1}{\sin B} + \frac{\color{blue}{-0.5 \cdot 2 + -0.5 \cdot \left(2 \cdot x\right)}}{\sin B \cdot {F}^{2}}\right) - \frac{x}{\tan B}
\] |
metadata-eval [=>]98.5 | \[ \left(\frac{1}{\sin B} + \frac{\color{blue}{-1} + -0.5 \cdot \left(2 \cdot x\right)}{\sin B \cdot {F}^{2}}\right) - \frac{x}{\tan B}
\] |
associate-*r* [=>]99.8 | \[ \left(\frac{1}{\sin B} + \frac{-1 + \color{blue}{\left(-0.5 \cdot 2\right) \cdot x}}{\sin B \cdot {F}^{2}}\right) - \frac{x}{\tan B}
\] |
metadata-eval [=>]99.8 | \[ \left(\frac{1}{\sin B} + \frac{-1 + \color{blue}{-1} \cdot x}{\sin B \cdot {F}^{2}}\right) - \frac{x}{\tan B}
\] |
mul-1-neg [=>]99.8 | \[ \left(\frac{1}{\sin B} + \frac{-1 + \color{blue}{\left(-x\right)}}{\sin B \cdot {F}^{2}}\right) - \frac{x}{\tan B}
\] |
*-commutative [=>]99.8 | \[ \left(\frac{1}{\sin B} + \frac{-1 + \left(-x\right)}{\color{blue}{{F}^{2} \cdot \sin B}}\right) - \frac{x}{\tan B}
\] |
unpow2 [=>]99.8 | \[ \left(\frac{1}{\sin B} + \frac{-1 + \left(-x\right)}{\color{blue}{\left(F \cdot F\right)} \cdot \sin B}\right) - \frac{x}{\tan B}
\] |
associate-*l* [=>]99.8 | \[ \left(\frac{1}{\sin B} + \frac{-1 + \left(-x\right)}{\color{blue}{F \cdot \left(F \cdot \sin B\right)}}\right) - \frac{x}{\tan B}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 33160 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 20744 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 20740 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 20552 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 20424 |
| Alternative 6 | |
|---|---|
| Accuracy | 91.9% |
| Cost | 20360 |
| Alternative 7 | |
|---|---|
| Accuracy | 88.9% |
| Cost | 14480 |
| Alternative 8 | |
|---|---|
| Accuracy | 84.7% |
| Cost | 14156 |
| Alternative 9 | |
|---|---|
| Accuracy | 64.3% |
| Cost | 14044 |
| Alternative 10 | |
|---|---|
| Accuracy | 64.3% |
| Cost | 14044 |
| Alternative 11 | |
|---|---|
| Accuracy | 84.7% |
| Cost | 13900 |
| Alternative 12 | |
|---|---|
| Accuracy | 84.7% |
| Cost | 13644 |
| Alternative 13 | |
|---|---|
| Accuracy | 77.3% |
| Cost | 13516 |
| Alternative 14 | |
|---|---|
| Accuracy | 63.9% |
| Cost | 7896 |
| Alternative 15 | |
|---|---|
| Accuracy | 65.2% |
| Cost | 7768 |
| Alternative 16 | |
|---|---|
| Accuracy | 58.3% |
| Cost | 7581 |
| Alternative 17 | |
|---|---|
| Accuracy | 43.4% |
| Cost | 7120 |
| Alternative 18 | |
|---|---|
| Accuracy | 44.0% |
| Cost | 6988 |
| Alternative 19 | |
|---|---|
| Accuracy | 43.6% |
| Cost | 904 |
| Alternative 20 | |
|---|---|
| Accuracy | 43.6% |
| Cost | 840 |
| Alternative 21 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 584 |
| Alternative 22 | |
|---|---|
| Accuracy | 30.6% |
| Cost | 521 |
| Alternative 23 | |
|---|---|
| Accuracy | 36.7% |
| Cost | 452 |
| Alternative 24 | |
|---|---|
| Accuracy | 10.7% |
| Cost | 192 |
herbie shell --seed 2023160
(FPCore (F B x)
:name "VandenBroeck and Keller, Equation (23)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))