Average Error: 13.9 → 0.3
Time: 5.2min
Precision: binary64
Cost: 20802
\[\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 -1.7345000061794282 \cdot 10^{+23}:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq 458314.3485299576:\\
\;\;\;\;\frac{F}{\sin B} \cdot \sqrt{\frac{1}{F \cdot F + 2}} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \left(\frac{x}{F \cdot F} + \frac{1}{F \cdot F}\right)}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
\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 -1.7345000061794282 \cdot 10^{+23}:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq 458314.3485299576:\\
\;\;\;\;\frac{F}{\sin B} \cdot \sqrt{\frac{1}{F \cdot F + 2}} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \left(\frac{x}{F \cdot F} + \frac{1}{F \cdot F}\right)}{\sin B} - \frac{x}{\tan B}\\
\end{array}(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 -1.7345000061794282e+23)
(- (/ -1.0 (sin B)) (/ x (tan B)))
(if (<= F 458314.3485299576)
(- (* (/ F (sin B)) (sqrt (/ 1.0 (+ (* F F) 2.0)))) (/ x (tan B)))
(- (/ (- 1.0 (+ (/ x (* F F)) (/ 1.0 (* F F)))) (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 <= -1.7345000061794282e+23) {
tmp = (-1.0 / sin(B)) - (x / tan(B));
} else if (F <= 458314.3485299576) {
tmp = ((F / sin(B)) * sqrt(1.0 / ((F * F) + 2.0))) - (x / tan(B));
} else {
tmp = ((1.0 - ((x / (F * F)) + (1.0 / (F * F)))) / sin(B)) - (x / tan(B));
}
return tmp;
}
Try it out
Enter valid numbers for all inputs
Alternatives
| Alternative 1 |
|---|
| Error | 0.2 |
|---|
| Cost | 20802 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -129820715864368.95:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq 458314.3485299576:\\
\;\;\;\;\frac{F \cdot \sqrt{\frac{1}{F \cdot F + 2}}}{\sin B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \left(\frac{x}{F \cdot F} + \frac{1}{F \cdot F}\right)}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 2 |
|---|
| Error | 4.9 |
|---|
| Cost | 14979 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -848392.7563719586:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq -7.932951086476523 \cdot 10^{-81}:\\
\;\;\;\;\frac{F \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5}}{\sin B} - \frac{x}{B}\\
\mathbf{elif}\;F \leq 560.3737196529521:\\
\;\;\;\;{\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5} \cdot \frac{F}{B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \left(\frac{x}{F \cdot F} + \frac{1}{F \cdot F}\right)}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 3 |
|---|
| Error | 5.0 |
|---|
| Cost | 14915 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -4645.146492727445:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq -8.149321183500055 \cdot 10^{-84}:\\
\;\;\;\;\frac{F \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5}}{\sin B} - \frac{x}{B}\\
\mathbf{elif}\;F \leq 469799.4013418561:\\
\;\;\;\;{\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5} \cdot \frac{F}{B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 4 |
|---|
| Error | 7.5 |
|---|
| Cost | 15236 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -1.7345000061794282 \cdot 10^{+23}:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq -2.552488465105514 \cdot 10^{-238}:\\
\;\;\;\;\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5} - \frac{x}{B}\\
\mathbf{elif}\;F \leq 1.1982040141203165 \cdot 10^{-110}:\\
\;\;\;\;\frac{x}{-\sin B} \cdot \cos B\\
\mathbf{elif}\;F \leq 0.4800257531838484:\\
\;\;\;\;\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 5 |
|---|
| Error | 7.4 |
|---|
| Cost | 15236 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -203633.2232100348:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq -1.0689241364748001 \cdot 10^{-237}:\\
\;\;\;\;\frac{F \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5}}{\sin B} - \frac{x}{B}\\
\mathbf{elif}\;F \leq 2.2638668393559438 \cdot 10^{-110}:\\
\;\;\;\;\frac{x}{-\sin B} \cdot \cos B\\
\mathbf{elif}\;F \leq 0.4800257531838484:\\
\;\;\;\;\frac{F \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5}}{\sin B} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 6 |
|---|
| Error | 10.9 |
|---|
| Cost | 13890 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -2.1857821194708164 \cdot 10^{-80}:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq 4.8963945120059034 \cdot 10^{-24}:\\
\;\;\;\;\frac{x}{-\sin B} \cdot \cos B\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 7 |
|---|
| Error | 15.5 |
|---|
| Cost | 13826 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -2.1857821194708164 \cdot 10^{-80}:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq 16.889853377425982:\\
\;\;\;\;\frac{x}{-\sin B} \cdot \cos B\\
\mathbf{elif}\;F \leq 4.7101697855186315 \cdot 10^{+135}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 8 |
|---|
| Error | 25.0 |
|---|
| Cost | 13505 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq 11.659649337890587:\\
\;\;\;\;\frac{x}{-\sin B} \cdot \cos B\\
\mathbf{elif}\;F \leq 6.737354207850628 \cdot 10^{+135}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\end{array}\]
| Alternative 9 |
|---|
| Error | 32.6 |
|---|
| Cost | 8460 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq -1.6375294095987955 \cdot 10^{-166}:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq -3.289141569193918 \cdot 10^{-241}:\\
\;\;\;\;-\frac{x}{B}\\
\mathbf{elif}\;F \leq 4.544496888397481 \cdot 10^{-280}:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq 1.1079463367285392 \cdot 10^{-185}:\\
\;\;\;\;-\frac{x}{B}\\
\mathbf{elif}\;F \leq 283783.38273218885 \lor \neg \left(F \leq 4.502361933676628 \cdot 10^{+137}\right):\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\end{array}\]
| Alternative 10 |
|---|
| Error | 39.7 |
|---|
| Cost | 7169 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq 1.7163339963652113 \cdot 10^{-130}:\\
\;\;\;\;-\frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\end{array}\]
| Alternative 11 |
|---|
| Error | 42.5 |
|---|
| Cost | 6913 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq 3.2549820013808687 \cdot 10^{-130}:\\
\;\;\;\;-\frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}\]
| Alternative 12 |
|---|
| Error | 44.6 |
|---|
| Cost | 641 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq 4.165783766895228 \cdot 10^{-87}:\\
\;\;\;\;-\frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{B}\\
\end{array}\]
| Alternative 13 |
|---|
| Error | 47.3 |
|---|
| Cost | 577 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq 5.841025508043288 \cdot 10^{-87}:\\
\;\;\;\;-\frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}\]
| Alternative 14 |
|---|
| Error | 56.4 |
|---|
| Cost | 513 |
|---|
\[\begin{array}{l}
\mathbf{if}\;F \leq 2.855296916216521 \cdot 10^{-127}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}\]
| Alternative 15 |
|---|
| Error | 61.0 |
|---|
| Cost | 64 |
|---|
\[1\]
Error

Time

Derivation
- Split input into 3 regimes
if F < -1.73450000617942817e23
Initial program 26.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)}\]
Simplified26.4
\[\leadsto \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5} - \frac{x}{\tan B}}\]
Taylor expanded around -inf 0.2
\[\leadsto \color{blue}{\frac{-1}{\sin B}} - \frac{x}{\tan B}\]
Simplified0.2
\[\leadsto \color{blue}{\frac{-1}{\sin B} - \frac{x}{\tan B}}\]
if -1.73450000617942817e23 < F < 458314.34852995758
Initial program 0.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)}\]
Simplified0.3
\[\leadsto \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5} - \frac{x}{\tan B}}\]
Taylor expanded around 0 0.4
\[\leadsto \frac{F}{\sin B} \cdot \color{blue}{\sqrt{\frac{1}{{F}^{2} + 2}}} - \frac{x}{\tan B}\]
Simplified0.4
\[\leadsto \frac{F}{\sin B} \cdot \color{blue}{\sqrt{\frac{1}{F \cdot F + 2}}} - \frac{x}{\tan B}\]
Simplified0.4
\[\leadsto \color{blue}{\frac{F}{\sin B} \cdot \sqrt{\frac{1}{F \cdot F + 2}} - \frac{x}{\tan B}}\]
if 458314.34852995758 < F
Initial program 25.8
\[\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)}\]
Simplified25.7
\[\leadsto \color{blue}{\frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5} - \frac{x}{\tan B}}\]
- Using strategy
rm Applied associate-*l/_binary6419.9
\[\leadsto \color{blue}{\frac{F \cdot {\left(\left(F \cdot F + 2\right) + x \cdot 2\right)}^{-0.5}}{\sin B}} - \frac{x}{\tan B}\]
Simplified19.9
\[\leadsto \frac{\color{blue}{F \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{-0.5}}}{\sin B} - \frac{x}{\tan B}\]
Taylor expanded around inf 0.2
\[\leadsto \frac{\color{blue}{1 - \left(\frac{x}{{F}^{2}} + \frac{1}{{F}^{2}}\right)}}{\sin B} - \frac{x}{\tan B}\]
Simplified0.2
\[\leadsto \frac{\color{blue}{1 - \left(\frac{x}{F \cdot F} + \frac{1}{F \cdot F}\right)}}{\sin B} - \frac{x}{\tan B}\]
Simplified0.2
\[\leadsto \color{blue}{\frac{1 - \left(\frac{x}{F \cdot F} + \frac{1}{F \cdot F}\right)}{\sin B} - \frac{x}{\tan B}}\]
- Recombined 3 regimes into one program.
Final simplification0.3
\[\leadsto \begin{array}{l}
\mathbf{if}\;F \leq -1.7345000061794282 \cdot 10^{+23}:\\
\;\;\;\;\frac{-1}{\sin B} - \frac{x}{\tan B}\\
\mathbf{elif}\;F \leq 458314.3485299576:\\
\;\;\;\;\frac{F}{\sin B} \cdot \sqrt{\frac{1}{F \cdot F + 2}} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \left(\frac{x}{F \cdot F} + \frac{1}{F \cdot F}\right)}{\sin B} - \frac{x}{\tan B}\\
\end{array}\]
Reproduce
herbie shell --seed 2021065
(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))))))