| Alternative 1 | |
|---|---|
| Accuracy | 85.7% |
| Cost | 33672 |
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(sqrt
(+
(*
(* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))
(* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))))
(* (- phi1 phi2) (- phi1 phi2))))))(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(hypot
(*
(- lambda1 lambda2)
(fma
(cos (* 0.5 phi2))
(cos (* 0.5 phi1))
(* (sin (* 0.5 phi1)) (sin (* phi2 -0.5)))))
(- phi1 phi2))))double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * sqrt(((((lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0))) * ((lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0)))) + ((phi1 - phi2) * (phi1 - phi2))));
}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * hypot(((lambda1 - lambda2) * fma(cos((0.5 * phi2)), cos((0.5 * phi1)), (sin((0.5 * phi1)) * sin((phi2 * -0.5))))), (phi1 - phi2));
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * sqrt(Float64(Float64(Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0))) * Float64(Float64(lambda1 - lambda2) * cos(Float64(Float64(phi1 + phi2) / 2.0)))) + Float64(Float64(phi1 - phi2) * Float64(phi1 - phi2))))) end
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * hypot(Float64(Float64(lambda1 - lambda2) * fma(cos(Float64(0.5 * phi2)), cos(Float64(0.5 * phi1)), Float64(sin(Float64(0.5 * phi1)) * sin(Float64(phi2 * -0.5))))), Float64(phi1 - phi2))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(lambda1 - lambda2), $MachinePrecision] * N[Cos[N[(N[(phi1 + phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(phi1 - phi2), $MachinePrecision] * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[Sqrt[N[(N[(lambda1 - lambda2), $MachinePrecision] * N[(N[Cos[N[(0.5 * phi2), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2 + N[(phi1 - phi2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]
R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\phi_2 \cdot -0.5\right)\right), \phi_1 - \phi_2\right)
Initial program 39.2%
Simplified94.2%
[Start]39.2 | \[ R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\] |
|---|---|
hypot-def [=>]94.2 | \[ R \cdot \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)}
\] |
Applied egg-rr94.2%
[Start]94.2 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right), \phi_1 - \phi_2\right)
\] |
|---|---|
expm1-log1p-u [=>]94.2 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)\right)}, \phi_1 - \phi_2\right)
\] |
div-inv [=>]94.2 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \color{blue}{\left(\left(\phi_1 + \phi_2\right) \cdot \frac{1}{2}\right)}\right)\right), \phi_1 - \phi_2\right)
\] |
metadata-eval [=>]94.2 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot \color{blue}{0.5}\right)\right)\right), \phi_1 - \phi_2\right)
\] |
Applied egg-rr99.8%
[Start]94.2 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\left(\phi_1 + \phi_2\right) \cdot 0.5\right)\right)\right), \phi_1 - \phi_2\right)
\] |
|---|---|
*-commutative [=>]94.2 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \color{blue}{\left(0.5 \cdot \left(\phi_1 + \phi_2\right)\right)}\right)\right), \phi_1 - \phi_2\right)
\] |
distribute-lft-in [=>]94.2 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \color{blue}{\left(0.5 \cdot \phi_1 + 0.5 \cdot \phi_2\right)}\right)\right), \phi_1 - \phi_2\right)
\] |
cos-sum [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)}\right)\right), \phi_1 - \phi_2\right)
\] |
Simplified99.8%
[Start]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right), \phi_1 - \phi_2\right)
\] |
|---|---|
*-commutative [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} - \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right), \phi_1 - \phi_2\right)
\] |
*-commutative [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \color{blue}{\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right)\right), \phi_1 - \phi_2\right)
\] |
fma-neg [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), -\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}\right)\right), \phi_1 - \phi_2\right)
\] |
distribute-rgt-neg-in [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \color{blue}{\sin \left(0.5 \cdot \phi_2\right) \cdot \left(-\sin \left(0.5 \cdot \phi_1\right)\right)}\right)\right)\right), \phi_1 - \phi_2\right)
\] |
Taylor expanded in phi2 around inf 99.7%
Taylor expanded in phi1 around inf 99.8%
Simplified99.8%
[Start]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) + -1 \cdot \left(\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right), \phi_1 - \phi_2\right)
\] |
|---|---|
neg-mul-1 [<=]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \cos \left(0.5 \cdot \phi_2\right) + \color{blue}{\left(-\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}\right), \phi_1 - \phi_2\right)
\] |
*-commutative [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\color{blue}{\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right)} + \left(-\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)\right), \phi_1 - \phi_2\right)
\] |
fma-def [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), -\sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}, \phi_1 - \phi_2\right)
\] |
distribute-lft-neg-in [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \color{blue}{\left(-\sin \left(0.5 \cdot \phi_2\right)\right) \cdot \sin \left(0.5 \cdot \phi_1\right)}\right), \phi_1 - \phi_2\right)
\] |
sin-neg [<=]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \color{blue}{\sin \left(-0.5 \cdot \phi_2\right)} \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)
\] |
neg-mul-1 [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \color{blue}{\left(-1 \cdot \left(0.5 \cdot \phi_2\right)\right)} \cdot \sin \left(0.5 \cdot \phi_1\right)\right), \phi_1 - \phi_2\right)
\] |
*-commutative [<=]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \color{blue}{\sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(-1 \cdot \left(0.5 \cdot \phi_2\right)\right)}\right), \phi_1 - \phi_2\right)
\] |
rem-square-sqrt [<=]47.5 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(-1 \cdot \color{blue}{\left(\sqrt{0.5 \cdot \phi_2} \cdot \sqrt{0.5 \cdot \phi_2}\right)}\right)\right), \phi_1 - \phi_2\right)
\] |
associate-*l* [<=]47.5 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \color{blue}{\left(\left(-1 \cdot \sqrt{0.5 \cdot \phi_2}\right) \cdot \sqrt{0.5 \cdot \phi_2}\right)}\right), \phi_1 - \phi_2\right)
\] |
neg-mul-1 [<=]47.5 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(\color{blue}{\left(-\sqrt{0.5 \cdot \phi_2}\right)} \cdot \sqrt{0.5 \cdot \phi_2}\right)\right), \phi_1 - \phi_2\right)
\] |
distribute-lft-neg-out [=>]47.5 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \color{blue}{\left(-\sqrt{0.5 \cdot \phi_2} \cdot \sqrt{0.5 \cdot \phi_2}\right)}\right), \phi_1 - \phi_2\right)
\] |
rem-square-sqrt [=>]99.8 | \[ R \cdot \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \mathsf{fma}\left(\cos \left(0.5 \cdot \phi_2\right), \cos \left(0.5 \cdot \phi_1\right), \sin \left(0.5 \cdot \phi_1\right) \cdot \sin \left(-\color{blue}{0.5 \cdot \phi_2}\right)\right), \phi_1 - \phi_2\right)
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 85.7% |
| Cost | 33672 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.4% |
| Cost | 33540 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.6% |
| Cost | 13700 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.5% |
| Cost | 13700 |
| Alternative 5 | |
|---|---|
| Accuracy | 94.1% |
| Cost | 13696 |
| Alternative 6 | |
|---|---|
| Accuracy | 94.2% |
| Cost | 13696 |
| Alternative 7 | |
|---|---|
| Accuracy | 73.2% |
| Cost | 13572 |
| Alternative 8 | |
|---|---|
| Accuracy | 74.4% |
| Cost | 13572 |
| Alternative 9 | |
|---|---|
| Accuracy | 63.8% |
| Cost | 6916 |
| Alternative 10 | |
|---|---|
| Accuracy | 63.8% |
| Cost | 6916 |
| Alternative 11 | |
|---|---|
| Accuracy | 78.7% |
| Cost | 6912 |
| Alternative 12 | |
|---|---|
| Accuracy | 26.1% |
| Cost | 968 |
| Alternative 13 | |
|---|---|
| Accuracy | 26.1% |
| Cost | 712 |
| Alternative 14 | |
|---|---|
| Accuracy | 26.1% |
| Cost | 585 |
| Alternative 15 | |
|---|---|
| Accuracy | 23.6% |
| Cost | 520 |
| Alternative 16 | |
|---|---|
| Accuracy | 24.9% |
| Cost | 388 |
| Alternative 17 | |
|---|---|
| Accuracy | 10.7% |
| Cost | 192 |
| Alternative 18 | |
|---|---|
| Accuracy | 15.5% |
| Cost | 192 |
herbie shell --seed 2023151
(FPCore (R lambda1 lambda2 phi1 phi2)
:name "Equirectangular approximation to distance on a great circle"
:precision binary64
(* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))))