Average Error: 52.1 → 34.6
Time: 34.0s
Precision: binary64
Cost: 21128
\[ \begin{array}{c}[A, C] = \mathsf{sort}([A, C])\\ \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(B, B, C \cdot \left(A \cdot -4\right)\right)\\ \mathbf{if}\;B \leq -3.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\ \mathbf{elif}\;B \leq 54:\\ \;\;\;\;\sqrt{\left(2 \cdot t_0\right) \cdot \left(F \cdot \left(A + A\right)\right)} \cdot \frac{1}{-t_0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\ \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 B B (* C (* A -4.0)))))
   (if (<= B -3.5e-67)
     (* (/ (sqrt 2.0) B) (sqrt (* F (- A (hypot A B)))))
     (if (<= B 54.0)
       (* (sqrt (* (* 2.0 t_0) (* F (+ A A)))) (/ 1.0 (- t_0)))
       (* (sqrt (* F (- A (hypot B A)))) (/ (- (sqrt 2.0)) B))))))
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(B, B, (C * (A * -4.0)));
	double tmp;
	if (B <= -3.5e-67) {
		tmp = (sqrt(2.0) / B) * sqrt((F * (A - hypot(A, B))));
	} else if (B <= 54.0) {
		tmp = sqrt(((2.0 * t_0) * (F * (A + A)))) * (1.0 / -t_0);
	} else {
		tmp = sqrt((F * (A - hypot(B, A)))) * (-sqrt(2.0) / B);
	}
	return tmp;
}
function code(A, B, C, F)
	return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)))
end
function code(A, B, C, F)
	t_0 = fma(B, B, Float64(C * Float64(A * -4.0)))
	tmp = 0.0
	if (B <= -3.5e-67)
		tmp = Float64(Float64(sqrt(2.0) / B) * sqrt(Float64(F * Float64(A - hypot(A, B)))));
	elseif (B <= 54.0)
		tmp = Float64(sqrt(Float64(Float64(2.0 * t_0) * Float64(F * Float64(A + A)))) * Float64(1.0 / Float64(-t_0)));
	else
		tmp = Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * Float64(Float64(-sqrt(2.0)) / B));
	end
	return tmp
end
code[A_, B_, C_, F_] := N[((-N[Sqrt[N[(N[(2.0 * N[(N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(B * B + N[(C * N[(A * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, -3.5e-67], N[(N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision] * N[Sqrt[N[(F * N[(A - N[Sqrt[A ^ 2 + B ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[B, 54.0], N[(N[Sqrt[N[(N[(2.0 * t$95$0), $MachinePrecision] * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 / (-t$95$0)), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]]]
\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(B, B, C \cdot \left(A \cdot -4\right)\right)\\
\mathbf{if}\;B \leq -3.5 \cdot 10^{-67}:\\
\;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\

\mathbf{elif}\;B \leq 54:\\
\;\;\;\;\sqrt{\left(2 \cdot t_0\right) \cdot \left(F \cdot \left(A + A\right)\right)} \cdot \frac{1}{-t_0}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if B < -3.5e-67

    1. Initial program 52.5

      \[\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. Taylor expanded in C around 0 63.4

      \[\leadsto \frac{-\color{blue}{\sqrt{\left(A - \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F} \cdot \left(\sqrt{2} \cdot B\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
    3. Simplified62.8

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{2}}{B} \cdot \sqrt{\left(A - \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F}} \]
    6. Simplified34.9

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

    if -3.5e-67 < B < 54

    1. Initial program 50.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. Applied egg-rr43.5

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

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

    if 54 < B

    1. Initial program 55.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. Applied egg-rr52.9

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\frac{\sqrt{2}}{B} \cdot \sqrt{\left(A - \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F}\right)} \]
    7. Simplified33.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;B \leq -3.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\ \mathbf{elif}\;B \leq 54:\\ \;\;\;\;\sqrt{\left(2 \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\right) \cdot \left(F \cdot \left(A + A\right)\right)} \cdot \frac{1}{-\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\ \end{array} \]

Alternatives

Alternative 1
Error34.6
Cost21000
\[\begin{array}{l} t_0 := \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\\ \mathbf{if}\;B \leq -3.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\ \mathbf{elif}\;B \leq 5 \cdot 10^{+15}:\\ \;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(A + A\right) \cdot \left(F \cdot t_0\right)\right)}}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\ \end{array} \]
Alternative 2
Error38.2
Cost20300
\[\begin{array}{l} \mathbf{if}\;B \leq -2.4 \cdot 10^{-107}:\\ \;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\ \mathbf{elif}\;B \leq 4.5 \cdot 10^{-102}:\\ \;\;\;\;\frac{1}{-\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(F \cdot C\right)\right)}\\ \mathbf{elif}\;B \leq 10^{+135}:\\ \;\;\;\;\frac{\sqrt{\left(A - \mathsf{hypot}\left(B, A\right)\right) \cdot \left(2 \cdot F\right)} \cdot \left(-B\right)}{B \cdot B + -4 \cdot \left(A \cdot C\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{F \cdot \left(C - \mathsf{hypot}\left(B, C\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\ \end{array} \]
Alternative 3
Error37.9
Cost20168
\[\begin{array}{l} \mathbf{if}\;B \leq -2.4 \cdot 10^{-107}:\\ \;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\ \mathbf{elif}\;B \leq 8.2 \cdot 10^{-95}:\\ \;\;\;\;\frac{1}{-\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(F \cdot C\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\ \end{array} \]
Alternative 4
Error41.7
Cost19972
\[\begin{array}{l} \mathbf{if}\;B \leq -2.4 \cdot 10^{-107}:\\ \;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(A, B\right)\right)}\\ \mathbf{elif}\;B \leq 4.5 \cdot 10^{-102}:\\ \;\;\;\;\frac{1}{-\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(F \cdot C\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\left(A - \mathsf{hypot}\left(B, A\right)\right) \cdot \left(2 \cdot F\right)} \cdot \left(-B\right)}{B \cdot B + -4 \cdot \left(A \cdot C\right)}\\ \end{array} \]
Alternative 5
Error45.6
Cost14472
\[\begin{array}{l} t_0 := \sqrt{\left(A - \mathsf{hypot}\left(B, A\right)\right) \cdot \left(2 \cdot F\right)}\\ \mathbf{if}\;B \leq -2.4 \cdot 10^{-107}:\\ \;\;\;\;\left(B \cdot t_0\right) \cdot \frac{1}{B \cdot B}\\ \mathbf{elif}\;B \leq 4.5 \cdot 10^{-102}:\\ \;\;\;\;\frac{1}{-\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(F \cdot C\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 \cdot \left(-B\right)}{B \cdot B + -4 \cdot \left(A \cdot C\right)}\\ \end{array} \]
Alternative 6
Error47.4
Cost14408
\[\begin{array}{l} t_0 := \sqrt{\left(A - \mathsf{hypot}\left(B, A\right)\right) \cdot \left(2 \cdot F\right)}\\ \mathbf{if}\;B \leq -2.4 \cdot 10^{-107}:\\ \;\;\;\;\left(B \cdot t_0\right) \cdot \frac{1}{B \cdot B}\\ \mathbf{elif}\;B \leq 4.5 \cdot 10^{-102}:\\ \;\;\;\;\frac{1}{-\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{\left(F \cdot C\right) \cdot \left(-16 \cdot \left(A \cdot A\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 \cdot \left(-B\right)}{B \cdot B + -4 \cdot \left(A \cdot C\right)}\\ \end{array} \]
Alternative 7
Error47.5
Cost14344
\[\begin{array}{l} t_0 := \sqrt{\left(A - \mathsf{hypot}\left(B, A\right)\right) \cdot \left(2 \cdot F\right)}\\ \mathbf{if}\;B \leq -2.4 \cdot 10^{-107}:\\ \;\;\;\;\left(B \cdot t_0\right) \cdot \frac{1}{B \cdot B}\\ \mathbf{elif}\;B \leq 4.5 \cdot 10^{-102}:\\ \;\;\;\;\frac{1}{-\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{\left(F \cdot C\right) \cdot \left(-16 \cdot \left(A \cdot A\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 \cdot \left(-B\right)}{B \cdot B}\\ \end{array} \]
Alternative 8
Error53.0
Cost13956
\[\begin{array}{l} t_0 := \sqrt{\left(A - \mathsf{hypot}\left(B, A\right)\right) \cdot \left(2 \cdot F\right)}\\ \mathbf{if}\;B \leq -4.5 \cdot 10^{-146}:\\ \;\;\;\;\left(B \cdot t_0\right) \cdot \frac{1}{B \cdot B}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 \cdot \left(-B\right)}{B \cdot B}\\ \end{array} \]
Alternative 9
Error58.0
Cost13760
\[\frac{\sqrt{\left(A - \mathsf{hypot}\left(B, A\right)\right) \cdot \left(2 \cdot F\right)} \cdot \left(-B\right)}{B \cdot B} \]
Alternative 10
Error61.6
Cost64
\[0 \]

Error

Reproduce

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