| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| 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 -2e+113)
(- (/ -1.0 (sin B)) t_0)
(if (<= F 0.00039)
(- (/ (* F (pow (fma x 2.0 (fma F F 2.0)) -0.5)) (sin B)) t_0)
(- (/ (+ 1.0 (/ (- -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 <= -2e+113) {
tmp = (-1.0 / sin(B)) - t_0;
} else if (F <= 0.00039) {
tmp = ((F * pow(fma(x, 2.0, fma(F, F, 2.0)), -0.5)) / sin(B)) - t_0;
} else {
tmp = ((1.0 + ((-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 <= -2e+113) tmp = Float64(Float64(-1.0 / sin(B)) - t_0); elseif (F <= 0.00039) tmp = Float64(Float64(Float64(F * (fma(x, 2.0, fma(F, F, 2.0)) ^ -0.5)) / sin(B)) - t_0); else tmp = Float64(Float64(Float64(1.0 + Float64(Float64(-1.0 - x) / Float64(F * 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, -2e+113], N[(N[(-1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[F, 0.00039], N[(N[(N[(F * N[Power[N[(x * 2.0 + N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(N[(N[(1.0 + N[(N[(-1.0 - x), $MachinePrecision] / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sin[B], $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 -2 \cdot 10^{+113}:\\
\;\;\;\;\frac{-1}{\sin B} - t_0\\
\mathbf{elif}\;F \leq 0.00039:\\
\;\;\;\;\frac{F \cdot {\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}{\sin B} - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + \frac{-1 - x}{F \cdot F}}{\sin B} - t_0\\
\end{array}
Herbie found 29 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if F < -2e113Initial program 46.0%
Simplified61.5%
[Start]46.0 | \[ \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 [=>]46.0 | \[ \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 [=>]46.0 | \[ \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/ [=>]61.5 | \[ \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/ [<=]61.6 | \[ \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 [<=]61.6 | \[ \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.8%
if -2e113 < F < 3.89999999999999993e-4Initial program 98.7%
Simplified99.7%
[Start]98.7 | \[ \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 [=>]98.7 | \[ \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 [=>]98.7 | \[ \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/ [=>]99.5 | \[ \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/ [<=]99.4 | \[ \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 [<=]99.4 | \[ \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-rr99.8%
[Start]99.7 | \[ 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/ [=>]99.8 | \[ \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}
\] |
if 3.89999999999999993e-4 < F Initial program 57.5%
Simplified77.6%
[Start]57.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 [=>]57.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 [=>]57.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/ [=>]77.6 | \[ \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/ [<=]77.5 | \[ \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 [<=]77.5 | \[ \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-rr77.7%
[Start]77.6 | \[ 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/ [=>]77.7 | \[ \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 99.8%
Simplified99.8%
[Start]99.8 | \[ \frac{1 + -0.5 \cdot \frac{2 + 2 \cdot x}{{F}^{2}}}{\sin B} - \frac{x}{\tan B}
\] |
|---|---|
associate-*r/ [=>]99.8 | \[ \frac{1 + \color{blue}{\frac{-0.5 \cdot \left(2 + 2 \cdot x\right)}{{F}^{2}}}}{\sin B} - \frac{x}{\tan B}
\] |
distribute-lft-in [=>]99.8 | \[ \frac{1 + \frac{\color{blue}{-0.5 \cdot 2 + -0.5 \cdot \left(2 \cdot x\right)}}{{F}^{2}}}{\sin B} - \frac{x}{\tan B}
\] |
metadata-eval [=>]99.8 | \[ \frac{1 + \frac{\color{blue}{-1} + -0.5 \cdot \left(2 \cdot x\right)}{{F}^{2}}}{\sin B} - \frac{x}{\tan B}
\] |
associate-*r* [=>]99.8 | \[ \frac{1 + \frac{-1 + \color{blue}{\left(-0.5 \cdot 2\right) \cdot x}}{{F}^{2}}}{\sin B} - \frac{x}{\tan B}
\] |
metadata-eval [=>]99.8 | \[ \frac{1 + \frac{-1 + \color{blue}{-1} \cdot x}{{F}^{2}}}{\sin B} - \frac{x}{\tan B}
\] |
mul-1-neg [=>]99.8 | \[ \frac{1 + \frac{-1 + \color{blue}{\left(-x\right)}}{{F}^{2}}}{\sin B} - \frac{x}{\tan B}
\] |
unpow2 [=>]99.8 | \[ \frac{1 + \frac{-1 + \left(-x\right)}{\color{blue}{F \cdot F}}}{\sin B} - \frac{x}{\tan B}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 33160 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 33160 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 27144 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 20744 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 20744 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 20040 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 20040 |
| Alternative 8 | |
|---|---|
| Accuracy | 88.3% |
| Cost | 14288 |
| Alternative 9 | |
|---|---|
| Accuracy | 91.5% |
| Cost | 14024 |
| Alternative 10 | |
|---|---|
| Accuracy | 91.5% |
| Cost | 14024 |
| Alternative 11 | |
|---|---|
| Accuracy | 84.0% |
| Cost | 13512 |
| Alternative 12 | |
|---|---|
| Accuracy | 71.0% |
| Cost | 13448 |
| Alternative 13 | |
|---|---|
| Accuracy | 71.0% |
| Cost | 13448 |
| Alternative 14 | |
|---|---|
| Accuracy | 71.0% |
| Cost | 13448 |
| Alternative 15 | |
|---|---|
| Accuracy | 77.9% |
| Cost | 13448 |
| Alternative 16 | |
|---|---|
| Accuracy | 60.6% |
| Cost | 7897 |
| Alternative 17 | |
|---|---|
| Accuracy | 62.9% |
| Cost | 7765 |
| Alternative 18 | |
|---|---|
| Accuracy | 59.9% |
| Cost | 7509 |
| Alternative 19 | |
|---|---|
| Accuracy | 55.2% |
| Cost | 7508 |
| Alternative 20 | |
|---|---|
| Accuracy | 44.6% |
| Cost | 6856 |
| Alternative 21 | |
|---|---|
| Accuracy | 43.9% |
| Cost | 6724 |
| Alternative 22 | |
|---|---|
| Accuracy | 42.6% |
| Cost | 968 |
| Alternative 23 | |
|---|---|
| Accuracy | 42.6% |
| Cost | 968 |
| Alternative 24 | |
|---|---|
| Accuracy | 42.4% |
| Cost | 708 |
| Alternative 25 | |
|---|---|
| Accuracy | 42.3% |
| Cost | 584 |
| Alternative 26 | |
|---|---|
| Accuracy | 35.5% |
| Cost | 452 |
| Alternative 27 | |
|---|---|
| Accuracy | 28.4% |
| Cost | 256 |
| Alternative 28 | |
|---|---|
| Accuracy | 10.6% |
| Cost | 192 |
herbie shell --seed 2023161
(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))))))