
(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 11 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 (<= A -3.2e+107) (/ (* (atan (* 0.5 (/ (fma (/ C A) B B) A))) 180.0) (PI)) (/ (* (atan (/ (- (- C A) (hypot B (- A C))) B)) 180.0) (PI))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -3.2 \cdot 10^{+107}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{\mathsf{fma}\left(\frac{C}{A}, B, B\right)}{A}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\left(C - A\right) - \mathsf{hypot}\left(B, A - C\right)}{B}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -3.20000000000000029e107Initial program 10.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.7%
Taylor expanded in A around -inf
mul-1-negN/A
distribute-lft-outN/A
associate-/l*N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.7
Applied rewrites80.7%
if -3.20000000000000029e107 < A Initial program 64.5%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites86.7%
Final simplification85.5%
(FPCore (A B C)
:precision binary64
(let* ((t_0
(* (pow B -1.0) (- (- C A) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))
(t_1 (/ (- C A) B)))
(if (<= t_0 -0.5)
(* 180.0 (/ (atan (- t_1 1.0)) (PI)))
(if (<= t_0 0.0)
(/ (* (atan (* (/ B A) 0.5)) 180.0) (PI))
(* 180.0 (/ (atan (+ t_1 1.0)) (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {B}^{-1} \cdot \left(\left(C - A\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)\\
t_1 := \frac{C - A}{B}\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(t\_1 - 1\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{B}{A} \cdot 0.5\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(t\_1 + 1\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if (*.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.5Initial program 60.2%
Taylor expanded in B around inf
+-commutativeN/A
associate--r+N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6475.4
Applied rewrites75.4%
if -0.5 < (*.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 15.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites15.2%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6453.1
Applied rewrites53.1%
if 0.0 < (*.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.2%
Taylor expanded in B around -inf
associate--l+N/A
div-subN/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6476.8
Applied rewrites76.8%
Final simplification73.4%
(FPCore (A B C)
:precision binary64
(if (<= A -2.7e+106)
(/ (* (atan (* 0.5 (/ (fma (/ C A) B B) A))) 180.0) (PI))
(if (<= A 1.25e-24)
(* 180.0 (/ (atan (/ (- C (hypot B C)) B)) (PI)))
(* 180.0 (/ (atan (/ (+ (hypot B A) A) (- B))) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.7 \cdot 10^{+106}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{\mathsf{fma}\left(\frac{C}{A}, B, B\right)}{A}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 1.25 \cdot 10^{-24}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{C - \mathsf{hypot}\left(B, C\right)}{B}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{\mathsf{hypot}\left(B, A\right) + A}{-B}\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -2.70000000000000006e106Initial program 10.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.7%
Taylor expanded in A around -inf
mul-1-negN/A
distribute-lft-outN/A
associate-/l*N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.7
Applied rewrites80.7%
if -2.70000000000000006e106 < A < 1.24999999999999995e-24Initial program 59.8%
Taylor expanded in A around 0
lower-/.f64N/A
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6481.3
Applied rewrites81.3%
if 1.24999999999999995e-24 < A Initial program 74.6%
Taylor expanded in C around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
mul-1-negN/A
lower-neg.f6491.1
Applied rewrites91.1%
Final simplification83.7%
(FPCore (A B C)
:precision binary64
(if (<= A -2.7e+106)
(/ (* (atan (* 0.5 (/ (fma (/ C A) B B) A))) 180.0) (PI))
(if (<= A 1.6e+139)
(* 180.0 (/ (atan (/ (- C (hypot B C)) B)) (PI)))
(* 180.0 (/ (atan (+ (/ (- C A) B) 1.0)) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.7 \cdot 10^{+106}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{\mathsf{fma}\left(\frac{C}{A}, B, B\right)}{A}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 1.6 \cdot 10^{+139}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{C - \mathsf{hypot}\left(B, C\right)}{B}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + 1\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -2.70000000000000006e106Initial program 10.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.7%
Taylor expanded in A around -inf
mul-1-negN/A
distribute-lft-outN/A
associate-/l*N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.7
Applied rewrites80.7%
if -2.70000000000000006e106 < A < 1.6000000000000001e139Initial program 60.6%
Taylor expanded in A around 0
lower-/.f64N/A
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6480.1
Applied rewrites80.1%
if 1.6000000000000001e139 < A Initial program 83.8%
Taylor expanded in B around -inf
associate--l+N/A
div-subN/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6494.3
Applied rewrites94.3%
Final simplification82.1%
(FPCore (A B C)
:precision binary64
(if (<= A -1.8e+105)
(/ (* (atan (* (/ B A) 0.5)) 180.0) (PI))
(if (<= A 5.8e+122)
(/ (* (atan (/ (- C B) B)) 180.0) (PI))
(* 180.0 (/ (atan (* (/ A B) -2.0)) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -1.8 \cdot 10^{+105}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{B}{A} \cdot 0.5\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 5.8 \cdot 10^{+122}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C - B}{B}\right) \cdot 180}{\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 < -1.7999999999999999e105Initial program 10.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.7%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
if -1.7999999999999999e105 < A < 5.8000000000000002e122Initial program 61.3%
Taylor expanded in A around inf
lower-*.f6413.0
Applied rewrites13.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites13.0%
Taylor expanded in A around 0
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6480.5
Applied rewrites80.5%
Taylor expanded in C around 0
Applied rewrites48.7%
if 5.8000000000000002e122 < A Initial program 75.9%
Taylor expanded in A around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6473.1
Applied rewrites73.1%
Final simplification59.0%
(FPCore (A B C)
:precision binary64
(if (<= A -1.8e+105)
(* 180.0 (/ (atan (* (/ B A) 0.5)) (PI)))
(if (<= A 5.8e+122)
(/ (* (atan (/ (- C B) B)) 180.0) (PI))
(* 180.0 (/ (atan (* (/ A B) -2.0)) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -1.8 \cdot 10^{+105}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{B}{A} \cdot 0.5\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 5.8 \cdot 10^{+122}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C - B}{B}\right) \cdot 180}{\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 < -1.7999999999999999e105Initial program 10.0%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6480.5
Applied rewrites80.5%
if -1.7999999999999999e105 < A < 5.8000000000000002e122Initial program 61.3%
Taylor expanded in A around inf
lower-*.f6413.0
Applied rewrites13.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites13.0%
Taylor expanded in A around 0
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6480.5
Applied rewrites80.5%
Taylor expanded in C around 0
Applied rewrites48.7%
if 5.8000000000000002e122 < A Initial program 75.9%
Taylor expanded in A around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6473.1
Applied rewrites73.1%
(FPCore (A B C) :precision binary64 (if (<= A -3.5e+105) (/ (* (atan (* (/ B A) 0.5)) 180.0) (PI)) (* 180.0 (/ (atan (+ (/ (- C A) B) 1.0)) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -3.5 \cdot 10^{+105}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{B}{A} \cdot 0.5\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + 1\right)}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -3.49999999999999991e105Initial program 10.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites41.7%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
if -3.49999999999999991e105 < A Initial program 64.5%
Taylor expanded in B around -inf
associate--l+N/A
div-subN/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6464.0
Applied rewrites64.0%
Final simplification67.1%
(FPCore (A B C) :precision binary64 (if (<= B -3.3e-24) (* 180.0 (/ (atan 1.0) (PI))) (/ (* (atan (/ (- C B) B)) 180.0) (PI))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -3.3 \cdot 10^{-24}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C - B}{B}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if B < -3.29999999999999984e-24Initial program 51.9%
Taylor expanded in B around -inf
Applied rewrites60.0%
if -3.29999999999999984e-24 < B Initial program 55.4%
Taylor expanded in A around inf
lower-*.f6425.9
Applied rewrites25.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites25.9%
Taylor expanded in A around 0
lower--.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6463.1
Applied rewrites63.1%
Taylor expanded in C around 0
Applied rewrites49.0%
(FPCore (A B C)
:precision binary64
(if (<= B -3.4e-116)
(* 180.0 (/ (atan 1.0) (PI)))
(if (<= B 5.8e-143)
(/ (* (atan 0.0) 180.0) (PI))
(* 180.0 (/ (atan -1.0) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -3.4 \cdot 10^{-116}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;B \leq 5.8 \cdot 10^{-143}:\\
\;\;\;\;\frac{\tan^{-1} 0 \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if B < -3.39999999999999992e-116Initial program 56.5%
Taylor expanded in B around -inf
Applied rewrites53.1%
if -3.39999999999999992e-116 < B < 5.8000000000000002e-143Initial program 45.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites76.2%
Taylor expanded in B around -inf
Applied rewrites6.3%
Taylor expanded in C around inf
div-addN/A
associate-*r/N/A
+-commutativeN/A
mul-1-negN/A
distribute-lft1-inN/A
metadata-evalN/A
distribute-lft-neg-inN/A
metadata-evalN/A
mul0-lft39.5
Applied rewrites39.5%
if 5.8000000000000002e-143 < B Initial program 58.5%
Taylor expanded in B around inf
Applied rewrites49.7%
Final simplification48.4%
(FPCore (A B C) :precision binary64 (if (<= B -1.4e-306) (* 180.0 (/ (atan 1.0) (PI))) (* 180.0 (/ (atan -1.0) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -1.4 \cdot 10^{-306}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if B < -1.4000000000000001e-306Initial program 53.6%
Taylor expanded in B around -inf
Applied rewrites42.5%
if -1.4000000000000001e-306 < B Initial program 55.1%
Taylor expanded in B around inf
Applied rewrites38.5%
(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 54.3%
Taylor expanded in B around inf
Applied rewrites18.6%
herbie shell --seed 2024326
(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))))