| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 39496 |

(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
(if (<= F -5e+117)
(- (/ -1.0 (sin B)) (* (cos B) (/ x (sin B))))
(if (<= F 20000.0)
(fma (/ F (sin B)) (pow (fma x 2.0 (fma F F 2.0)) -0.5) (/ (- x) (tan B)))
(- (/ 1.0 (sin B)) (/ x (tan B))))))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 tmp;
if (F <= -5e+117) {
tmp = (-1.0 / sin(B)) - (cos(B) * (x / sin(B)));
} else if (F <= 20000.0) {
tmp = fma((F / sin(B)), pow(fma(x, 2.0, fma(F, F, 2.0)), -0.5), (-x / tan(B)));
} else {
tmp = (1.0 / sin(B)) - (x / tan(B));
}
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) tmp = 0.0 if (F <= -5e+117) tmp = Float64(Float64(-1.0 / sin(B)) - Float64(cos(B) * Float64(x / sin(B)))); elseif (F <= 20000.0) tmp = fma(Float64(F / sin(B)), (fma(x, 2.0, fma(F, F, 2.0)) ^ -0.5), Float64(Float64(-x) / tan(B))); else tmp = Float64(Float64(1.0 / sin(B)) - Float64(x / tan(B))); 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_] := If[LessEqual[F, -5e+117], N[(N[(-1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[B], $MachinePrecision] * N[(x / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 20000.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] + N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $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}
\mathbf{if}\;F \leq -5 \cdot 10^{+117}:\\
\;\;\;\;\frac{-1}{\sin B} - \cos B \cdot \frac{x}{\sin B}\\
\mathbf{elif}\;F \leq 20000:\\
\;\;\;\;\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{-x}{\tan B}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{\tan B}\\
\end{array}
Herbie found 28 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if F < -4.99999999999999983e117Initial program 47.7%
Simplified47.7%
[Start]47.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 [=>]47.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)}
\] |
fma-def [=>]47.7% | \[ \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 [=>]47.7% | \[ \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 [=>]47.7% | \[ \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 [=>]47.7% | \[ \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 [=>]47.7% | \[ \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 [=>]47.7% | \[ \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 [=>]47.7% | \[ \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 [=>]47.7% | \[ \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/ [=>]47.7% | \[ \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 [=>]47.7% | \[ \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)
\] |
Taylor expanded in F around -inf 99.8%
Simplified99.8%
[Start]99.8% | \[ -1 \cdot \frac{\cos B \cdot x}{\sin B} - \frac{1}{\sin B}
\] |
|---|---|
mul-1-neg [=>]99.8% | \[ \color{blue}{\left(-\frac{\cos B \cdot x}{\sin B}\right)} - \frac{1}{\sin B}
\] |
*-commutative [=>]99.8% | \[ \left(-\frac{\color{blue}{x \cdot \cos B}}{\sin B}\right) - \frac{1}{\sin B}
\] |
associate-*l/ [<=]99.8% | \[ \left(-\color{blue}{\frac{x}{\sin B} \cdot \cos B}\right) - \frac{1}{\sin B}
\] |
*-commutative [=>]99.8% | \[ \left(-\color{blue}{\cos B \cdot \frac{x}{\sin B}}\right) - \frac{1}{\sin B}
\] |
if -4.99999999999999983e117 < F < 2e4Initial program 99.4%
Simplified99.6%
[Start]99.4% | \[ \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.4% | \[ \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.4% | \[ \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.4% | \[ \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.4% | \[ \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.4% | \[ \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.4% | \[ \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.4% | \[ \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.4% | \[ \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.4% | \[ \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 2e4 < F Initial program 61.0%
Simplified70.4%
[Start]61.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 [=>]61.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 [=>]61.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/ [=>]70.3% | \[ \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/ [<=]70.3% | \[ \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 [<=]70.3% | \[ \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-rr70.4%
[Start]70.4% | \[ 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}
\] |
|---|---|
clear-num [=>]70.4% | \[ F \cdot \color{blue}{\frac{1}{\frac{\sin B}{{\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}}} - \frac{x}{\tan B}
\] |
inv-pow [=>]70.4% | \[ F \cdot \color{blue}{{\left(\frac{\sin B}{{\left(\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}\right)}^{-1}} - \frac{x}{\tan B}
\] |
fma-def [<=]70.4% | \[ F \cdot {\left(\frac{\sin B}{{\left(\mathsf{fma}\left(x, 2, \color{blue}{F \cdot F + 2}\right)\right)}^{-0.5}}\right)}^{-1} - \frac{x}{\tan B}
\] |
fma-udef [=>]70.4% | \[ F \cdot {\left(\frac{\sin B}{{\color{blue}{\left(x \cdot 2 + \left(F \cdot F + 2\right)\right)}}^{-0.5}}\right)}^{-1} - \frac{x}{\tan B}
\] |
*-commutative [<=]70.4% | \[ F \cdot {\left(\frac{\sin B}{{\left(\color{blue}{2 \cdot x} + \left(F \cdot F + 2\right)\right)}^{-0.5}}\right)}^{-1} - \frac{x}{\tan B}
\] |
fma-def [=>]70.4% | \[ F \cdot {\left(\frac{\sin B}{{\color{blue}{\left(\mathsf{fma}\left(2, x, F \cdot F + 2\right)\right)}}^{-0.5}}\right)}^{-1} - \frac{x}{\tan B}
\] |
fma-def [=>]70.4% | \[ F \cdot {\left(\frac{\sin B}{{\left(\mathsf{fma}\left(2, x, \color{blue}{\mathsf{fma}\left(F, F, 2\right)}\right)\right)}^{-0.5}}\right)}^{-1} - \frac{x}{\tan B}
\] |
Simplified70.4%
[Start]70.4% | \[ F \cdot {\left(\frac{\sin B}{{\left(\mathsf{fma}\left(2, x, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}\right)}^{-1} - \frac{x}{\tan B}
\] |
|---|---|
unpow-1 [=>]70.4% | \[ F \cdot \color{blue}{\frac{1}{\frac{\sin B}{{\left(\mathsf{fma}\left(2, x, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}}} - \frac{x}{\tan B}
\] |
Taylor expanded in F around inf 99.6%
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 39496 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 33096 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 20744 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 20616 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 20424 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 20424 |
| Alternative 7 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 20040 |
| Alternative 8 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 20040 |
| Alternative 9 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 20040 |
| Alternative 10 | |
|---|---|
| Accuracy | 92.5% |
| Cost | 14476 |
| Alternative 11 | |
|---|---|
| Accuracy | 92.4% |
| Cost | 14348 |
| Alternative 12 | |
|---|---|
| Accuracy | 92.1% |
| Cost | 14156 |
| Alternative 13 | |
|---|---|
| Accuracy | 91.1% |
| Cost | 14024 |
| Alternative 14 | |
|---|---|
| Accuracy | 91.2% |
| Cost | 14024 |
| Alternative 15 | |
|---|---|
| Accuracy | 68.0% |
| Cost | 13712 |
| Alternative 16 | |
|---|---|
| Accuracy | 67.4% |
| Cost | 13712 |
| Alternative 17 | |
|---|---|
| Accuracy | 84.5% |
| Cost | 13644 |
| Alternative 18 | |
|---|---|
| Accuracy | 76.7% |
| Cost | 13580 |
| Alternative 19 | |
|---|---|
| Accuracy | 58.9% |
| Cost | 7817 |
| Alternative 20 | |
|---|---|
| Accuracy | 59.1% |
| Cost | 7628 |
| Alternative 21 | |
|---|---|
| Accuracy | 56.2% |
| Cost | 7377 |
| Alternative 22 | |
|---|---|
| Accuracy | 57.9% |
| Cost | 7377 |
| Alternative 23 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 7113 |
| Alternative 24 | |
|---|---|
| Accuracy | 38.2% |
| Cost | 6788 |
| Alternative 25 | |
|---|---|
| Accuracy | 36.3% |
| Cost | 1220 |
| Alternative 26 | |
|---|---|
| Accuracy | 36.3% |
| Cost | 708 |
| Alternative 27 | |
|---|---|
| Accuracy | 35.7% |
| Cost | 452 |
| Alternative 28 | |
|---|---|
| Accuracy | 28.9% |
| Cost | 256 |
herbie shell --seed 2023165
(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))))))