ABCF->ab-angle a

Percentage Accurate: 18.6% → 49.5%
Time: 20.2s
Alternatives: 9
Speedup: 16.9×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\ \frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0} \end{array} \end{array} \]
(FPCore (A B C F)
 :precision binary64
 (let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
   (/
    (-
     (sqrt
      (*
       (* 2.0 (* t_0 F))
       (+ (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
    t_0)))
double code(double A, double B, double C, double F) {
	double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
	return -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_0;
}
real(8) function code(a, b, c, f)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: f
    real(8) :: t_0
    t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
    code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) + sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
	double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
	return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F):
	t_0 = math.pow(B, 2.0) - ((4.0 * A) * C)
	return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F)
	t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C))
	return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) + sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0)
end
function tmp = code(A, B, C, F)
	t_0 = (B ^ 2.0) - ((4.0 * A) * C);
	tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0;
end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * 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]) / t$95$0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0}
\end{array}
\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 9 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: 18.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\ \frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0} \end{array} \end{array} \]
(FPCore (A B C F)
 :precision binary64
 (let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
   (/
    (-
     (sqrt
      (*
       (* 2.0 (* t_0 F))
       (+ (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
    t_0)))
double code(double A, double B, double C, double F) {
	double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
	return -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_0;
}
real(8) function code(a, b, c, f)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: f
    real(8) :: t_0
    t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
    code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) + sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
	double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
	return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F):
	t_0 = math.pow(B, 2.0) - ((4.0 * A) * C)
	return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F)
	t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C))
	return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) + sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0)
end
function tmp = code(A, B, C, F)
	t_0 = (B ^ 2.0) - ((4.0 * A) * C);
	tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0;
end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * 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]) / t$95$0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0}
\end{array}
\end{array}

Alternative 1: 49.5% accurate, 1.7× speedup?

\[\begin{array}{l} B_m = \left|B\right| \\ [A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\ \\ \begin{array}{l} t_0 := \mathsf{fma}\left(B\_m, B\_m, -4 \cdot \left(A \cdot C\right)\right)\\ \mathbf{if}\;{B\_m}^{2} \leq 5 \cdot 10^{-257}:\\ \;\;\;\;\frac{\sqrt{\left(F \cdot \left(2 \cdot t\_0\right)\right) \cdot \left(2 \cdot C\right)}}{-t\_0}\\ \mathbf{elif}\;{B\_m}^{2} \leq 5 \cdot 10^{+104}:\\ \;\;\;\;\left(-\sqrt{F}\right) \cdot \left(\sqrt{\frac{\left(B\_m \cdot B\_m\right) \cdot -0.5}{A}} \cdot \frac{\sqrt{2}}{B\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{\sqrt{2 \cdot F}}{\sqrt{B\_m}}\\ \end{array} \end{array} \]
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
 :precision binary64
 (let* ((t_0 (fma B_m B_m (* -4.0 (* A C)))))
   (if (<= (pow B_m 2.0) 5e-257)
     (/ (sqrt (* (* F (* 2.0 t_0)) (* 2.0 C))) (- t_0))
     (if (<= (pow B_m 2.0) 5e+104)
       (*
        (- (sqrt F))
        (* (sqrt (/ (* (* B_m B_m) -0.5) A)) (/ (sqrt 2.0) B_m)))
       (- (/ (sqrt (* 2.0 F)) (sqrt B_m)))))))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
	double t_0 = fma(B_m, B_m, (-4.0 * (A * C)));
	double tmp;
	if (pow(B_m, 2.0) <= 5e-257) {
		tmp = sqrt(((F * (2.0 * t_0)) * (2.0 * C))) / -t_0;
	} else if (pow(B_m, 2.0) <= 5e+104) {
		tmp = -sqrt(F) * (sqrt((((B_m * B_m) * -0.5) / A)) * (sqrt(2.0) / B_m));
	} else {
		tmp = -(sqrt((2.0 * F)) / sqrt(B_m));
	}
	return tmp;
}
B_m = abs(B)
A, B_m, C, F = sort([A, B_m, C, F])
function code(A, B_m, C, F)
	t_0 = fma(B_m, B_m, Float64(-4.0 * Float64(A * C)))
	tmp = 0.0
	if ((B_m ^ 2.0) <= 5e-257)
		tmp = Float64(sqrt(Float64(Float64(F * Float64(2.0 * t_0)) * Float64(2.0 * C))) / Float64(-t_0));
	elseif ((B_m ^ 2.0) <= 5e+104)
		tmp = Float64(Float64(-sqrt(F)) * Float64(sqrt(Float64(Float64(Float64(B_m * B_m) * -0.5) / A)) * Float64(sqrt(2.0) / B_m)));
	else
		tmp = Float64(-Float64(sqrt(Float64(2.0 * F)) / sqrt(B_m)));
	end
	return tmp
end
B_m = N[Abs[B], $MachinePrecision]
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
code[A_, B$95$m_, C_, F_] := Block[{t$95$0 = N[(B$95$m * B$95$m + N[(-4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 5e-257], N[(N[Sqrt[N[(N[(F * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] * N[(2.0 * C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-t$95$0)), $MachinePrecision], If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 5e+104], N[((-N[Sqrt[F], $MachinePrecision]) * N[(N[Sqrt[N[(N[(N[(B$95$m * B$95$m), $MachinePrecision] * -0.5), $MachinePrecision] / A), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(N[Sqrt[N[(2.0 * F), $MachinePrecision]], $MachinePrecision] / N[Sqrt[B$95$m], $MachinePrecision]), $MachinePrecision])]]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(B\_m, B\_m, -4 \cdot \left(A \cdot C\right)\right)\\
\mathbf{if}\;{B\_m}^{2} \leq 5 \cdot 10^{-257}:\\
\;\;\;\;\frac{\sqrt{\left(F \cdot \left(2 \cdot t\_0\right)\right) \cdot \left(2 \cdot C\right)}}{-t\_0}\\

\mathbf{elif}\;{B\_m}^{2} \leq 5 \cdot 10^{+104}:\\
\;\;\;\;\left(-\sqrt{F}\right) \cdot \left(\sqrt{\frac{\left(B\_m \cdot B\_m\right) \cdot -0.5}{A}} \cdot \frac{\sqrt{2}}{B\_m}\right)\\

\mathbf{else}:\\
\;\;\;\;-\frac{\sqrt{2 \cdot F}}{\sqrt{B\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (pow.f64 B #s(literal 2 binary64)) < 4.99999999999999989e-257

    1. Initial program 24.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. Add Preprocessing
    3. Taylor expanded in A around 0

      \[\leadsto \frac{\mathsf{neg}\left(\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \color{blue}{\left(C + \sqrt{{B}^{2} + {C}^{2}}\right)}}\right)}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
    4. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \color{blue}{\left(C + \sqrt{{B}^{2} + {C}^{2}}\right)}}\right)}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
      2. lower-sqrt.f64N/A

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(C + \sqrt{\mathsf{fma}\left(C, C, \color{blue}{B \cdot B}\right)}\right)}\right)}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
      7. lower-*.f6430.3

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

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

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

      \[\leadsto \frac{\sqrt{\left(F \cdot \left(2 \cdot \mathsf{fma}\left(B, B, -4 \cdot \left(A \cdot C\right)\right)\right)\right) \cdot \color{blue}{\left(2 \cdot C\right)}}}{\mathsf{neg}\left(\mathsf{fma}\left(B, B, -4 \cdot \left(A \cdot C\right)\right)\right)} \]
    8. Step-by-step derivation
      1. lower-*.f6454.5

        \[\leadsto \frac{\sqrt{\left(F \cdot \left(2 \cdot \mathsf{fma}\left(B, B, -4 \cdot \left(A \cdot C\right)\right)\right)\right) \cdot \color{blue}{\left(2 \cdot C\right)}}}{-\mathsf{fma}\left(B, B, -4 \cdot \left(A \cdot C\right)\right)} \]
    9. Applied rewrites54.5%

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

    if 4.99999999999999989e-257 < (pow.f64 B #s(literal 2 binary64)) < 4.9999999999999997e104

    1. Initial program 25.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. Add Preprocessing
    3. Taylor expanded in C around 0

      \[\leadsto \color{blue}{-1 \cdot \left(\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A + \sqrt{{A}^{2} + {B}^{2}}\right)}\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(A + \sqrt{{A}^{2} + {B}^{2}}\right)}\right)} \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\sqrt{F \cdot \left(A + \sqrt{{A}^{2} + {B}^{2}}\right)} \cdot \frac{\sqrt{2}}{B}}\right) \]
      3. distribute-rgt-neg-inN/A

        \[\leadsto \color{blue}{\sqrt{F \cdot \left(A + \sqrt{{A}^{2} + {B}^{2}}\right)} \cdot \left(\mathsf{neg}\left(\frac{\sqrt{2}}{B}\right)\right)} \]
      4. mul-1-negN/A

        \[\leadsto \sqrt{F \cdot \left(A + \sqrt{{A}^{2} + {B}^{2}}\right)} \cdot \color{blue}{\left(-1 \cdot \frac{\sqrt{2}}{B}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{F \cdot \left(A + \sqrt{{A}^{2} + {B}^{2}}\right)} \cdot \left(-1 \cdot \frac{\sqrt{2}}{B}\right)} \]
    5. Applied rewrites15.3%

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

      \[\leadsto \sqrt{F \cdot \left(\frac{-1}{2} \cdot \frac{{B}^{2}}{A}\right)} \cdot \left(\mathsf{neg}\left(\frac{\sqrt{2}}{B}\right)\right) \]
    7. Step-by-step derivation
      1. Applied rewrites30.3%

        \[\leadsto \sqrt{F \cdot \frac{-0.5 \cdot \left(B \cdot B\right)}{A}} \cdot \left(-\frac{\sqrt{2}}{B}\right) \]
      2. Step-by-step derivation
        1. Applied rewrites39.1%

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

        if 4.9999999999999997e104 < (pow.f64 B #s(literal 2 binary64))

        1. Initial program 12.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. Add Preprocessing
        3. Taylor expanded in B around inf

          \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{\frac{F}{B}} \cdot \sqrt{2}\right)} \]
        4. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(\sqrt{\frac{F}{B}} \cdot \sqrt{2}\right)} \]
          2. lower-neg.f64N/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(\sqrt{\frac{F}{B}} \cdot \sqrt{2}\right)} \]
          3. *-commutativeN/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{\sqrt{2} \cdot \sqrt{\frac{F}{B}}}\right) \]
          4. lower-*.f64N/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{\sqrt{2} \cdot \sqrt{\frac{F}{B}}}\right) \]
          5. lower-sqrt.f64N/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{\sqrt{2}} \cdot \sqrt{\frac{F}{B}}\right) \]
          6. lower-sqrt.f64N/A

            \[\leadsto \mathsf{neg}\left(\sqrt{2} \cdot \color{blue}{\sqrt{\frac{F}{B}}}\right) \]
          7. lower-/.f6449.4

            \[\leadsto -\sqrt{2} \cdot \sqrt{\color{blue}{\frac{F}{B}}} \]
        5. Applied rewrites49.4%

          \[\leadsto \color{blue}{-\sqrt{2} \cdot \sqrt{\frac{F}{B}}} \]
        6. Step-by-step derivation
          1. Applied rewrites68.9%

            \[\leadsto -\frac{\sqrt{F \cdot 2}}{\sqrt{B}} \]
        7. Recombined 3 regimes into one program.
        8. Final simplification55.9%

          \[\leadsto \begin{array}{l} \mathbf{if}\;{B}^{2} \leq 5 \cdot 10^{-257}:\\ \;\;\;\;\frac{\sqrt{\left(F \cdot \left(2 \cdot \mathsf{fma}\left(B, B, -4 \cdot \left(A \cdot C\right)\right)\right)\right) \cdot \left(2 \cdot C\right)}}{-\mathsf{fma}\left(B, B, -4 \cdot \left(A \cdot C\right)\right)}\\ \mathbf{elif}\;{B}^{2} \leq 5 \cdot 10^{+104}:\\ \;\;\;\;\left(-\sqrt{F}\right) \cdot \left(\sqrt{\frac{\left(B \cdot B\right) \cdot -0.5}{A}} \cdot \frac{\sqrt{2}}{B}\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{\sqrt{2 \cdot F}}{\sqrt{B}}\\ \end{array} \]
        9. Add Preprocessing

        Alternative 2: 50.8% accurate, 1.2× speedup?

        \[\begin{array}{l} B_m = \left|B\right| \\ [A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\ \\ \begin{array}{l} t_0 := \left(4 \cdot A\right) \cdot C\\ \mathbf{if}\;{B\_m}^{2} \leq 5 \cdot 10^{+104}:\\ \;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left({B\_m}^{2} - t\_0\right) \cdot F\right)\right) \cdot \mathsf{fma}\left(\frac{B\_m \cdot B\_m}{A}, -0.5, 2 \cdot C\right)}}{t\_0 - {B\_m}^{2}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\sqrt{2 \cdot F}}{\sqrt{B\_m}}\\ \end{array} \end{array} \]
        B_m = (fabs.f64 B)
        NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
        (FPCore (A B_m C F)
         :precision binary64
         (let* ((t_0 (* (* 4.0 A) C)))
           (if (<= (pow B_m 2.0) 5e+104)
             (/
              (sqrt
               (*
                (* 2.0 (* (- (pow B_m 2.0) t_0) F))
                (fma (/ (* B_m B_m) A) -0.5 (* 2.0 C))))
              (- t_0 (pow B_m 2.0)))
             (- (/ (sqrt (* 2.0 F)) (sqrt B_m))))))
        B_m = fabs(B);
        assert(A < B_m && B_m < C && C < F);
        double code(double A, double B_m, double C, double F) {
        	double t_0 = (4.0 * A) * C;
        	double tmp;
        	if (pow(B_m, 2.0) <= 5e+104) {
        		tmp = sqrt(((2.0 * ((pow(B_m, 2.0) - t_0) * F)) * fma(((B_m * B_m) / A), -0.5, (2.0 * C)))) / (t_0 - pow(B_m, 2.0));
        	} else {
        		tmp = -(sqrt((2.0 * F)) / sqrt(B_m));
        	}
        	return tmp;
        }
        
        B_m = abs(B)
        A, B_m, C, F = sort([A, B_m, C, F])
        function code(A, B_m, C, F)
        	t_0 = Float64(Float64(4.0 * A) * C)
        	tmp = 0.0
        	if ((B_m ^ 2.0) <= 5e+104)
        		tmp = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64((B_m ^ 2.0) - t_0) * F)) * fma(Float64(Float64(B_m * B_m) / A), -0.5, Float64(2.0 * C)))) / Float64(t_0 - (B_m ^ 2.0)));
        	else
        		tmp = Float64(-Float64(sqrt(Float64(2.0 * F)) / sqrt(B_m)));
        	end
        	return tmp
        end
        
        B_m = N[Abs[B], $MachinePrecision]
        NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
        code[A_, B$95$m_, C_, F_] := Block[{t$95$0 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 5e+104], N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[Power[B$95$m, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(B$95$m * B$95$m), $MachinePrecision] / A), $MachinePrecision] * -0.5 + N[(2.0 * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 - N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(N[Sqrt[N[(2.0 * F), $MachinePrecision]], $MachinePrecision] / N[Sqrt[B$95$m], $MachinePrecision]), $MachinePrecision])]]
        
        \begin{array}{l}
        B_m = \left|B\right|
        \\
        [A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
        \\
        \begin{array}{l}
        t_0 := \left(4 \cdot A\right) \cdot C\\
        \mathbf{if}\;{B\_m}^{2} \leq 5 \cdot 10^{+104}:\\
        \;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left({B\_m}^{2} - t\_0\right) \cdot F\right)\right) \cdot \mathsf{fma}\left(\frac{B\_m \cdot B\_m}{A}, -0.5, 2 \cdot C\right)}}{t\_0 - {B\_m}^{2}}\\
        
        \mathbf{else}:\\
        \;\;\;\;-\frac{\sqrt{2 \cdot F}}{\sqrt{B\_m}}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (pow.f64 B #s(literal 2 binary64)) < 4.9999999999999997e104

          1. Initial program 24.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. Add Preprocessing
          3. Taylor expanded in A around -inf

            \[\leadsto \frac{\mathsf{neg}\left(\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \color{blue}{\left(\frac{-1}{2} \cdot \frac{{B}^{2}}{A} + 2 \cdot C\right)}}\right)}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

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

              \[\leadsto \frac{\mathsf{neg}\left(\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{{B}^{2}}{A}, \frac{-1}{2}, 2 \cdot C\right)}}\right)}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
            3. lower-/.f64N/A

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

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

              \[\leadsto \frac{\mathsf{neg}\left(\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \mathsf{fma}\left(\frac{\color{blue}{B \cdot B}}{A}, \frac{-1}{2}, 2 \cdot C\right)}\right)}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
            6. lower-*.f6441.3

              \[\leadsto \frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \mathsf{fma}\left(\frac{B \cdot B}{A}, -0.5, \color{blue}{2 \cdot C}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C} \]
          5. Applied rewrites41.3%

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

          if 4.9999999999999997e104 < (pow.f64 B #s(literal 2 binary64))

          1. Initial program 9.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. Add Preprocessing
          3. Taylor expanded in B around inf

            \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{\frac{F}{B}} \cdot \sqrt{2}\right)} \]
          4. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \color{blue}{\mathsf{neg}\left(\sqrt{\frac{F}{B}} \cdot \sqrt{2}\right)} \]
            2. lower-neg.f64N/A

              \[\leadsto \color{blue}{\mathsf{neg}\left(\sqrt{\frac{F}{B}} \cdot \sqrt{2}\right)} \]
            3. *-commutativeN/A

              \[\leadsto \mathsf{neg}\left(\color{blue}{\sqrt{2} \cdot \sqrt{\frac{F}{B}}}\right) \]
            4. lower-*.f64N/A

              \[\leadsto \mathsf{neg}\left(\color{blue}{\sqrt{2} \cdot \sqrt{\frac{F}{B}}}\right) \]
            5. lower-sqrt.f64N/A

              \[\leadsto \mathsf{neg}\left(\color{blue}{\sqrt{2}} \cdot \sqrt{\frac{F}{B}}\right) \]
            6. lower-sqrt.f64N/A

              \[\leadsto \mathsf{neg}\left(\sqrt{2} \cdot \color{blue}{\sqrt{\frac{F}{B}}}\right) \]
            7. lower-/.f6445.8

              \[\leadsto -\sqrt{2} \cdot \sqrt{\color{blue}{\frac{F}{B}}} \]
          5. Applied rewrites45.8%

            \[\leadsto \color{blue}{-\sqrt{2} \cdot \sqrt{\frac{F}{B}}} \]
          6. Step-by-step derivation
            1. Applied rewrites64.2%

              \[\leadsto -\frac{\sqrt{F \cdot 2}}{\sqrt{B}} \]
          7. Recombined 2 regimes into one program.
          8. Final simplification50.8%

            \[\leadsto \begin{array}{l} \mathbf{if}\;{B}^{2} \leq 5 \cdot 10^{+104}:\\ \;\;\;\;\frac{\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \mathsf{fma}\left(\frac{B \cdot B}{A}, -0.5, 2 \cdot C\right)}}{\left(4 \cdot A\right) \cdot C - {B}^{2}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\sqrt{2 \cdot F}}{\sqrt{B}}\\ \end{array} \]
          9. Add Preprocessing

          Reproduce

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