
(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 3 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 (* 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}
Initial program 51.6%
(FPCore (A B C)
:precision binary64
(let* ((t_0 (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))) (t_1 (- (- C A) t_0)))
(if (<= (atan (* (/ 1.0 B) t_1)) 0.0)
(* 180.0 (/ (atan t_1) (PI)))
(* 180.0 (/ (atan t_0) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\\
t_1 := \left(C - A\right) - t\_0\\
\mathbf{if}\;\tan^{-1} \left(\frac{1}{B} \cdot t\_1\right) \leq 0:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} t\_1}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} t\_0}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if (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))))))) < 0.0Initial program 45.2%
Taylor expanded in A around 0
Applied rewrites33.2%
if 0.0 < (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))))))) Initial program 59.7%
Taylor expanded in A around 0
Applied rewrites40.5%
(FPCore (A B C) :precision binary64 (* 180.0 (/ (atan (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))) (PI))))
\begin{array}{l}
\\
180 \cdot \frac{\tan^{-1} \left(\sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}{\mathsf{PI}\left(\right)}
\end{array}
Initial program 51.6%
Taylor expanded in A around 0
Applied rewrites19.3%
herbie shell --seed 2024321
(FPCore (A B C)
:name "ABCF->ab-angle angle"
:precision binary64
:pre (TRUE)
(* 180.0 (/ (atan (* (/ 1.0 B) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))) (PI))))