
(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 (<= A -2.15e+39)
(/ (* 180.0 (atan (* 0.5 (/ B A)))) (PI))
(*
(pow
(/ (sqrt (PI)) (* (atan (/ (- (- C A) (hypot B (- A C))) B)) 180.0))
-1.0)
(pow (PI) -0.5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.15 \cdot 10^{+39}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{\sqrt{\mathsf{PI}\left(\right)}}{\tan^{-1} \left(\frac{\left(C - A\right) - \mathsf{hypot}\left(B, A - C\right)}{B}\right) \cdot 180}\right)}^{-1} \cdot {\mathsf{PI}\left(\right)}^{-0.5}\\
\end{array}
\end{array}
if A < -2.15e39Initial program 20.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites51.9%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6471.6
Applied rewrites71.6%
if -2.15e39 < A Initial program 58.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites83.2%
lift-/.f64N/A
clear-numN/A
inv-powN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-/l*N/A
unpow-prod-downN/A
inv-powN/A
lower-*.f64N/A
Applied rewrites83.2%
Final simplification80.3%
(FPCore (A B C)
:precision binary64
(let* ((t_0
(* (- (- C A) (sqrt (+ (pow B 2.0) (pow (- A C) 2.0)))) (/ 1.0 B))))
(if (<= t_0 -0.5)
(* (/ (atan (- -1.0 (/ A B))) (PI)) 180.0)
(if (<= t_0 5e-20)
(* (/ (atan 0.0) (PI)) 180.0)
(* (/ (atan (- 1.0 (/ A B))) (PI)) 180.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(C - A\right) - \sqrt{{B}^{2} + {\left(A - C\right)}^{2}}\right) \cdot \frac{1}{B}\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;\frac{\tan^{-1} \left(-1 - \frac{A}{B}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-20}:\\
\;\;\;\;\frac{\tan^{-1} 0}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(1 - \frac{A}{B}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\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 51.1%
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.f6471.3
Applied rewrites71.3%
Taylor expanded in B around inf
Applied rewrites63.6%
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)))))) < 4.9999999999999999e-20Initial program 23.6%
Taylor expanded in C around inf
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
div0N/A
metadata-eval23.6
Applied rewrites23.6%
if 4.9999999999999999e-20 < (*.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 56.7%
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.f6464.9
Applied rewrites64.9%
Taylor expanded in B around -inf
Applied rewrites58.0%
Final simplification55.0%
(FPCore (A B C)
:precision binary64
(if (<= C -1.1e+106)
(/ (* (atan (- (/ (- C A) B) 1.0)) 180.0) (PI))
(if (<= C 3.2e+204)
(* (/ (atan (/ (+ (hypot B A) A) (- B))) (PI)) 180.0)
(/ (* (atan (* (/ B C) -0.5)) 180.0) (PI)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;C \leq -1.1 \cdot 10^{+106}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C - A}{B} - 1\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;C \leq 3.2 \cdot 10^{+204}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\mathsf{hypot}\left(B, A\right) + A}{-B}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{B}{C} \cdot -0.5\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if C < -1.09999999999999996e106Initial program 85.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites93.1%
Taylor expanded in B around inf
+-commutativeN/A
associate--r+N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6490.5
Applied rewrites90.5%
if -1.09999999999999996e106 < C < 3.2e204Initial program 46.7%
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.f6468.6
Applied rewrites68.6%
if 3.2e204 < C Initial program 5.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites56.6%
Taylor expanded in C around inf
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
div0N/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6491.7
Applied rewrites91.7%
Taylor expanded in C around inf
Applied rewrites92.0%
Final simplification74.2%
(FPCore (A B C) :precision binary64 (if (<= A -2.15e+39) (/ (* 180.0 (atan (* 0.5 (/ B A)))) (PI)) (/ (* (atan (/ (- (- C A) (hypot (- A C) B)) B)) 180.0) (PI))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.15 \cdot 10^{+39}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{\left(C - A\right) - \mathsf{hypot}\left(A - C, B\right)}{B}\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -2.15e39Initial program 20.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites51.9%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6471.6
Applied rewrites71.6%
if -2.15e39 < A Initial program 58.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites83.2%
Final simplification80.3%
(FPCore (A B C)
:precision binary64
(if (<= A -2.7e-25)
(/ (* 180.0 (atan (* 0.5 (/ B A)))) (PI))
(if (<= A 7.5e-13)
(/ (* (atan (- (/ C B) 1.0)) 180.0) (PI))
(* (/ (atan (- -1.0 (/ A B))) (PI)) 180.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.7 \cdot 10^{-25}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{elif}\;A \leq 7.5 \cdot 10^{-13}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C}{B} - 1\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(-1 - \frac{A}{B}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if A < -2.70000000000000016e-25Initial program 20.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites55.9%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6464.0
Applied rewrites64.0%
if -2.70000000000000016e-25 < A < 7.5000000000000004e-13Initial program 57.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites81.3%
Taylor expanded in B around inf
+-commutativeN/A
associate--r+N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6458.1
Applied rewrites58.1%
Taylor expanded in C around inf
Applied rewrites55.3%
if 7.5000000000000004e-13 < A Initial program 71.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.f6486.0
Applied rewrites86.0%
Taylor expanded in B around inf
Applied rewrites77.7%
Final simplification62.7%
(FPCore (A B C)
:precision binary64
(if (<= A -2.7e-25)
(* (/ (atan (* 0.5 (/ B A))) (PI)) 180.0)
(if (<= A 7.5e-13)
(/ (* (atan (- (/ C B) 1.0)) 180.0) (PI))
(* (/ (atan (- -1.0 (/ A B))) (PI)) 180.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.7 \cdot 10^{-25}:\\
\;\;\;\;\frac{\tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{elif}\;A \leq 7.5 \cdot 10^{-13}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C}{B} - 1\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(-1 - \frac{A}{B}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if A < -2.70000000000000016e-25Initial program 20.1%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6464.0
Applied rewrites64.0%
if -2.70000000000000016e-25 < A < 7.5000000000000004e-13Initial program 57.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites81.3%
Taylor expanded in B around inf
+-commutativeN/A
associate--r+N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6458.1
Applied rewrites58.1%
Taylor expanded in C around inf
Applied rewrites55.3%
if 7.5000000000000004e-13 < A Initial program 71.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.f6486.0
Applied rewrites86.0%
Taylor expanded in B around inf
Applied rewrites77.7%
Final simplification62.7%
(FPCore (A B C) :precision binary64 (if (<= A -2.7e-25) (/ (* 180.0 (atan (* 0.5 (/ B A)))) (PI)) (/ (* (atan (- (/ (- C A) B) 1.0)) 180.0) (PI))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.7 \cdot 10^{-25}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C - A}{B} - 1\right) \cdot 180}{\mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if A < -2.70000000000000016e-25Initial program 20.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites55.9%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6464.0
Applied rewrites64.0%
if -2.70000000000000016e-25 < A Initial program 61.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites83.7%
Taylor expanded in B around inf
+-commutativeN/A
associate--r+N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6464.0
Applied rewrites64.0%
Final simplification64.0%
(FPCore (A B C) :precision binary64 (if (<= A -2.7e-25) (/ (* 180.0 (atan (* 0.5 (/ B A)))) (PI)) (* (/ (atan (- (/ (- C A) B) 1.0)) (PI)) 180.0)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;A \leq -2.7 \cdot 10^{-25}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(0.5 \cdot \frac{B}{A}\right)}{\mathsf{PI}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(\frac{C - A}{B} - 1\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if A < -2.70000000000000016e-25Initial program 20.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites55.9%
Taylor expanded in A around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6464.0
Applied rewrites64.0%
if -2.70000000000000016e-25 < A Initial program 61.8%
Taylor expanded in B around inf
+-commutativeN/A
associate--r+N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6464.0
Applied rewrites64.0%
Final simplification64.0%
(FPCore (A B C) :precision binary64 (if (<= B -1.3e-118) (* (/ (atan 1.0) (PI)) 180.0) (* (/ (atan (- -1.0 (/ A B))) (PI)) 180.0)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -1.3 \cdot 10^{-118}:\\
\;\;\;\;\frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} \left(-1 - \frac{A}{B}\right)}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if B < -1.3e-118Initial program 51.1%
Taylor expanded in B around -inf
Applied rewrites49.4%
if -1.3e-118 < B Initial program 48.2%
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.f6460.4
Applied rewrites60.4%
Taylor expanded in B around inf
Applied rewrites49.7%
Final simplification49.6%
(FPCore (A B C)
:precision binary64
(if (<= B -8e-89)
(* (/ (atan 1.0) (PI)) 180.0)
(if (<= B 1.25e-84)
(* (/ (atan 0.0) (PI)) 180.0)
(* (/ (atan -1.0) (PI)) 180.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -8 \cdot 10^{-89}:\\
\;\;\;\;\frac{\tan^{-1} 1}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{elif}\;B \leq 1.25 \cdot 10^{-84}:\\
\;\;\;\;\frac{\tan^{-1} 0}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if B < -8.00000000000000031e-89Initial program 49.6%
Taylor expanded in B around -inf
Applied rewrites53.5%
if -8.00000000000000031e-89 < B < 1.25e-84Initial program 54.9%
Taylor expanded in C around inf
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
div0N/A
metadata-eval31.5
Applied rewrites31.5%
if 1.25e-84 < B Initial program 42.6%
Taylor expanded in B around inf
Applied rewrites54.0%
Final simplification45.4%
(FPCore (A B C) :precision binary64 (if (<= B 1.25e-84) (* (/ (atan 0.0) (PI)) 180.0) (* (/ (atan -1.0) (PI)) 180.0)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 1.25 \cdot 10^{-84}:\\
\;\;\;\;\frac{\tan^{-1} 0}{\mathsf{PI}\left(\right)} \cdot 180\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)} \cdot 180\\
\end{array}
\end{array}
if B < 1.25e-84Initial program 52.7%
Taylor expanded in C around inf
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
div0N/A
metadata-eval20.3
Applied rewrites20.3%
if 1.25e-84 < B Initial program 42.6%
Taylor expanded in B around inf
Applied rewrites54.0%
Final simplification32.3%
(FPCore (A B C) :precision binary64 (* (/ (atan -1.0) (PI)) 180.0))
\begin{array}{l}
\\
\frac{\tan^{-1} -1}{\mathsf{PI}\left(\right)} \cdot 180
\end{array}
Initial program 49.1%
Taylor expanded in B around inf
Applied rewrites22.5%
Final simplification22.5%
herbie shell --seed 2024284
(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))))