Average Error: 52.9 → 33.6
Time: 34.9s
Precision: binary64
\[[A, C] = \mathsf{sort}([A, C]) \\]
\[\frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)\\ \mathbf{if}\;C \leq -5.699986030362876 \cdot 10^{-108}:\\ \;\;\;\;\frac{A \cdot \left(\sqrt{2} \cdot \sqrt{-8 \cdot \left(C \cdot F\right)}\right)}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \mathsf{hypot}\left(B, A - C\right)\\ \mathbf{if}\;C \leq -3.073995699162904 \cdot 10^{-304}:\\ \;\;\;\;\frac{-\sqrt{t_0 \cdot \left(2 \cdot \left(F \cdot \left(A + \left(C - t_1\right)\right)\right)\right)}}{t_0}\\ \mathbf{elif}\;C \leq 3.028623453697263 \cdot 10^{+21}:\\ \;\;\;\;-\frac{\sqrt{2 \cdot \left(F \cdot \left(\left(C + A\right) - t_1\right)\right)}}{\sqrt{t_0}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{{\left(-F\right)}^{0.5}}{\sqrt{C}}\\ \end{array}\\ \end{array} \]
\frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C}
\begin{array}{l}
t_0 := \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)\\
\mathbf{if}\;C \leq -5.699986030362876 \cdot 10^{-108}:\\
\;\;\;\;\frac{A \cdot \left(\sqrt{2} \cdot \sqrt{-8 \cdot \left(C \cdot F\right)}\right)}{t_0}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \mathsf{hypot}\left(B, A - C\right)\\
\mathbf{if}\;C \leq -3.073995699162904 \cdot 10^{-304}:\\
\;\;\;\;\frac{-\sqrt{t_0 \cdot \left(2 \cdot \left(F \cdot \left(A + \left(C - t_1\right)\right)\right)\right)}}{t_0}\\

\mathbf{elif}\;C \leq 3.028623453697263 \cdot 10^{+21}:\\
\;\;\;\;-\frac{\sqrt{2 \cdot \left(F \cdot \left(\left(C + A\right) - t_1\right)\right)}}{\sqrt{t_0}}\\

\mathbf{else}:\\
\;\;\;\;-\frac{{\left(-F\right)}^{0.5}}{\sqrt{C}}\\


\end{array}\\


\end{array}
(FPCore (A B C F)
 :precision binary64
 (/
  (-
   (sqrt
    (*
     (* 2.0 (* (- (pow B 2.0) (* (* 4.0 A) C)) F))
     (- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
  (- (pow B 2.0) (* (* 4.0 A) C))))
(FPCore (A B C F)
 :precision binary64
 (let* ((t_0 (fma A (* C -4.0) (* B B))))
   (if (<= C -5.699986030362876e-108)
     (/ (* A (* (sqrt 2.0) (sqrt (* -8.0 (* C F))))) t_0)
     (let* ((t_1 (hypot B (- A C))))
       (if (<= C -3.073995699162904e-304)
         (/ (- (sqrt (* t_0 (* 2.0 (* F (+ A (- C t_1))))))) t_0)
         (if (<= C 3.028623453697263e+21)
           (- (/ (sqrt (* 2.0 (* F (- (+ C A) t_1)))) (sqrt t_0)))
           (- (/ (pow (- F) 0.5) (sqrt C)))))))))
double code(double A, double B, double C, double F) {
	return -sqrt((2.0 * ((pow(B, 2.0) - ((4.0 * A) * C)) * F)) * ((A + C) - sqrt(pow((A - C), 2.0) + pow(B, 2.0)))) / (pow(B, 2.0) - ((4.0 * A) * C));
}
double code(double A, double B, double C, double F) {
	double t_0 = fma(A, (C * -4.0), (B * B));
	double tmp;
	if (C <= -5.699986030362876e-108) {
		tmp = (A * (sqrt(2.0) * sqrt(-8.0 * (C * F)))) / t_0;
	} else {
		double t_1 = hypot(B, (A - C));
		double tmp_1;
		if (C <= -3.073995699162904e-304) {
			tmp_1 = -sqrt(t_0 * (2.0 * (F * (A + (C - t_1))))) / t_0;
		} else if (C <= 3.028623453697263e+21) {
			tmp_1 = -(sqrt(2.0 * (F * ((C + A) - t_1))) / sqrt(t_0));
		} else {
			tmp_1 = -(pow(-F, 0.5) / sqrt(C));
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus A

Bits error versus B

Bits error versus C

Bits error versus F

Derivation

  1. Split input into 4 regimes
  2. if C < -5.69998603036287621e-108

    1. Initial program 50.9

      \[\frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
    2. Simplified46.8

      \[\leadsto \color{blue}{\frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot \left(2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \]
    3. Taylor expanded in A around -inf 42.8

      \[\leadsto \frac{-\color{blue}{-1 \cdot \left(A \cdot \left(\sqrt{2} \cdot \sqrt{-8 \cdot \left(C \cdot F\right)}\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \]
    4. Simplified42.8

      \[\leadsto \frac{-\color{blue}{\left(-A \cdot \left(\sqrt{2} \cdot \sqrt{-8 \cdot \left(C \cdot F\right)}\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \]

    if -5.69998603036287621e-108 < C < -3.07399569916290406e-304

    1. Initial program 45.2

      \[\frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
    2. Simplified36.8

      \[\leadsto \color{blue}{\frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot \left(2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \]
    3. Applied associate--l+_binary6436.8

      \[\leadsto \frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot \left(2 \cdot \left(F \cdot \color{blue}{\left(A + \left(C - \mathsf{hypot}\left(B, A - C\right)\right)\right)}\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \]

    if -3.07399569916290406e-304 < C < 3.0286234536972627e21

    1. Initial program 45.7

      \[\frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
    2. Simplified42.2

      \[\leadsto \color{blue}{\frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot \left(2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \]
    3. Applied add-sqr-sqrt_binary6442.5

      \[\leadsto \frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot \left(2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}{\color{blue}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}} \]
    4. Applied sqrt-prod_binary6434.7

      \[\leadsto \frac{-\color{blue}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)}}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \]
    5. Applied distribute-lft-neg-in_binary6434.7

      \[\leadsto \frac{\color{blue}{\left(-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}\right) \cdot \sqrt{2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)}}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \]
    6. Applied times-frac_binary6434.6

      \[\leadsto \color{blue}{\frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \cdot \frac{\sqrt{2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}} \]
    7. Simplified34.1

      \[\leadsto \color{blue}{-1} \cdot \frac{\sqrt{2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \]

    if 3.0286234536972627e21 < C

    1. Initial program 61.9

      \[\frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
    2. Simplified60.8

      \[\leadsto \color{blue}{\frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot \left(2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \]
    3. Taylor expanded in A around -inf 38.3

      \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{-0.5 \cdot \frac{F}{C}} \cdot \sqrt{2}\right)} \]
    4. Simplified38.3

      \[\leadsto \color{blue}{-\sqrt{-0.5 \cdot \frac{F}{C}} \cdot \sqrt{2}} \]
    5. Applied associate-*r/_binary6438.3

      \[\leadsto -\sqrt{\color{blue}{\frac{-0.5 \cdot F}{C}}} \cdot \sqrt{2} \]
    6. Applied sqrt-div_binary6429.9

      \[\leadsto -\color{blue}{\frac{\sqrt{-0.5 \cdot F}}{\sqrt{C}}} \cdot \sqrt{2} \]
    7. Applied associate-*l/_binary6429.9

      \[\leadsto -\color{blue}{\frac{\sqrt{-0.5 \cdot F} \cdot \sqrt{2}}{\sqrt{C}}} \]
    8. Applied add-sqr-sqrt_binary6429.9

      \[\leadsto -\frac{\sqrt{-0.5 \cdot F} \cdot \color{blue}{\left(\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{2}}\right)}}{\sqrt{C}} \]
    9. Applied associate-*r*_binary6429.9

      \[\leadsto -\frac{\color{blue}{\left(\sqrt{-0.5 \cdot F} \cdot \sqrt{\sqrt{2}}\right) \cdot \sqrt{\sqrt{2}}}}{\sqrt{C}} \]
    10. Applied pow1_binary6429.9

      \[\leadsto -\frac{\left(\sqrt{-0.5 \cdot F} \cdot \sqrt{\sqrt{2}}\right) \cdot \sqrt{\color{blue}{{\left(\sqrt{2}\right)}^{1}}}}{\sqrt{C}} \]
    11. Applied sqrt-pow1_binary6429.9

      \[\leadsto -\frac{\left(\sqrt{-0.5 \cdot F} \cdot \sqrt{\sqrt{2}}\right) \cdot \color{blue}{{\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}}{\sqrt{C}} \]
    12. Applied pow1_binary6429.9

      \[\leadsto -\frac{\left(\sqrt{-0.5 \cdot F} \cdot \sqrt{\color{blue}{{\left(\sqrt{2}\right)}^{1}}}\right) \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
    13. Applied sqrt-pow1_binary6429.9

      \[\leadsto -\frac{\left(\sqrt{-0.5 \cdot F} \cdot \color{blue}{{\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}\right) \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
    14. Applied pow1_binary6429.9

      \[\leadsto -\frac{\left(\sqrt{-0.5 \cdot \color{blue}{{F}^{1}}} \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
    15. Applied pow1_binary6429.9

      \[\leadsto -\frac{\left(\sqrt{\color{blue}{{-0.5}^{1}} \cdot {F}^{1}} \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
    16. Applied pow-prod-down_binary6429.9

      \[\leadsto -\frac{\left(\sqrt{\color{blue}{{\left(-0.5 \cdot F\right)}^{1}}} \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
    17. Applied sqrt-pow1_binary6429.9

      \[\leadsto -\frac{\left(\color{blue}{{\left(-0.5 \cdot F\right)}^{\left(\frac{1}{2}\right)}} \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
    18. Applied pow-prod-down_binary6429.8

      \[\leadsto -\frac{\color{blue}{{\left(\left(-0.5 \cdot F\right) \cdot \sqrt{2}\right)}^{\left(\frac{1}{2}\right)}} \cdot {\left(\sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
    19. Applied pow-prod-down_binary6429.9

      \[\leadsto -\frac{\color{blue}{{\left(\left(\left(-0.5 \cdot F\right) \cdot \sqrt{2}\right) \cdot \sqrt{2}\right)}^{\left(\frac{1}{2}\right)}}}{\sqrt{C}} \]
    20. Simplified29.8

      \[\leadsto -\frac{{\color{blue}{\left(-F\right)}}^{\left(\frac{1}{2}\right)}}{\sqrt{C}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification33.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;C \leq -5.699986030362876 \cdot 10^{-108}:\\ \;\;\;\;\frac{A \cdot \left(\sqrt{2} \cdot \sqrt{-8 \cdot \left(C \cdot F\right)}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}\\ \mathbf{elif}\;C \leq -3.073995699162904 \cdot 10^{-304}:\\ \;\;\;\;\frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot \left(2 \cdot \left(F \cdot \left(A + \left(C - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}\\ \mathbf{elif}\;C \leq 3.028623453697263 \cdot 10^{+21}:\\ \;\;\;\;-\frac{\sqrt{2 \cdot \left(F \cdot \left(\left(C + A\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{{\left(-F\right)}^{0.5}}{\sqrt{C}}\\ \end{array} \]

Reproduce

herbie shell --seed 2022081 
(FPCore (A B C F)
  :name "ABCF->ab-angle b"
  :precision binary64
  (/ (- (sqrt (* (* 2.0 (* (- (pow B 2.0) (* (* 4.0 A) C)) F)) (- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))) (- (pow B 2.0) (* (* 4.0 A) C))))