
(FPCore (A B C) :precision binary64 (* 180.0 (/ (atan (* (/ 1.0 B) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))) (PI))))
\begin{array}{l}
\\
180 \cdot \frac{\tan^{-1} \left(\frac{1}{B} \cdot \left(\left(C - A\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)\right)}{\mathsf{PI}\left(\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (A B C) :precision binary64 (* 180.0 (/ (atan (* (/ 1.0 B) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))) (PI))))
\begin{array}{l}
\\
180 \cdot \frac{\tan^{-1} \left(\frac{1}{B} \cdot \left(\left(C - A\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)\right)}{\mathsf{PI}\left(\right)}
\end{array}
(FPCore (A B C) :precision binary64 (if (<= C 7.4e+96) (* (/ 180.0 (PI)) (atan (/ (- (- C (hypot (- A C) B)) A) B))) (* 180.0 (/ (atan (* (/ B C) -0.5)) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;C \leq 7.4 \cdot 10^{+96}:\\
\;\;\;\;\frac{180}{\mathsf{PI}\left(\right)} \cdot \tan^{-1} \left(\frac{\left(C - \mathsf{hypot}\left(A - C, B\right)\right) - A}{B}\right)\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{C} \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if C < 7.39999999999999982e96Initial program 64.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites82.5%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f6476.7
lift-hypot.f64N/A
+-commutativeN/A
lower-hypot.f6476.7
Applied rewrites76.7%
Taylor expanded in C around -inf
Applied rewrites77.9%
Taylor expanded in A around -inf
Applied rewrites83.6%
if 7.39999999999999982e96 < C Initial program 9.2%
Taylor expanded in B around inf
Applied rewrites11.5%
Taylor expanded in C around inf
Applied rewrites88.7%
(FPCore (A B C)
:precision binary64
(let* ((t_0
(*
180.0
(/
(atan
(* (/ 1.0 B) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))
(PI))))
(t_1 (/ (- C A) B)))
(if (<= t_0 -40.0)
(* 180.0 (/ (atan (- t_1 1.0)) (PI)))
(if (<= t_0 0.0)
(* 180.0 (/ (atan (* (/ B C) -0.5)) (PI)))
(* 180.0 (/ (atan (+ 1.0 t_1)) (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 180 \cdot \frac{\tan^{-1} \left(\frac{1}{B} \cdot \left(\left(C - A\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)\right)}{\mathsf{PI}\left(\right)}\\
t_1 := \frac{C - A}{B}\\
\mathbf{if}\;t\_0 \leq -40:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(t\_1 - 1\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{C} \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(1 + t\_1\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if (*.f64 #s(literal 180 binary64) (/.f64 (atan.f64 (*.f64 (/.f64 #s(literal 1 binary64) B) (-.f64 (-.f64 C A) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64))))))) (PI.f64))) < -40Initial program 58.0%
Taylor expanded in B around inf
Applied rewrites72.6%
if -40 < (*.f64 #s(literal 180 binary64) (/.f64 (atan.f64 (*.f64 (/.f64 #s(literal 1 binary64) B) (-.f64 (-.f64 C A) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64))))))) (PI.f64))) < -0.0Initial program 11.8%
Taylor expanded in B around inf
Applied rewrites4.2%
Taylor expanded in C around inf
Applied rewrites58.9%
if -0.0 < (*.f64 #s(literal 180 binary64) (/.f64 (atan.f64 (*.f64 (/.f64 #s(literal 1 binary64) B) (-.f64 (-.f64 C A) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64))))))) (PI.f64))) Initial program 64.0%
Taylor expanded in B around -inf
Applied rewrites76.3%
(FPCore (A B C)
:precision binary64
(if (<= C -2.35e-26)
(* 180.0 (/ (atan (- (/ (- C A) B) 1.0)) (PI)))
(if (<= C 1e+97)
(* 180.0 (/ (atan (/ (+ (hypot B A) A) (- B))) (PI)))
(* 180.0 (/ (atan (* (/ B C) -0.5)) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;C \leq -2.35 \cdot 10^{-26}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} - 1\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;C \leq 10^{+97}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\mathsf{hypot}\left(B, A\right) + A}{-B}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{C} \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if C < -2.34999999999999995e-26Initial program 86.6%
Taylor expanded in B around inf
Applied rewrites87.0%
if -2.34999999999999995e-26 < C < 1.0000000000000001e97Initial program 53.2%
Taylor expanded in C around 0
Applied rewrites77.5%
if 1.0000000000000001e97 < C Initial program 9.2%
Taylor expanded in B around inf
Applied rewrites11.5%
Taylor expanded in C around inf
Applied rewrites88.7%
(FPCore (A B C)
:precision binary64
(if (<= A -6.2e-198)
(/ (* 180.0 (atan (* 0.5 (/ B A)))) (PI))
(if (<= A 4.5e-291)
(* 180.0 (/ (atan (* (/ B C) -0.5)) (PI)))
(if (<= A 1.55e-157)
(* 180.0 (/ (atan (* (/ C B) 2.0)) (PI)))
(* 180.0 (/ (atan (* (/ A B) -2.0)) (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -6.2 \cdot 10^{-198}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 4.5 \cdot 10^{-291}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{C} \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 1.55 \cdot 10^{-157}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{C}{B} \cdot 2\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{A}{B} \cdot -2\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -6.1999999999999997e-198Initial program 34.8%
Taylor expanded in A around -inf
Applied rewrites61.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f6461.2
Applied rewrites61.2%
if -6.1999999999999997e-198 < A < 4.49999999999999974e-291Initial program 47.2%
Taylor expanded in B around inf
Applied rewrites27.8%
Taylor expanded in C around inf
Applied rewrites42.9%
if 4.49999999999999974e-291 < A < 1.5499999999999999e-157Initial program 71.5%
Taylor expanded in C around -inf
Applied rewrites61.5%
if 1.5499999999999999e-157 < A Initial program 76.0%
Taylor expanded in A around inf
Applied rewrites60.9%
(FPCore (A B C)
:precision binary64
(if (<= A -6.2e-198)
(* 180.0 (/ (atan (* (/ B A) 0.5)) (PI)))
(if (<= A 4.5e-291)
(* 180.0 (/ (atan (* (/ B C) -0.5)) (PI)))
(if (<= A 1.55e-157)
(* 180.0 (/ (atan (* (/ C B) 2.0)) (PI)))
(* 180.0 (/ (atan (* (/ A B) -2.0)) (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -6.2 \cdot 10^{-198}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{A} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 4.5 \cdot 10^{-291}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{C} \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 1.55 \cdot 10^{-157}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{C}{B} \cdot 2\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{A}{B} \cdot -2\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -6.1999999999999997e-198Initial program 34.8%
Taylor expanded in A around -inf
Applied rewrites61.1%
if -6.1999999999999997e-198 < A < 4.49999999999999974e-291Initial program 47.2%
Taylor expanded in B around inf
Applied rewrites27.8%
Taylor expanded in C around inf
Applied rewrites42.9%
if 4.49999999999999974e-291 < A < 1.5499999999999999e-157Initial program 71.5%
Taylor expanded in C around -inf
Applied rewrites61.5%
if 1.5499999999999999e-157 < A Initial program 76.0%
Taylor expanded in A around inf
Applied rewrites60.9%
(FPCore (A B C)
:precision binary64
(if (<= A -6.2e-198)
(* 180.0 (/ (atan (* (/ B A) 0.5)) (PI)))
(if (<= A 7.6e-185)
(* 180.0 (/ (atan (* (/ B C) -0.5)) (PI)))
(* 180.0 (/ (atan (* (/ A B) -2.0)) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -6.2 \cdot 10^{-198}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{A} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 7.6 \cdot 10^{-185}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{C} \cdot -0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{A}{B} \cdot -2\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -6.1999999999999997e-198Initial program 34.8%
Taylor expanded in A around -inf
Applied rewrites61.1%
if -6.1999999999999997e-198 < A < 7.5999999999999998e-185Initial program 51.4%
Taylor expanded in B around inf
Applied rewrites21.9%
Taylor expanded in C around inf
Applied rewrites36.0%
if 7.5999999999999998e-185 < A Initial program 77.7%
Taylor expanded in A around inf
Applied rewrites59.5%
(FPCore (A B C)
:precision binary64
(if (<= A -5.2e-206)
(* 180.0 (/ (atan (* (/ B A) 0.5)) (PI)))
(if (<= A 7.6e-185)
(* 180.0 (/ (atan 1.0) (PI)))
(* 180.0 (/ (atan (* (/ A B) -2.0)) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -5.2 \cdot 10^{-206}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{A} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 7.6 \cdot 10^{-185}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{A}{B} \cdot -2\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -5.2000000000000001e-206Initial program 35.4%
Taylor expanded in A around -inf
Applied rewrites60.7%
if -5.2000000000000001e-206 < A < 7.5999999999999998e-185Initial program 50.3%
Taylor expanded in B around -inf
Applied rewrites28.3%
if 7.5999999999999998e-185 < A Initial program 77.7%
Taylor expanded in A around inf
Applied rewrites59.5%
(FPCore (A B C)
:precision binary64
(if (<= B -5e-17)
(* 180.0 (/ (atan 1.0) (PI)))
(if (<= B 3e-65)
(* 180.0 (/ (atan (* (/ A B) -2.0)) (PI)))
(* 180.0 (/ (atan -1.0) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -5 \cdot 10^{-17}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;B \leq 3 \cdot 10^{-65}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{A}{B} \cdot -2\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if B < -4.9999999999999999e-17Initial program 59.0%
Taylor expanded in B around -inf
Applied rewrites62.5%
if -4.9999999999999999e-17 < B < 2.99999999999999998e-65Initial program 59.3%
Taylor expanded in A around inf
Applied rewrites40.2%
if 2.99999999999999998e-65 < B Initial program 49.0%
Taylor expanded in B around inf
Applied rewrites50.5%
(FPCore (A B C) :precision binary64 (if (<= A -6.2e+48) (/ (* 180.0 (atan (* 0.5 (/ B A)))) (PI)) (* 180.0 (/ (atan (+ 1.0 (/ (- C A) B))) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -6.2 \cdot 10^{+48}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(1 + \frac{C - A}{B}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -6.20000000000000011e48Initial program 15.6%
Taylor expanded in A around -inf
Applied rewrites76.5%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f6476.6
Applied rewrites76.6%
if -6.20000000000000011e48 < A Initial program 68.1%
Taylor expanded in B around -inf
Applied rewrites64.6%
(FPCore (A B C)
:precision binary64
(if (<= B -1.2e-131)
(* 180.0 (/ (atan 1.0) (PI)))
(if (<= B 7.5e-108)
(* 180.0 (/ (atan 0.0) (PI)))
(* 180.0 (/ (atan -1.0) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -1.2 \cdot 10^{-131}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;B \leq 7.5 \cdot 10^{-108}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 0}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if B < -1.2e-131Initial program 58.0%
Taylor expanded in B around -inf
Applied rewrites49.1%
if -1.2e-131 < B < 7.4999999999999993e-108Initial program 59.8%
Taylor expanded in B around inf
Applied rewrites7.3%
Taylor expanded in C around inf
Applied rewrites31.6%
if 7.4999999999999993e-108 < B Initial program 50.4%
Taylor expanded in B around inf
Applied rewrites48.9%
(FPCore (A B C) :precision binary64 (if (<= B 7.5e-108) (* 180.0 (/ (atan 0.0) (PI))) (* 180.0 (/ (atan -1.0) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 7.5 \cdot 10^{-108}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 0}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if B < 7.4999999999999993e-108Initial program 58.9%
Taylor expanded in B around inf
Applied rewrites4.6%
Taylor expanded in C around inf
Applied rewrites18.4%
if 7.4999999999999993e-108 < B Initial program 50.4%
Taylor expanded in B around inf
Applied rewrites48.9%
(FPCore (A B C) :precision binary64 (* 180.0 (/ (atan -1.0) (PI))))
\begin{array}{l}
\\
180 \cdot \frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 56.2%
Taylor expanded in B around inf
Applied rewrites18.6%
herbie shell --seed 2025019
(FPCore (A B C)
:name "ABCF->ab-angle angle"
:precision binary64
(* 180.0 (/ (atan (* (/ 1.0 B) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))) (PI))))