Average Error: 52.3 → 31.6
Time: 34.8s
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 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\ t_1 := \frac{-\sqrt{\left(2 \cdot \left(t_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{t_0}\\ t_2 := \sqrt{-F}\\ \mathbf{if}\;t_1 \leq -4.219261108436416 \cdot 10^{+203}:\\ \;\;\;\;\frac{-1}{\frac{\sqrt{C}}{t_2}}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_3 := \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)\\ \mathbf{if}\;t_1 \leq -1.9628409073321262 \cdot 10^{-202}:\\ \;\;\;\;\frac{-1}{\frac{t_3}{\sqrt{t_3 \cdot \left(2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}}\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;-\frac{{\left(-F\right)}^{0.5}}{\sqrt{C}}\\ \mathbf{elif}\;t_1 \leq \infty:\\ \;\;\;\;\begin{array}{l} t_4 := \sqrt{-8 \cdot \left(C \cdot F\right)}\\ \frac{\mathsf{fma}\left(A, \sqrt{2} \cdot t_4, \frac{F \cdot \left(\left(B \cdot B\right) \cdot \sqrt{2}\right)}{t_4}\right)}{t_3} \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \frac{-1}{\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 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
t_1 := \frac{-\sqrt{\left(2 \cdot \left(t_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{t_0}\\
t_2 := \sqrt{-F}\\
\mathbf{if}\;t_1 \leq -4.219261108436416 \cdot 10^{+203}:\\
\;\;\;\;\frac{-1}{\frac{\sqrt{C}}{t_2}}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := \mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)\\
\mathbf{if}\;t_1 \leq -1.9628409073321262 \cdot 10^{-202}:\\
\;\;\;\;\frac{-1}{\frac{t_3}{\sqrt{t_3 \cdot \left(2 \cdot \left(F \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}}\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;-\frac{{\left(-F\right)}^{0.5}}{\sqrt{C}}\\

\mathbf{elif}\;t_1 \leq \infty:\\
\;\;\;\;\begin{array}{l}
t_4 := \sqrt{-8 \cdot \left(C \cdot F\right)}\\
\frac{\mathsf{fma}\left(A, \sqrt{2} \cdot t_4, \frac{F \cdot \left(\left(B \cdot B\right) \cdot \sqrt{2}\right)}{t_4}\right)}{t_3}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;t_2 \cdot \frac{-1}{\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 (- (pow B 2.0) (* (* 4.0 A) C)))
        (t_1
         (/
          (-
           (sqrt
            (*
             (* 2.0 (* t_0 F))
             (- (+ A C) (sqrt (+ (pow B 2.0) (pow (- A C) 2.0)))))))
          t_0))
        (t_2 (sqrt (- F))))
   (if (<= t_1 -4.219261108436416e+203)
     (/ -1.0 (/ (sqrt C) t_2))
     (let* ((t_3 (fma A (* C -4.0) (* B B))))
       (if (<= t_1 -1.9628409073321262e-202)
         (/
          -1.0
          (/ t_3 (sqrt (* t_3 (* 2.0 (* F (- (+ A C) (hypot B (- A C)))))))))
         (if (<= t_1 0.0)
           (- (/ (pow (- F) 0.5) (sqrt C)))
           (if (<= t_1 INFINITY)
             (let* ((t_4 (sqrt (* -8.0 (* C F)))))
               (/
                (fma A (* (sqrt 2.0) t_4) (/ (* F (* (* B B) (sqrt 2.0))) t_4))
                t_3))
             (* t_2 (/ -1.0 (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 = pow(B, 2.0) - ((4.0 * A) * C);
	double t_1 = -sqrt((2.0 * (t_0 * F)) * ((A + C) - sqrt(pow(B, 2.0) + pow((A - C), 2.0)))) / t_0;
	double t_2 = sqrt(-F);
	double tmp;
	if (t_1 <= -4.219261108436416e+203) {
		tmp = -1.0 / (sqrt(C) / t_2);
	} else {
		double t_3 = fma(A, (C * -4.0), (B * B));
		double tmp_1;
		if (t_1 <= -1.9628409073321262e-202) {
			tmp_1 = -1.0 / (t_3 / sqrt(t_3 * (2.0 * (F * ((A + C) - hypot(B, (A - C)))))));
		} else if (t_1 <= 0.0) {
			tmp_1 = -(pow(-F, 0.5) / sqrt(C));
		} else if (t_1 <= ((double) INFINITY)) {
			double t_4 = sqrt(-8.0 * (C * F));
			tmp_1 = fma(A, (sqrt(2.0) * t_4), ((F * ((B * B) * sqrt(2.0))) / t_4)) / t_3;
		} else {
			tmp_1 = t_2 * (-1.0 / 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 5 regimes
  2. if (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < -4.2192611084364161e203

    1. Initial program 62.3

      \[\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. Simplified52.7

      \[\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 36.1

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

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

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

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

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

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

      \[\leadsto -\frac{\sqrt{\color{blue}{-F}}}{\sqrt{C}} \]
    10. Applied clear-num_binary6423.6

      \[\leadsto -\color{blue}{\frac{1}{\frac{\sqrt{C}}{\sqrt{-F}}}} \]

    if -4.2192611084364161e203 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < -1.962840907332126e-202

    1. Initial program 1.1

      \[\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. Simplified1.3

      \[\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 *-un-lft-identity_binary641.3

      \[\leadsto \frac{-\color{blue}{1 \cdot \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)} \]
    4. Applied distribute-lft-neg-in_binary641.3

      \[\leadsto \frac{\color{blue}{\left(-1\right) \cdot \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)} \]
    5. Applied associate-/l*_binary641.4

      \[\leadsto \color{blue}{\frac{-1}{\frac{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}{\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)}}}} \]

    if -1.962840907332126e-202 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < 0.0

    1. Initial program 60.3

      \[\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. Simplified58.9

      \[\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 33.5

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

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

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

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

      \[\leadsto -\color{blue}{\frac{\sqrt{-0.5 \cdot F} \cdot \sqrt{2}}{\sqrt{C}}} \]
    8. Applied pow1/2_binary6430.3

      \[\leadsto -\frac{\sqrt{-0.5 \cdot F} \cdot \color{blue}{{2}^{0.5}}}{\sqrt{C}} \]
    9. Applied pow1/2_binary6430.3

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

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

      \[\leadsto -\frac{{\color{blue}{\left(-F\right)}}^{0.5}}{\sqrt{C}} \]

    if 0.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < +inf.0

    1. Initial program 38.4

      \[\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. Simplified25.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 15.9

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

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

    if +inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)))

    1. Initial program 64.0

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

      \[\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 52.4

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

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

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

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

      \[\leadsto -\color{blue}{\frac{\sqrt{-0.5 \cdot F} \cdot \sqrt{2}}{\sqrt{C}}} \]
    8. Applied sqrt-unprod_binary6448.5

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

      \[\leadsto -\frac{\sqrt{\color{blue}{-F}}}{\sqrt{C}} \]
    10. Applied div-inv_binary6448.5

      \[\leadsto -\color{blue}{\sqrt{-F} \cdot \frac{1}{\sqrt{C}}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification31.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\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{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \leq -4.219261108436416 \cdot 10^{+203}:\\ \;\;\;\;\frac{-1}{\frac{\sqrt{C}}{\sqrt{-F}}}\\ \mathbf{elif}\;\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{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \leq -1.9628409073321262 \cdot 10^{-202}:\\ \;\;\;\;\frac{-1}{\frac{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}{\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)}}}\\ \mathbf{elif}\;\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{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \leq 0:\\ \;\;\;\;-\frac{{\left(-F\right)}^{0.5}}{\sqrt{C}}\\ \mathbf{elif}\;\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{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \leq \infty:\\ \;\;\;\;\frac{\mathsf{fma}\left(A, \sqrt{2} \cdot \sqrt{-8 \cdot \left(C \cdot F\right)}, \frac{F \cdot \left(\left(B \cdot B\right) \cdot \sqrt{2}\right)}{\sqrt{-8 \cdot \left(C \cdot F\right)}}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-F} \cdot \frac{-1}{\sqrt{C}}\\ \end{array} \]

Reproduce

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