Average Error: 52.0 → 41.4
Time: 1.4min
Precision: binary64
\[\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{hypot}\left(B, A - C\right)\\ t_1 := \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)\\ t_2 := \sqrt{2 \cdot t_1}\\ \mathbf{if}\;C \leq -5.535441828491868 \cdot 10^{-34}:\\ \;\;\;\;-\sqrt{-0.5 \cdot \frac{F}{C}} \cdot \sqrt{2}\\ \mathbf{elif}\;C \leq 2.0318267948283777 \cdot 10^{-124}:\\ \;\;\;\;\frac{-t_2 \cdot \left(\sqrt{F} \cdot \sqrt{\mathsf{fma}\left(1, C + A, t_0\right)}\right)}{t_1}\\ \mathbf{elif}\;C \leq 6.316120380681736 \cdot 10^{+48}:\\ \;\;\;\;\frac{-t_2 \cdot \sqrt{F \cdot \left(C + \sqrt{{C}^{2} + {B}^{2}}\right)}}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{-t_2 \cdot \left(\sqrt{F} \cdot \sqrt{\mathsf{fma}\left(1, A, C + t_0\right)}\right)}{t_1}\\ \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{hypot}\left(B, A - C\right)\\
t_1 := \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)\\
t_2 := \sqrt{2 \cdot t_1}\\
\mathbf{if}\;C \leq -5.535441828491868 \cdot 10^{-34}:\\
\;\;\;\;-\sqrt{-0.5 \cdot \frac{F}{C}} \cdot \sqrt{2}\\

\mathbf{elif}\;C \leq 2.0318267948283777 \cdot 10^{-124}:\\
\;\;\;\;\frac{-t_2 \cdot \left(\sqrt{F} \cdot \sqrt{\mathsf{fma}\left(1, C + A, t_0\right)}\right)}{t_1}\\

\mathbf{elif}\;C \leq 6.316120380681736 \cdot 10^{+48}:\\
\;\;\;\;\frac{-t_2 \cdot \sqrt{F \cdot \left(C + \sqrt{{C}^{2} + {B}^{2}}\right)}}{t_1}\\

\mathbf{else}:\\
\;\;\;\;\frac{-t_2 \cdot \left(\sqrt{F} \cdot \sqrt{\mathsf{fma}\left(1, A, C + t_0\right)}\right)}{t_1}\\


\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 (hypot B (- A C)))
        (t_1 (fma A (* C -4.0) (* B B)))
        (t_2 (sqrt (* 2.0 t_1))))
   (if (<= C -5.535441828491868e-34)
     (- (* (sqrt (* -0.5 (/ F C))) (sqrt 2.0)))
     (if (<= C 2.0318267948283777e-124)
       (/ (- (* t_2 (* (sqrt F) (sqrt (fma 1.0 (+ C A) t_0))))) t_1)
       (if (<= C 6.316120380681736e+48)
         (/
          (- (* t_2 (sqrt (* F (+ C (sqrt (+ (pow C 2.0) (pow B 2.0))))))))
          t_1)
         (/ (- (* t_2 (* (sqrt F) (sqrt (fma 1.0 A (+ C t_0)))))) t_1))))))
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 = hypot(B, (A - C));
	double t_1 = fma(A, (C * -4.0), (B * B));
	double t_2 = sqrt((2.0 * t_1));
	double tmp;
	if (C <= -5.535441828491868e-34) {
		tmp = -(sqrt((-0.5 * (F / C))) * sqrt(2.0));
	} else if (C <= 2.0318267948283777e-124) {
		tmp = -(t_2 * (sqrt(F) * sqrt(fma(1.0, (C + A), t_0)))) / t_1;
	} else if (C <= 6.316120380681736e+48) {
		tmp = -(t_2 * sqrt((F * (C + sqrt((pow(C, 2.0) + pow(B, 2.0))))))) / t_1;
	} else {
		tmp = -(t_2 * (sqrt(F) * sqrt(fma(1.0, A, (C + t_0))))) / t_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.5354418284918682e-34

    1. Initial program 60.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. Simplified59.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. Taylor expanded in A around inf 40.3

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

      \[\leadsto \color{blue}{-\sqrt{-0.5 \cdot \frac{F}{C}} \cdot \sqrt{2}} \]

    if -5.5354418284918682e-34 < C < 2.0318267948283777e-124

    1. Initial program 48.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. Simplified45.4

      \[\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 egg-rr42.7

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

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

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

    if 2.0318267948283777e-124 < C < 6.31612038068173587e48

    1. Initial program 41.6

      \[\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. Simplified40.0

      \[\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 egg-rr44.5

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

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

    if 6.31612038068173587e48 < C

    1. Initial program 54.8

      \[\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. Simplified48.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 egg-rr50.5

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

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

      \[\leadsto \frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right) \cdot 2} \cdot \left(\sqrt{F} \cdot \sqrt{\color{blue}{\mathsf{fma}\left(1, A, C + \mathsf{hypot}\left(B, A - C\right)\right)}}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification41.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;C \leq -5.535441828491868 \cdot 10^{-34}:\\ \;\;\;\;-\sqrt{-0.5 \cdot \frac{F}{C}} \cdot \sqrt{2}\\ \mathbf{elif}\;C \leq 2.0318267948283777 \cdot 10^{-124}:\\ \;\;\;\;\frac{-\sqrt{2 \cdot \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \left(\sqrt{F} \cdot \sqrt{\mathsf{fma}\left(1, C + A, \mathsf{hypot}\left(B, A - C\right)\right)}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}\\ \mathbf{elif}\;C \leq 6.316120380681736 \cdot 10^{+48}:\\ \;\;\;\;\frac{-\sqrt{2 \cdot \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{F \cdot \left(C + \sqrt{{C}^{2} + {B}^{2}}\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\sqrt{2 \cdot \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \left(\sqrt{F} \cdot \sqrt{\mathsf{fma}\left(1, A, C + \mathsf{hypot}\left(B, A - C\right)\right)}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (A B C F)
  :name "ABCF->ab-angle a"
  :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))))