ABCF->ab-angle angle

Percentage Accurate: 53.3% → 72.7%
Time: 12.1s
Alternatives: 12
Speedup: 0.6×

Specification

?
\[\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)}{\pi} \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)))
double code(double A, double B, double C) {
	return 180.0 * (atan(((1.0 / B) * ((C - A) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / ((double) M_PI));
}
public static double code(double A, double B, double C) {
	return 180.0 * (Math.atan(((1.0 / B) * ((C - A) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / Math.PI);
}
def code(A, B, C):
	return 180.0 * (math.atan(((1.0 / B) * ((C - A) - math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / math.pi)
function code(A, B, C)
	return Float64(180.0 * Float64(atan(Float64(Float64(1.0 / B) * Float64(Float64(C - A) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0)))))) / pi))
end
function tmp = code(A, B, C)
	tmp = 180.0 * (atan(((1.0 / B) * ((C - A) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / pi);
end
code[A_, B_, C_] := N[(180.0 * N[(N[ArcTan[N[(N[(1.0 / B), $MachinePrecision] * N[(N[(C - A), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\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)}{\pi}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 12 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 53.3% accurate, 1.0× speedup?

\[\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)}{\pi} \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)))
double code(double A, double B, double C) {
	return 180.0 * (atan(((1.0 / B) * ((C - A) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / ((double) M_PI));
}
public static double code(double A, double B, double C) {
	return 180.0 * (Math.atan(((1.0 / B) * ((C - A) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / Math.PI);
}
def code(A, B, C):
	return 180.0 * (math.atan(((1.0 / B) * ((C - A) - math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / math.pi)
function code(A, B, C)
	return Float64(180.0 * Float64(atan(Float64(Float64(1.0 / B) * Float64(Float64(C - A) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0)))))) / pi))
end
function tmp = code(A, B, C)
	tmp = 180.0 * (atan(((1.0 / B) * ((C - A) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / pi);
end
code[A_, B_, C_] := N[(180.0 * N[(N[ArcTan[N[(N[(1.0 / B), $MachinePrecision] * N[(N[(C - A), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\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)}{\pi}
\end{array}

Alternative 1: 72.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{B} \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:\\ \;\;\;\;\frac{180 \cdot \tan^{-1} \left(t\_1 + -1\right)}{\pi}\\ \mathbf{elif}\;t\_0 \leq 10^{-7}:\\ \;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(B, \frac{-0.5}{C}, 0\right)\right) \cdot \left(180 \cdot \frac{1}{\pi}\right)\\ \mathbf{else}:\\ \;\;\;\;180 \cdot \frac{\tan^{-1} \left(1 + t\_1\right)}{\pi}\\ \end{array} \end{array} \]
(FPCore (A B C)
 :precision binary64
 (let* ((t_0
         (* (/ 1.0 B) (- (- 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 1e-7)
       (* (atan (fma B (/ -0.5 C) 0.0)) (* 180.0 (/ 1.0 PI)))
       (* 180.0 (/ (atan (+ 1.0 t_1)) PI))))))
double code(double A, double B, double C) {
	double t_0 = (1.0 / B) * ((C - A) - sqrt((pow((A - C), 2.0) + pow(B, 2.0))));
	double t_1 = (C - A) / B;
	double tmp;
	if (t_0 <= -0.5) {
		tmp = (180.0 * atan((t_1 + -1.0))) / ((double) M_PI);
	} else if (t_0 <= 1e-7) {
		tmp = atan(fma(B, (-0.5 / C), 0.0)) * (180.0 * (1.0 / ((double) M_PI)));
	} else {
		tmp = 180.0 * (atan((1.0 + t_1)) / ((double) M_PI));
	}
	return tmp;
}
function code(A, B, C)
	t_0 = Float64(Float64(1.0 / B) * Float64(Float64(C - A) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0)))))
	t_1 = Float64(Float64(C - A) / B)
	tmp = 0.0
	if (t_0 <= -0.5)
		tmp = Float64(Float64(180.0 * atan(Float64(t_1 + -1.0))) / pi);
	elseif (t_0 <= 1e-7)
		tmp = Float64(atan(fma(B, Float64(-0.5 / C), 0.0)) * Float64(180.0 * Float64(1.0 / pi)));
	else
		tmp = Float64(180.0 * Float64(atan(Float64(1.0 + t_1)) / pi));
	end
	return tmp
end
code[A_, B_, C_] := Block[{t$95$0 = N[(N[(1.0 / B), $MachinePrecision] * N[(N[(C - A), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(C - A), $MachinePrecision] / B), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], N[(N[(180.0 * N[ArcTan[N[(t$95$1 + -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision], If[LessEqual[t$95$0, 1e-7], N[(N[ArcTan[N[(B * N[(-0.5 / C), $MachinePrecision] + 0.0), $MachinePrecision]], $MachinePrecision] * N[(180.0 * N[(1.0 / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(180.0 * N[(N[ArcTan[N[(1.0 + t$95$1), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{B} \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:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(t\_1 + -1\right)}{\pi}\\

\mathbf{elif}\;t\_0 \leq 10^{-7}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(B, \frac{-0.5}{C}, 0\right)\right) \cdot \left(180 \cdot \frac{1}{\pi}\right)\\

\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(1 + t\_1\right)}{\pi}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. 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.5

    1. Initial program 57.3%

      \[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)}{\pi} \]
    2. Add Preprocessing
    3. Taylor expanded in B around inf

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C}{B} - \left(1 + \frac{A}{B}\right)\right)}}{\mathsf{PI}\left(\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{C}{B} - \color{blue}{\left(\frac{A}{B} + 1\right)}\right)}{\mathsf{PI}\left(\right)} \]
      2. associate--r+N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\left(\frac{C}{B} - \frac{A}{B}\right) - 1\right)}}{\mathsf{PI}\left(\right)} \]
      3. div-subN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\color{blue}{\frac{C - A}{B}} - 1\right)}{\mathsf{PI}\left(\right)} \]
      4. sub-negN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + \left(\mathsf{neg}\left(1\right)\right)\right)}}{\mathsf{PI}\left(\right)} \]
      5. metadata-evalN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + \color{blue}{-1}\right)}{\mathsf{PI}\left(\right)} \]
      6. lower-+.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + -1\right)}}{\mathsf{PI}\left(\right)} \]
      7. lower-/.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\color{blue}{\frac{C - A}{B}} + -1\right)}{\mathsf{PI}\left(\right)} \]
      8. lower--.f6476.7

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\color{blue}{C - A}}{B} + -1\right)}{\pi} \]
    5. Applied rewrites76.7%

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + -1\right)}}{\pi} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      2. lift-/.f64N/A

        \[\leadsto 180 \cdot \color{blue}{\frac{\tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      3. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      5. lower-*.f6476.7

        \[\leadsto \frac{\color{blue}{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}}{\pi} \]
    7. Applied rewrites76.7%

      \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\pi}} \]

    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)))))) < 9.9999999999999995e-8

    1. Initial program 28.3%

      \[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)}{\pi} \]
    2. Add Preprocessing
    3. Taylor expanded in A around -inf

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(-1 \cdot \frac{\frac{-1}{2} \cdot B + \frac{-1}{2} \cdot \frac{B \cdot C}{A}}{A}\right)}}{\mathsf{PI}\left(\right)} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{-1 \cdot \left(\frac{-1}{2} \cdot B + \frac{-1}{2} \cdot \frac{B \cdot C}{A}\right)}{A}\right)}}{\mathsf{PI}\left(\right)} \]
      2. lower-/.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{-1 \cdot \left(\frac{-1}{2} \cdot B + \frac{-1}{2} \cdot \frac{B \cdot C}{A}\right)}{A}\right)}}{\mathsf{PI}\left(\right)} \]
      3. distribute-lft-outN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{-1 \cdot \color{blue}{\left(\frac{-1}{2} \cdot \left(B + \frac{B \cdot C}{A}\right)\right)}}{A}\right)}{\mathsf{PI}\left(\right)} \]
      4. associate-*r*N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\color{blue}{\left(-1 \cdot \frac{-1}{2}\right) \cdot \left(B + \frac{B \cdot C}{A}\right)}}{A}\right)}{\mathsf{PI}\left(\right)} \]
      5. metadata-evalN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\color{blue}{\frac{1}{2}} \cdot \left(B + \frac{B \cdot C}{A}\right)}{A}\right)}{\mathsf{PI}\left(\right)} \]
      6. lower-*.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\color{blue}{\frac{1}{2} \cdot \left(B + \frac{B \cdot C}{A}\right)}}{A}\right)}{\mathsf{PI}\left(\right)} \]
      7. +-commutativeN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \color{blue}{\left(\frac{B \cdot C}{A} + B\right)}}{A}\right)}{\mathsf{PI}\left(\right)} \]
      8. associate-/l*N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \left(\color{blue}{B \cdot \frac{C}{A}} + B\right)}{A}\right)}{\mathsf{PI}\left(\right)} \]
      9. lower-fma.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \color{blue}{\mathsf{fma}\left(B, \frac{C}{A}, B\right)}}{A}\right)}{\mathsf{PI}\left(\right)} \]
      10. lower-/.f6428.5

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{0.5 \cdot \mathsf{fma}\left(B, \color{blue}{\frac{C}{A}}, B\right)}{A}\right)}{\pi} \]
    5. Applied rewrites28.5%

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{0.5 \cdot \mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right)}}{\pi} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{180 \cdot \frac{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right)}{\mathsf{PI}\left(\right)}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right)}{\mathsf{PI}\left(\right)} \cdot 180} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right)}{\mathsf{PI}\left(\right)}} \cdot 180 \]
      4. div-invN/A

        \[\leadsto \color{blue}{\left(\tan^{-1} \left(\frac{\frac{1}{2} \cdot \mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right) \cdot \frac{1}{\mathsf{PI}\left(\right)}\right)} \cdot 180 \]
      5. associate-*l*N/A

        \[\leadsto \color{blue}{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right)} \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\tan^{-1} \left(\frac{\frac{1}{2} \cdot \mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right)} \]
    7. Applied rewrites28.6%

      \[\leadsto \color{blue}{\tan^{-1} \left(0.5 \cdot \frac{\mathsf{fma}\left(B, \frac{C}{A}, B\right)}{A}\right) \cdot \left(\frac{1}{\pi} \cdot 180\right)} \]
    8. Taylor expanded in C around inf

      \[\leadsto \tan^{-1} \color{blue}{\left(-1 \cdot \frac{A + -1 \cdot A}{B} + \frac{-1}{2} \cdot \frac{B}{C}\right)} \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \tan^{-1} \color{blue}{\left(\frac{-1}{2} \cdot \frac{B}{C} + -1 \cdot \frac{A + -1 \cdot A}{B}\right)} \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      2. associate-*r/N/A

        \[\leadsto \tan^{-1} \left(\color{blue}{\frac{\frac{-1}{2} \cdot B}{C}} + -1 \cdot \frac{A + -1 \cdot A}{B}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      3. *-commutativeN/A

        \[\leadsto \tan^{-1} \left(\frac{\color{blue}{B \cdot \frac{-1}{2}}}{C} + -1 \cdot \frac{A + -1 \cdot A}{B}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      4. associate-/l*N/A

        \[\leadsto \tan^{-1} \left(\color{blue}{B \cdot \frac{\frac{-1}{2}}{C}} + -1 \cdot \frac{A + -1 \cdot A}{B}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      5. associate-*r/N/A

        \[\leadsto \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \color{blue}{\frac{-1 \cdot \left(A + -1 \cdot A\right)}{B}}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      6. distribute-rgt1-inN/A

        \[\leadsto \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{-1 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot A\right)}}{B}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      7. metadata-evalN/A

        \[\leadsto \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{-1 \cdot \left(\color{blue}{0} \cdot A\right)}{B}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      8. mul0-lftN/A

        \[\leadsto \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{-1 \cdot \color{blue}{0}}{B}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      9. metadata-evalN/A

        \[\leadsto \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{\color{blue}{0}}{B}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      10. div0N/A

        \[\leadsto \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \color{blue}{0}\right) \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      11. lower-fma.f64N/A

        \[\leadsto \tan^{-1} \color{blue}{\left(\mathsf{fma}\left(B, \frac{\frac{-1}{2}}{C}, 0\right)\right)} \cdot \left(\frac{1}{\mathsf{PI}\left(\right)} \cdot 180\right) \]
      12. lower-/.f6469.9

        \[\leadsto \tan^{-1} \left(\mathsf{fma}\left(B, \color{blue}{\frac{-0.5}{C}}, 0\right)\right) \cdot \left(\frac{1}{\pi} \cdot 180\right) \]
    10. Applied rewrites69.9%

      \[\leadsto \tan^{-1} \color{blue}{\left(\mathsf{fma}\left(B, \frac{-0.5}{C}, 0\right)\right)} \cdot \left(\frac{1}{\pi} \cdot 180\right) \]

    if 9.9999999999999995e-8 < (*.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))))))

    1. Initial program 60.6%

      \[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)}{\pi} \]
    2. Add Preprocessing
    3. Taylor expanded in B around -inf

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\left(1 + \frac{C}{B}\right) - \frac{A}{B}\right)}}{\mathsf{PI}\left(\right)} \]
    4. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(1 + \left(\frac{C}{B} - \frac{A}{B}\right)\right)}}{\mathsf{PI}\left(\right)} \]
      2. div-subN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(1 + \color{blue}{\frac{C - A}{B}}\right)}{\mathsf{PI}\left(\right)} \]
      3. lower-+.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(1 + \frac{C - A}{B}\right)}}{\mathsf{PI}\left(\right)} \]
      4. lower-/.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(1 + \color{blue}{\frac{C - A}{B}}\right)}{\mathsf{PI}\left(\right)} \]
      5. lower--.f6475.4

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(1 + \frac{\color{blue}{C - A}}{B}\right)}{\pi} \]
    5. Applied rewrites75.4%

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(1 + \frac{C - A}{B}\right)}}{\pi} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{B} \cdot \left(\left(C - A\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right) \leq -0.5:\\ \;\;\;\;\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\pi}\\ \mathbf{elif}\;\frac{1}{B} \cdot \left(\left(C - A\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right) \leq 10^{-7}:\\ \;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(B, \frac{-0.5}{C}, 0\right)\right) \cdot \left(180 \cdot \frac{1}{\pi}\right)\\ \mathbf{else}:\\ \;\;\;\;180 \cdot \frac{\tan^{-1} \left(1 + \frac{C - A}{B}\right)}{\pi}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 72.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{B} \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:\\ \;\;\;\;\frac{180 \cdot \tan^{-1} \left(t\_1 + -1\right)}{\pi}\\ \mathbf{elif}\;t\_0 \leq 10^{-7}:\\ \;\;\;\;\frac{180 \cdot \tan^{-1} \left(\mathsf{fma}\left(B, \frac{-0.5}{C}, 0\right)\right)}{\pi}\\ \mathbf{else}:\\ \;\;\;\;180 \cdot \frac{\tan^{-1} \left(1 + t\_1\right)}{\pi}\\ \end{array} \end{array} \]
(FPCore (A B C)
 :precision binary64
 (let* ((t_0
         (* (/ 1.0 B) (- (- 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 1e-7)
       (/ (* 180.0 (atan (fma B (/ -0.5 C) 0.0))) PI)
       (* 180.0 (/ (atan (+ 1.0 t_1)) PI))))))
double code(double A, double B, double C) {
	double t_0 = (1.0 / B) * ((C - A) - sqrt((pow((A - C), 2.0) + pow(B, 2.0))));
	double t_1 = (C - A) / B;
	double tmp;
	if (t_0 <= -0.5) {
		tmp = (180.0 * atan((t_1 + -1.0))) / ((double) M_PI);
	} else if (t_0 <= 1e-7) {
		tmp = (180.0 * atan(fma(B, (-0.5 / C), 0.0))) / ((double) M_PI);
	} else {
		tmp = 180.0 * (atan((1.0 + t_1)) / ((double) M_PI));
	}
	return tmp;
}
function code(A, B, C)
	t_0 = Float64(Float64(1.0 / B) * Float64(Float64(C - A) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0)))))
	t_1 = Float64(Float64(C - A) / B)
	tmp = 0.0
	if (t_0 <= -0.5)
		tmp = Float64(Float64(180.0 * atan(Float64(t_1 + -1.0))) / pi);
	elseif (t_0 <= 1e-7)
		tmp = Float64(Float64(180.0 * atan(fma(B, Float64(-0.5 / C), 0.0))) / pi);
	else
		tmp = Float64(180.0 * Float64(atan(Float64(1.0 + t_1)) / pi));
	end
	return tmp
end
code[A_, B_, C_] := Block[{t$95$0 = N[(N[(1.0 / B), $MachinePrecision] * N[(N[(C - A), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(C - A), $MachinePrecision] / B), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], N[(N[(180.0 * N[ArcTan[N[(t$95$1 + -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision], If[LessEqual[t$95$0, 1e-7], N[(N[(180.0 * N[ArcTan[N[(B * N[(-0.5 / C), $MachinePrecision] + 0.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision], N[(180.0 * N[(N[ArcTan[N[(1.0 + t$95$1), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{B} \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:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(t\_1 + -1\right)}{\pi}\\

\mathbf{elif}\;t\_0 \leq 10^{-7}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(\mathsf{fma}\left(B, \frac{-0.5}{C}, 0\right)\right)}{\pi}\\

\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(1 + t\_1\right)}{\pi}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. 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.5

    1. Initial program 57.9%

      \[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)}{\pi} \]
    2. Add Preprocessing
    3. Taylor expanded in B around inf

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C}{B} - \left(1 + \frac{A}{B}\right)\right)}}{\mathsf{PI}\left(\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{C}{B} - \color{blue}{\left(\frac{A}{B} + 1\right)}\right)}{\mathsf{PI}\left(\right)} \]
      2. associate--r+N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\left(\frac{C}{B} - \frac{A}{B}\right) - 1\right)}}{\mathsf{PI}\left(\right)} \]
      3. div-subN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\color{blue}{\frac{C - A}{B}} - 1\right)}{\mathsf{PI}\left(\right)} \]
      4. sub-negN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + \left(\mathsf{neg}\left(1\right)\right)\right)}}{\mathsf{PI}\left(\right)} \]
      5. metadata-evalN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + \color{blue}{-1}\right)}{\mathsf{PI}\left(\right)} \]
      6. lower-+.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + -1\right)}}{\mathsf{PI}\left(\right)} \]
      7. lower-/.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\color{blue}{\frac{C - A}{B}} + -1\right)}{\mathsf{PI}\left(\right)} \]
      8. lower--.f6475.5

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\color{blue}{C - A}}{B} + -1\right)}{\pi} \]
    5. Applied rewrites75.5%

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + -1\right)}}{\pi} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      2. lift-/.f64N/A

        \[\leadsto 180 \cdot \color{blue}{\frac{\tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      3. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      5. lower-*.f6475.5

        \[\leadsto \frac{\color{blue}{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}}{\pi} \]
    7. Applied rewrites75.5%

      \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\pi}} \]

    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)))))) < 9.9999999999999995e-8

    1. Initial program 20.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)}{\pi} \]
    2. Add Preprocessing
    3. Taylor expanded in B around inf

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C}{B} - \left(1 + \frac{A}{B}\right)\right)}}{\mathsf{PI}\left(\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{C}{B} - \color{blue}{\left(\frac{A}{B} + 1\right)}\right)}{\mathsf{PI}\left(\right)} \]
      2. associate--r+N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\left(\frac{C}{B} - \frac{A}{B}\right) - 1\right)}}{\mathsf{PI}\left(\right)} \]
      3. div-subN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\color{blue}{\frac{C - A}{B}} - 1\right)}{\mathsf{PI}\left(\right)} \]
      4. sub-negN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + \left(\mathsf{neg}\left(1\right)\right)\right)}}{\mathsf{PI}\left(\right)} \]
      5. metadata-evalN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + \color{blue}{-1}\right)}{\mathsf{PI}\left(\right)} \]
      6. lower-+.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + -1\right)}}{\mathsf{PI}\left(\right)} \]
      7. lower-/.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\color{blue}{\frac{C - A}{B}} + -1\right)}{\mathsf{PI}\left(\right)} \]
      8. lower--.f643.7

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(\frac{\color{blue}{C - A}}{B} + -1\right)}{\pi} \]
    5. Applied rewrites3.7%

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\frac{C - A}{B} + -1\right)}}{\pi} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{180 \cdot \frac{\tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      2. lift-/.f64N/A

        \[\leadsto 180 \cdot \color{blue}{\frac{\tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      3. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\mathsf{PI}\left(\right)}} \]
      5. lower-*.f643.7

        \[\leadsto \frac{\color{blue}{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}}{\pi} \]
    7. Applied rewrites3.7%

      \[\leadsto \color{blue}{\frac{180 \cdot \tan^{-1} \left(\frac{C - A}{B} + -1\right)}{\pi}} \]
    8. Taylor expanded in C around inf

      \[\leadsto \frac{180 \cdot \tan^{-1} \color{blue}{\left(-1 \cdot \frac{A + -1 \cdot A}{B} + \frac{-1}{2} \cdot \frac{B}{C}\right)}}{\mathsf{PI}\left(\right)} \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \color{blue}{\left(\frac{-1}{2} \cdot \frac{B}{C} + -1 \cdot \frac{A + -1 \cdot A}{B}\right)}}{\mathsf{PI}\left(\right)} \]
      2. associate-*r/N/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(\color{blue}{\frac{\frac{-1}{2} \cdot B}{C}} + -1 \cdot \frac{A + -1 \cdot A}{B}\right)}{\mathsf{PI}\left(\right)} \]
      3. *-commutativeN/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(\frac{\color{blue}{B \cdot \frac{-1}{2}}}{C} + -1 \cdot \frac{A + -1 \cdot A}{B}\right)}{\mathsf{PI}\left(\right)} \]
      4. associate-/l*N/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(\color{blue}{B \cdot \frac{\frac{-1}{2}}{C}} + -1 \cdot \frac{A + -1 \cdot A}{B}\right)}{\mathsf{PI}\left(\right)} \]
      5. associate-*r/N/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \color{blue}{\frac{-1 \cdot \left(A + -1 \cdot A\right)}{B}}\right)}{\mathsf{PI}\left(\right)} \]
      6. distribute-rgt1-inN/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{-1 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot A\right)}}{B}\right)}{\mathsf{PI}\left(\right)} \]
      7. metadata-evalN/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{-1 \cdot \left(\color{blue}{0} \cdot A\right)}{B}\right)}{\mathsf{PI}\left(\right)} \]
      8. mul0-lftN/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{-1 \cdot \color{blue}{0}}{B}\right)}{\mathsf{PI}\left(\right)} \]
      9. metadata-evalN/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \frac{\color{blue}{0}}{B}\right)}{\mathsf{PI}\left(\right)} \]
      10. div0N/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(B \cdot \frac{\frac{-1}{2}}{C} + \color{blue}{0}\right)}{\mathsf{PI}\left(\right)} \]
      11. lower-fma.f64N/A

        \[\leadsto \frac{180 \cdot \tan^{-1} \color{blue}{\left(\mathsf{fma}\left(B, \frac{\frac{-1}{2}}{C}, 0\right)\right)}}{\mathsf{PI}\left(\right)} \]
      12. lower-/.f6452.2

        \[\leadsto \frac{180 \cdot \tan^{-1} \left(\mathsf{fma}\left(B, \color{blue}{\frac{-0.5}{C}}, 0\right)\right)}{\pi} \]
    10. Applied rewrites52.2%

      \[\leadsto \frac{180 \cdot \tan^{-1} \color{blue}{\left(\mathsf{fma}\left(B, \frac{-0.5}{C}, 0\right)\right)}}{\pi} \]

    if 9.9999999999999995e-8 < (*.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))))))

    1. Initial program 59.5%

      \[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)}{\pi} \]
    2. Add Preprocessing
    3. Taylor expanded in B around -inf

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(\left(1 + \frac{C}{B}\right) - \frac{A}{B}\right)}}{\mathsf{PI}\left(\right)} \]
    4. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(1 + \left(\frac{C}{B} - \frac{A}{B}\right)\right)}}{\mathsf{PI}\left(\right)} \]
      2. div-subN/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(1 + \color{blue}{\frac{C - A}{B}}\right)}{\mathsf{PI}\left(\right)} \]
      3. lower-+.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(1 + \frac{C - A}{B}\right)}}{\mathsf{PI}\left(\right)} \]
      4. lower-/.f64N/A

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(1 + \color{blue}{\frac{C - A}{B}}\right)}{\mathsf{PI}\left(\right)} \]
      5. lower--.f6476.5

        \[\leadsto 180 \cdot \frac{\tan^{-1} \left(1 + \frac{\color{blue}{C - A}}{B}\right)}{\pi} \]
    5. Applied rewrites76.5%

      \[\leadsto 180 \cdot \frac{\tan^{-1} \color{blue}{\left(1 + \frac{C - A}{B}\right)}}{\pi} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2024219 
(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)))