?

Average Error: 16.6 → 16.6
Time: 25.8s
Precision: binary64
Cost: 39232

?

\[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
\[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right)\right) \cdot R \]
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (+
    (* (sin phi1) (sin phi2))
    (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
  R))
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  (acos
   (+
    (* (sin phi1) (sin phi2))
    (* (cos phi1) (* (cos (- lambda1 lambda2)) (cos phi2)))))
  R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos((lambda1 - lambda2)) * cos(phi2))))) * R;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * r
end function
real(8) function code(r, lambda1, lambda2, phi1, phi2)
    real(8), intent (in) :: r
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: lambda2
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    code = acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos((lambda1 - lambda2)) * cos(phi2))))) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) * R;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi1) * (Math.cos((lambda1 - lambda2)) * Math.cos(phi2))))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2):
	return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) * R
def code(R, lambda1, lambda2, phi1, phi2):
	return math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi1) * (math.cos((lambda1 - lambda2)) * math.cos(phi2))))) * R
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R)
end
function code(R, lambda1, lambda2, phi1, phi2)
	return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi1) * Float64(cos(Float64(lambda1 - lambda2)) * cos(phi2))))) * R)
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
end
function tmp = code(R, lambda1, lambda2, phi1, phi2)
	tmp = acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos((lambda1 - lambda2)) * cos(phi2))))) * R;
end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right)\right) \cdot R

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 16.6

    \[\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]
  2. Simplified16.6

    \[\leadsto \color{blue}{\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right)\right) \cdot R} \]
    Proof

    [Start]16.6

    \[ \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R \]

    rational_best_oopsla_all_46_json_45_simplify-74 [=>]16.6

    \[ \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \color{blue}{\cos \left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)}\right) \cdot R \]

    rational_best_oopsla_all_46_json_45_simplify-7 [=>]16.6

    \[ \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \color{blue}{\cos \phi_1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right)}\right) \cdot R \]
  3. Final simplification16.6

    \[\leadsto \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right)\right) \cdot R \]

Alternatives

Alternative 1
Error16.9
Cost39432
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ t_1 := \cos^{-1} \left(t_0 + \cos \phi_1 \cdot \left(\cos \left(-\lambda_2\right) \cdot \cos \phi_2\right)\right) \cdot R\\ \mathbf{if}\;\lambda_2 \leq -5 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\lambda_2 \leq 2.8 \cdot 10^{-18}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error23.5
Cost39368
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\lambda_2 \leq -0.007:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\lambda_2 \leq 0.00041:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot \cos \lambda_1\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \end{array} \]
Alternative 3
Error16.6
Cost39232
\[\cos^{-1} \left(\cos \phi_2 \cdot \left(\cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right) + \sin \phi_1 \cdot \sin \phi_2\right) \cdot R \]
Alternative 4
Error30.0
Cost33096
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_1 \leq -1.35 \cdot 10^{+130}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 145:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_2 \cdot \cos \phi_1\right) \cdot R\\ \end{array} \]
Alternative 5
Error29.1
Cost33096
\[\begin{array}{l} t_0 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_1 \leq -200000:\\ \;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \phi_2 + t_0\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 1950000:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + t_0\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \cos \phi_1\right) \cdot R\\ \end{array} \]
Alternative 6
Error29.7
Cost32972
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_1 \leq -1.4 \cdot 10^{+222}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -0.35:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 0.00092:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_2 \cdot \cos \phi_1\right) \cdot R\\ \end{array} \]
Alternative 7
Error29.5
Cost32840
\[\begin{array}{l} t_0 := \sin \phi_1 \cdot \sin \phi_2\\ \mathbf{if}\;\phi_1 \leq -0.00165:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 0.014:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_2 \cdot \cos \phi_1\right) \cdot R\\ \end{array} \]
Alternative 8
Error35.4
Cost32708
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq -0.0024:\\ \;\;\;\;\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\ \end{array} \]
Alternative 9
Error39.9
Cost26572
\[\begin{array}{l} t_0 := \phi_1 \cdot \sin \phi_2\\ t_1 := \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{if}\;\lambda_2 \leq -1.15 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\lambda_2 \leq 2.3 \cdot 10^{-250}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_2 \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{elif}\;\lambda_2 \leq 5.2 \cdot 10^{-12}:\\ \;\;\;\;\cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error37.9
Cost26568
\[\begin{array}{l} t_0 := \phi_1 \cdot \sin \phi_2\\ t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\ \mathbf{if}\;\phi_1 \leq -1.25 \cdot 10^{+221}:\\ \;\;\;\;\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq -0.0014:\\ \;\;\;\;\cos^{-1} \left(t_0 + t_1 \cdot \cos \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(t_0 + t_1 \cdot \cos \phi_2\right) \cdot R\\ \end{array} \]
Alternative 11
Error42.7
Cost26440
\[\begin{array}{l} t_0 := \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{if}\;\phi_1 \leq -2.75 \cdot 10^{+219}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq -1.95 \cdot 10^{-25}:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \lambda_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 2.45 \cdot 10^{-219}:\\ \;\;\;\;\cos^{-1} \left(\phi_2 \cdot \phi_1 + \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error40.9
Cost26436
\[\begin{array}{l} \mathbf{if}\;\phi_2 \leq 3.5 \cdot 10^{-6}:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \end{array} \]
Alternative 13
Error43.3
Cost20300
\[\begin{array}{l} t_0 := \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{if}\;\phi_1 \leq -3 \cdot 10^{+218}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq -270000:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_1\right) \cdot R\\ \mathbf{elif}\;\phi_1 \leq 1.3 \cdot 10^{-219}:\\ \;\;\;\;\cos^{-1} \left(\phi_2 \cdot \phi_1 + \cos \left(\lambda_1 - \lambda_2\right) \cdot \cos \phi_2\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 14
Error44.2
Cost19912
\[\begin{array}{l} t_0 := \cos^{-1} \left(\cos \phi_2 \cdot \cos \left(-\lambda_2\right)\right) \cdot R\\ \mathbf{if}\;\phi_1 \leq -3 \cdot 10^{+218}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\phi_1 \leq -25000:\\ \;\;\;\;\cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_1\right) \cdot R\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 15
Error44.0
Cost19584
\[\cos^{-1} \left(\cos \phi_2 \cdot \cos \left(-\lambda_2\right)\right) \cdot R \]
Alternative 16
Error52.6
Cost13056
\[\cos^{-1} \cos \left(-\lambda_2\right) \cdot R \]
Alternative 17
Error60.9
Cost256
\[\left(-\lambda_2\right) \cdot R \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Spherical law of cosines"
  :precision binary64
  (* (acos (+ (* (sin phi1) (sin phi2)) (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2))))) R))