Quadratic roots, full range

Percentage Accurate: 51.6% → 85.3%
Time: 16.3s
Alternatives: 9
Speedup: 12.9×

Specification

?
\[\begin{array}{l} \\ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\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: 51.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}

Alternative 1: 85.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot \left(c \cdot -4\right)\\ \mathbf{if}\;b \leq -2 \cdot 10^{+152}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.9 \cdot 10^{-139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{-80}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 3.55 \cdot 10^{-37}:\\ \;\;\;\;\frac{\frac{t_0}{b + \mathsf{hypot}\left(\sqrt{t_0}, b\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (* a (* c -4.0))))
   (if (<= b -2e+152)
     (/ (fma b -2.0 (/ (* a 2.0) (/ b c))) (* a 2.0))
     (if (<= b 5.9e-139)
       (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
       (if (<= b 3.5e-80)
         (/ (- c) b)
         (if (<= b 3.55e-37)
           (/ (/ t_0 (+ b (hypot (sqrt t_0) b))) (* a 2.0))
           (/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b)))))))))))
double code(double a, double b, double c) {
	double t_0 = a * (c * -4.0);
	double tmp;
	if (b <= -2e+152) {
		tmp = fma(b, -2.0, ((a * 2.0) / (b / c))) / (a * 2.0);
	} else if (b <= 5.9e-139) {
		tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
	} else if (b <= 3.5e-80) {
		tmp = -c / b;
	} else if (b <= 3.55e-37) {
		tmp = (t_0 / (b + hypot(sqrt(t_0), b))) / (a * 2.0);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
function code(a, b, c)
	t_0 = Float64(a * Float64(c * -4.0))
	tmp = 0.0
	if (b <= -2e+152)
		tmp = Float64(fma(b, -2.0, Float64(Float64(a * 2.0) / Float64(b / c))) / Float64(a * 2.0));
	elseif (b <= 5.9e-139)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0));
	elseif (b <= 3.5e-80)
		tmp = Float64(Float64(-c) / b);
	elseif (b <= 3.55e-37)
		tmp = Float64(Float64(t_0 / Float64(b + hypot(sqrt(t_0), b))) / Float64(a * 2.0));
	else
		tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b)))));
	end
	return tmp
end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e+152], N[(N[(b * -2.0 + N[(N[(a * 2.0), $MachinePrecision] / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.9e-139], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.5e-80], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.55e-37], N[(N[(t$95$0 / N[(b + N[Sqrt[N[Sqrt[t$95$0], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot -4\right)\\
\mathbf{if}\;b \leq -2 \cdot 10^{+152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\

\mathbf{elif}\;b \leq 5.9 \cdot 10^{-139}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 3.5 \cdot 10^{-80}:\\
\;\;\;\;\frac{-c}{b}\\

\mathbf{elif}\;b \leq 3.55 \cdot 10^{-37}:\\
\;\;\;\;\frac{\frac{t_0}{b + \mathsf{hypot}\left(\sqrt{t_0}, b\right)}}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if b < -2.0000000000000001e152

    1. Initial program 40.0%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative40.0%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified40.0%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 90.9%

      \[\leadsto \frac{\color{blue}{-2 \cdot b + 2 \cdot \frac{a \cdot c}{b}}}{a \cdot 2} \]
    6. Step-by-step derivation
      1. *-commutative90.9%

        \[\leadsto \frac{\color{blue}{b \cdot -2} + 2 \cdot \frac{a \cdot c}{b}}{a \cdot 2} \]
      2. fma-def90.9%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(b, -2, 2 \cdot \frac{a \cdot c}{b}\right)}}{a \cdot 2} \]
      3. associate-/l*100.0%

        \[\leadsto \frac{\mathsf{fma}\left(b, -2, 2 \cdot \color{blue}{\frac{a}{\frac{b}{c}}}\right)}{a \cdot 2} \]
      4. associate-*r/100.0%

        \[\leadsto \frac{\mathsf{fma}\left(b, -2, \color{blue}{\frac{2 \cdot a}{\frac{b}{c}}}\right)}{a \cdot 2} \]
      5. *-commutative100.0%

        \[\leadsto \frac{\mathsf{fma}\left(b, -2, \frac{\color{blue}{a \cdot 2}}{\frac{b}{c}}\right)}{a \cdot 2} \]
    7. Simplified100.0%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}}{a \cdot 2} \]

    if -2.0000000000000001e152 < b < 5.8999999999999998e-139

    1. Initial program 83.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Add Preprocessing

    if 5.8999999999999998e-139 < b < 3.50000000000000015e-80

    1. Initial program 23.4%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative23.4%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified23.4%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 81.2%

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    6. Step-by-step derivation
      1. mul-1-neg81.2%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac81.2%

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    7. Simplified81.2%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]

    if 3.50000000000000015e-80 < b < 3.54999999999999989e-37

    1. Initial program 76.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified76.3%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\mathsf{fma}\left(b, b, -c \cdot \left(4 \cdot a\right)\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}}{a \cdot 2} \]
      2. *-commutative76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, -\color{blue}{\left(4 \cdot a\right) \cdot c}\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}{a \cdot 2} \]
      3. fma-def76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(b \cdot b + \left(-\left(4 \cdot a\right) \cdot c\right)\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}{a \cdot 2} \]
      4. associate-+l+76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{b \cdot b + \left(\left(-\left(4 \cdot a\right) \cdot c\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}}{a \cdot 2} \]
      5. pow276.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2}} + \left(\left(-\left(4 \cdot a\right) \cdot c\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      6. distribute-lft-neg-in76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{\left(-4 \cdot a\right) \cdot c} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      7. *-commutative76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\left(-\color{blue}{a \cdot 4}\right) \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      8. distribute-rgt-neg-in76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{\left(a \cdot \left(-4\right)\right)} \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      9. metadata-eval76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\left(a \cdot \color{blue}{-4}\right) \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      10. associate-*r*76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{a \cdot \left(-4 \cdot c\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      11. *-commutative76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \color{blue}{\left(c \cdot -4\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      12. *-commutative76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \mathsf{fma}\left(-c, 4 \cdot a, \color{blue}{\left(4 \cdot a\right) \cdot c}\right)\right)}}{a \cdot 2} \]
      13. fma-udef76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \color{blue}{\left(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(4 \cdot a\right) \cdot c\right)}\right)}}{a \cdot 2} \]
    6. Applied egg-rr76.3%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \left(a \cdot \left(c \cdot -4\right) + \left(c \cdot 4\right) \cdot a\right)\right)}}}{a \cdot 2} \]
    7. Step-by-step derivation
      1. fma-def76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \color{blue}{\mathsf{fma}\left(a, c \cdot -4, a \cdot \left(c \cdot -4\right) + \left(c \cdot 4\right) \cdot a\right)}}}{a \cdot 2} \]
      2. fma-def76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \color{blue}{\mathsf{fma}\left(a, c \cdot -4, \left(c \cdot 4\right) \cdot a\right)}\right)}}{a \cdot 2} \]
      3. associate-*l*76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, \color{blue}{c \cdot \left(4 \cdot a\right)}\right)\right)}}{a \cdot 2} \]
    8. Simplified76.3%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)}}}{a \cdot 2} \]
    9. Step-by-step derivation
      1. +-commutative76.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right) + {b}^{2}}}}{a \cdot 2} \]
      2. add-sqr-sqrt76.1%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)}} + {b}^{2}}}{a \cdot 2} \]
      3. unpow276.1%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)} \cdot \sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)} + \color{blue}{b \cdot b}}}{a \cdot 2} \]
      4. hypot-def76.3%

        \[\leadsto \frac{\left(-b\right) + \color{blue}{\mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)}, b\right)}}{a \cdot 2} \]
      5. *-commutative76.3%

        \[\leadsto \frac{\left(-b\right) + \mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \color{blue}{\left(a \cdot 4\right)}\right)\right)}, b\right)}{a \cdot 2} \]
    10. Applied egg-rr76.3%

      \[\leadsto \frac{\left(-b\right) + \color{blue}{\mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(a \cdot 4\right)\right)\right)}, b\right)}}{a \cdot 2} \]
    11. Step-by-step derivation
      1. +-commutative76.3%

        \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(a \cdot 4\right)\right)\right)}, b\right) + \left(-b\right)}}{a \cdot 2} \]
      2. flip-+75.4%

        \[\leadsto \frac{\color{blue}{\frac{\mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(a \cdot 4\right)\right)\right)}, b\right) \cdot \mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(a \cdot 4\right)\right)\right)}, b\right) - \left(-b\right) \cdot \left(-b\right)}{\mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(a \cdot 4\right)\right)\right)}, b\right) - \left(-b\right)}}}{a \cdot 2} \]
    12. Applied egg-rr75.3%

      \[\leadsto \frac{\color{blue}{\frac{\left(\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(a \cdot 4\right)\right)\right) + {b}^{2}\right) - {b}^{2}}{b + \mathsf{hypot}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(a \cdot 4\right)\right)\right)}, b\right)}}}{a \cdot 2} \]
    13. Simplified98.9%

      \[\leadsto \frac{\color{blue}{\frac{a \cdot \left(-4 \cdot c\right)}{b + \mathsf{hypot}\left(\sqrt{a \cdot \left(-4 \cdot c\right)}, b\right)}}}{a \cdot 2} \]

    if 3.54999999999999989e-37 < b

    1. Initial program 14.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative14.1%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified14.1%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr5.3%

      \[\leadsto \color{blue}{{\left(\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}\right)}^{-1}} \]
    6. Step-by-step derivation
      1. unpow-15.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}}} \]
      2. associate-/r/5.3%

        \[\leadsto \frac{1}{\color{blue}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    7. Applied egg-rr5.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    8. Step-by-step derivation
      1. div-inv5.3%

        \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
      2. frac-2neg5.3%

        \[\leadsto \frac{1}{\left(a \cdot \color{blue}{\frac{-1}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      3. metadata-eval5.3%

        \[\leadsto \frac{1}{\left(a \cdot \frac{\color{blue}{-1}}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      4. distribute-neg-in5.3%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\left(-b\right) + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      5. add-sqr-sqrt0.0%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{-b} \cdot \sqrt{-b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      6. sqrt-unprod13.3%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      7. sqr-neg13.3%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\sqrt{\color{blue}{b \cdot b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      8. sqrt-prod11.7%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{b} \cdot \sqrt{b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      9. add-sqr-sqrt14.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      10. sub-neg14.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}}\right) \cdot 2} \]
    9. Applied egg-rr14.2%

      \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{-1}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
    10. Taylor expanded in a around 0 91.5%

      \[\leadsto \frac{1}{\color{blue}{\left(-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}\right)} \cdot 2} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification88.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{+152}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.9 \cdot 10^{-139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{-80}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 3.55 \cdot 10^{-37}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \mathsf{hypot}\left(\sqrt{a \cdot \left(c \cdot -4\right)}, b\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.1% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{+150}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \leq 2.25 \cdot 10^{-138}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.15e+150)
   (/ (fma b -2.0 (/ (* a 2.0) (/ b c))) (* a 2.0))
   (if (<= b 2.25e-138)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
     (/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b))))))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.15e+150) {
		tmp = fma(b, -2.0, ((a * 2.0) / (b / c))) / (a * 2.0);
	} else if (b <= 2.25e-138) {
		tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.15e+150)
		tmp = Float64(fma(b, -2.0, Float64(Float64(a * 2.0) / Float64(b / c))) / Float64(a * 2.0));
	elseif (b <= 2.25e-138)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b)))));
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -1.15e+150], N[(N[(b * -2.0 + N[(N[(a * 2.0), $MachinePrecision] / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.25e-138], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{+150}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\

\mathbf{elif}\;b \leq 2.25 \cdot 10^{-138}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -1.15000000000000001e150

    1. Initial program 40.0%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative40.0%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified40.0%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 90.9%

      \[\leadsto \frac{\color{blue}{-2 \cdot b + 2 \cdot \frac{a \cdot c}{b}}}{a \cdot 2} \]
    6. Step-by-step derivation
      1. *-commutative90.9%

        \[\leadsto \frac{\color{blue}{b \cdot -2} + 2 \cdot \frac{a \cdot c}{b}}{a \cdot 2} \]
      2. fma-def90.9%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(b, -2, 2 \cdot \frac{a \cdot c}{b}\right)}}{a \cdot 2} \]
      3. associate-/l*100.0%

        \[\leadsto \frac{\mathsf{fma}\left(b, -2, 2 \cdot \color{blue}{\frac{a}{\frac{b}{c}}}\right)}{a \cdot 2} \]
      4. associate-*r/100.0%

        \[\leadsto \frac{\mathsf{fma}\left(b, -2, \color{blue}{\frac{2 \cdot a}{\frac{b}{c}}}\right)}{a \cdot 2} \]
      5. *-commutative100.0%

        \[\leadsto \frac{\mathsf{fma}\left(b, -2, \frac{\color{blue}{a \cdot 2}}{\frac{b}{c}}\right)}{a \cdot 2} \]
    7. Simplified100.0%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}}{a \cdot 2} \]

    if -1.15000000000000001e150 < b < 2.25000000000000004e-138

    1. Initial program 83.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Add Preprocessing

    if 2.25000000000000004e-138 < b

    1. Initial program 20.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative20.2%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified20.2%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr12.2%

      \[\leadsto \color{blue}{{\left(\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}\right)}^{-1}} \]
    6. Step-by-step derivation
      1. unpow-112.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}}} \]
      2. associate-/r/12.2%

        \[\leadsto \frac{1}{\color{blue}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    7. Applied egg-rr12.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    8. Step-by-step derivation
      1. div-inv12.2%

        \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
      2. frac-2neg12.2%

        \[\leadsto \frac{1}{\left(a \cdot \color{blue}{\frac{-1}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      3. metadata-eval12.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{\color{blue}{-1}}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      4. distribute-neg-in12.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\left(-b\right) + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      5. add-sqr-sqrt0.0%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{-b} \cdot \sqrt{-b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      6. sqrt-unprod19.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      7. sqr-neg19.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\sqrt{\color{blue}{b \cdot b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      8. sqrt-prod18.1%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{b} \cdot \sqrt{b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      9. add-sqr-sqrt20.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      10. sub-neg20.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}}\right) \cdot 2} \]
    9. Applied egg-rr20.2%

      \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{-1}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
    10. Taylor expanded in a around 0 85.6%

      \[\leadsto \frac{1}{\color{blue}{\left(-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}\right)} \cdot 2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification86.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{+150}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\ \mathbf{elif}\;b \leq 2.25 \cdot 10^{-138}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 78.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.52 \cdot 10^{-164}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.52e-164)
   (- (/ c b) (/ b a))
   (if (<= b 2.5e-138)
     (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
     (/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b))))))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.52e-164) {
		tmp = (c / b) - (b / a);
	} else if (b <= 2.5e-138) {
		tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-1.52d-164)) then
        tmp = (c / b) - (b / a)
    else if (b <= 2.5d-138) then
        tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
    else
        tmp = 1.0d0 / (2.0d0 * (((b / c) * (-0.5d0)) + (0.5d0 * (a / b))))
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.52e-164) {
		tmp = (c / b) - (b / a);
	} else if (b <= 2.5e-138) {
		tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -1.52e-164:
		tmp = (c / b) - (b / a)
	elif b <= 2.5e-138:
		tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0)
	else:
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))))
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.52e-164)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= 2.5e-138)
		tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b)))));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -1.52e-164)
		tmp = (c / b) - (b / a);
	elseif (b <= 2.5e-138)
		tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
	else
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -1.52e-164], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.5e-138], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.52 \cdot 10^{-164}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -1.52000000000000007e-164

    1. Initial program 69.5%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative69.5%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified69.5%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 79.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}} \]
    6. Step-by-step derivation
      1. +-commutative79.0%

        \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
      2. mul-1-neg79.0%

        \[\leadsto \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)} \]
      3. unsub-neg79.0%

        \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]
    7. Simplified79.0%

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]

    if -1.52000000000000007e-164 < b < 2.49999999999999994e-138

    1. Initial program 77.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative77.9%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified77.9%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\mathsf{fma}\left(b, b, -c \cdot \left(4 \cdot a\right)\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}}{a \cdot 2} \]
      2. *-commutative77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, -\color{blue}{\left(4 \cdot a\right) \cdot c}\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}{a \cdot 2} \]
      3. fma-def77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(b \cdot b + \left(-\left(4 \cdot a\right) \cdot c\right)\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}{a \cdot 2} \]
      4. associate-+l+77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{b \cdot b + \left(\left(-\left(4 \cdot a\right) \cdot c\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}}{a \cdot 2} \]
      5. pow277.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2}} + \left(\left(-\left(4 \cdot a\right) \cdot c\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      6. distribute-lft-neg-in77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{\left(-4 \cdot a\right) \cdot c} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      7. *-commutative77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\left(-\color{blue}{a \cdot 4}\right) \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      8. distribute-rgt-neg-in77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{\left(a \cdot \left(-4\right)\right)} \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      9. metadata-eval77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\left(a \cdot \color{blue}{-4}\right) \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      10. associate-*r*77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{a \cdot \left(-4 \cdot c\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      11. *-commutative77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \color{blue}{\left(c \cdot -4\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      12. *-commutative77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \mathsf{fma}\left(-c, 4 \cdot a, \color{blue}{\left(4 \cdot a\right) \cdot c}\right)\right)}}{a \cdot 2} \]
      13. fma-udef77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \color{blue}{\left(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(4 \cdot a\right) \cdot c\right)}\right)}}{a \cdot 2} \]
    6. Applied egg-rr77.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \left(a \cdot \left(c \cdot -4\right) + \left(c \cdot 4\right) \cdot a\right)\right)}}}{a \cdot 2} \]
    7. Step-by-step derivation
      1. fma-def77.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \color{blue}{\mathsf{fma}\left(a, c \cdot -4, a \cdot \left(c \cdot -4\right) + \left(c \cdot 4\right) \cdot a\right)}}}{a \cdot 2} \]
      2. fma-def77.7%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \color{blue}{\mathsf{fma}\left(a, c \cdot -4, \left(c \cdot 4\right) \cdot a\right)}\right)}}{a \cdot 2} \]
      3. associate-*l*77.7%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, \color{blue}{c \cdot \left(4 \cdot a\right)}\right)\right)}}{a \cdot 2} \]
    8. Simplified77.7%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)}}}{a \cdot 2} \]
    9. Taylor expanded in b around 0 77.6%

      \[\leadsto \frac{\color{blue}{\sqrt{-8 \cdot \left(a \cdot c\right) + 4 \cdot \left(a \cdot c\right)} + -1 \cdot b}}{a \cdot 2} \]
    10. Step-by-step derivation
      1. mul-1-neg77.6%

        \[\leadsto \frac{\sqrt{-8 \cdot \left(a \cdot c\right) + 4 \cdot \left(a \cdot c\right)} + \color{blue}{\left(-b\right)}}{a \cdot 2} \]
      2. unsub-neg77.6%

        \[\leadsto \frac{\color{blue}{\sqrt{-8 \cdot \left(a \cdot c\right) + 4 \cdot \left(a \cdot c\right)} - b}}{a \cdot 2} \]
      3. distribute-rgt-out77.8%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(a \cdot c\right) \cdot \left(-8 + 4\right)}} - b}{a \cdot 2} \]
      4. metadata-eval77.8%

        \[\leadsto \frac{\sqrt{\left(a \cdot c\right) \cdot \color{blue}{-4}} - b}{a \cdot 2} \]
      5. associate-*r*77.9%

        \[\leadsto \frac{\sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}} - b}{a \cdot 2} \]
      6. *-commutative77.9%

        \[\leadsto \frac{\sqrt{a \cdot \color{blue}{\left(-4 \cdot c\right)}} - b}{a \cdot 2} \]
    11. Simplified77.9%

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot \left(-4 \cdot c\right)} - b}}{a \cdot 2} \]

    if 2.49999999999999994e-138 < b

    1. Initial program 20.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative20.2%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified20.2%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr12.2%

      \[\leadsto \color{blue}{{\left(\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}\right)}^{-1}} \]
    6. Step-by-step derivation
      1. unpow-112.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}}} \]
      2. associate-/r/12.2%

        \[\leadsto \frac{1}{\color{blue}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    7. Applied egg-rr12.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    8. Step-by-step derivation
      1. div-inv12.2%

        \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
      2. frac-2neg12.2%

        \[\leadsto \frac{1}{\left(a \cdot \color{blue}{\frac{-1}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      3. metadata-eval12.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{\color{blue}{-1}}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      4. distribute-neg-in12.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\left(-b\right) + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      5. add-sqr-sqrt0.0%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{-b} \cdot \sqrt{-b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      6. sqrt-unprod19.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      7. sqr-neg19.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\sqrt{\color{blue}{b \cdot b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      8. sqrt-prod18.1%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{b} \cdot \sqrt{b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      9. add-sqr-sqrt20.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      10. sub-neg20.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}}\right) \cdot 2} \]
    9. Applied egg-rr20.2%

      \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{-1}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
    10. Taylor expanded in a around 0 85.6%

      \[\leadsto \frac{1}{\color{blue}{\left(-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}\right)} \cdot 2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification81.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.52 \cdot 10^{-164}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -3.25 \cdot 10^{-170}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -3.25e-170)
   (- (/ c b) (/ b a))
   (if (<= b 2.5e-138)
     (* 0.5 (/ (sqrt (* a (* c -4.0))) a))
     (/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b))))))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -3.25e-170) {
		tmp = (c / b) - (b / a);
	} else if (b <= 2.5e-138) {
		tmp = 0.5 * (sqrt((a * (c * -4.0))) / a);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-3.25d-170)) then
        tmp = (c / b) - (b / a)
    else if (b <= 2.5d-138) then
        tmp = 0.5d0 * (sqrt((a * (c * (-4.0d0)))) / a)
    else
        tmp = 1.0d0 / (2.0d0 * (((b / c) * (-0.5d0)) + (0.5d0 * (a / b))))
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -3.25e-170) {
		tmp = (c / b) - (b / a);
	} else if (b <= 2.5e-138) {
		tmp = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -3.25e-170:
		tmp = (c / b) - (b / a)
	elif b <= 2.5e-138:
		tmp = 0.5 * (math.sqrt((a * (c * -4.0))) / a)
	else:
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))))
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -3.25e-170)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= 2.5e-138)
		tmp = Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a));
	else
		tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b)))));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -3.25e-170)
		tmp = (c / b) - (b / a);
	elseif (b <= 2.5e-138)
		tmp = 0.5 * (sqrt((a * (c * -4.0))) / a);
	else
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -3.25e-170], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.5e-138], N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.25 \cdot 10^{-170}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -3.25000000000000018e-170

    1. Initial program 69.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative69.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified69.3%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 78.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}} \]
    6. Step-by-step derivation
      1. +-commutative78.6%

        \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
      2. mul-1-neg78.6%

        \[\leadsto \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)} \]
      3. unsub-neg78.6%

        \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]
    7. Simplified78.6%

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]

    if -3.25000000000000018e-170 < b < 2.49999999999999994e-138

    1. Initial program 78.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative78.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified78.6%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\mathsf{fma}\left(b, b, -c \cdot \left(4 \cdot a\right)\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}}{a \cdot 2} \]
      2. *-commutative78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, -\color{blue}{\left(4 \cdot a\right) \cdot c}\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}{a \cdot 2} \]
      3. fma-def78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(b \cdot b + \left(-\left(4 \cdot a\right) \cdot c\right)\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)}}{a \cdot 2} \]
      4. associate-+l+78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{b \cdot b + \left(\left(-\left(4 \cdot a\right) \cdot c\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}}{a \cdot 2} \]
      5. pow278.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2}} + \left(\left(-\left(4 \cdot a\right) \cdot c\right) + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      6. distribute-lft-neg-in78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{\left(-4 \cdot a\right) \cdot c} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      7. *-commutative78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\left(-\color{blue}{a \cdot 4}\right) \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      8. distribute-rgt-neg-in78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{\left(a \cdot \left(-4\right)\right)} \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      9. metadata-eval78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\left(a \cdot \color{blue}{-4}\right) \cdot c + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      10. associate-*r*78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(\color{blue}{a \cdot \left(-4 \cdot c\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      11. *-commutative78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \color{blue}{\left(c \cdot -4\right)} + \mathsf{fma}\left(-c, 4 \cdot a, c \cdot \left(4 \cdot a\right)\right)\right)}}{a \cdot 2} \]
      12. *-commutative78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \mathsf{fma}\left(-c, 4 \cdot a, \color{blue}{\left(4 \cdot a\right) \cdot c}\right)\right)}}{a \cdot 2} \]
      13. fma-udef78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \color{blue}{\left(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(4 \cdot a\right) \cdot c\right)}\right)}}{a \cdot 2} \]
    6. Applied egg-rr78.3%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \left(a \cdot \left(c \cdot -4\right) + \left(c \cdot 4\right) \cdot a\right)\right)}}}{a \cdot 2} \]
    7. Step-by-step derivation
      1. fma-def78.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \color{blue}{\mathsf{fma}\left(a, c \cdot -4, a \cdot \left(c \cdot -4\right) + \left(c \cdot 4\right) \cdot a\right)}}}{a \cdot 2} \]
      2. fma-def78.4%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \color{blue}{\mathsf{fma}\left(a, c \cdot -4, \left(c \cdot 4\right) \cdot a\right)}\right)}}{a \cdot 2} \]
      3. associate-*l*78.4%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, \color{blue}{c \cdot \left(4 \cdot a\right)}\right)\right)}}{a \cdot 2} \]
    8. Simplified78.4%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \mathsf{fma}\left(a, c \cdot -4, \mathsf{fma}\left(a, c \cdot -4, c \cdot \left(4 \cdot a\right)\right)\right)}}}{a \cdot 2} \]
    9. Taylor expanded in b around 0 78.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{1}{a} \cdot \sqrt{-8 \cdot \left(a \cdot c\right) + 4 \cdot \left(a \cdot c\right)}\right)} \]
    10. Step-by-step derivation
      1. associate-*l/78.1%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{1 \cdot \sqrt{-8 \cdot \left(a \cdot c\right) + 4 \cdot \left(a \cdot c\right)}}{a}} \]
      2. *-lft-identity78.1%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{-8 \cdot \left(a \cdot c\right) + 4 \cdot \left(a \cdot c\right)}}}{a} \]
      3. distribute-rgt-out78.3%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{\left(a \cdot c\right) \cdot \left(-8 + 4\right)}}}{a} \]
      4. metadata-eval78.3%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\left(a \cdot c\right) \cdot \color{blue}{-4}}}{a} \]
      5. associate-*r*78.4%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}}}{a} \]
      6. *-commutative78.4%

        \[\leadsto 0.5 \cdot \frac{\sqrt{a \cdot \color{blue}{\left(-4 \cdot c\right)}}}{a} \]
    11. Simplified78.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\sqrt{a \cdot \left(-4 \cdot c\right)}}{a}} \]

    if 2.49999999999999994e-138 < b

    1. Initial program 20.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative20.2%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified20.2%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr12.2%

      \[\leadsto \color{blue}{{\left(\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}\right)}^{-1}} \]
    6. Step-by-step derivation
      1. unpow-112.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}}} \]
      2. associate-/r/12.2%

        \[\leadsto \frac{1}{\color{blue}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    7. Applied egg-rr12.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    8. Step-by-step derivation
      1. div-inv12.2%

        \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
      2. frac-2neg12.2%

        \[\leadsto \frac{1}{\left(a \cdot \color{blue}{\frac{-1}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      3. metadata-eval12.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{\color{blue}{-1}}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      4. distribute-neg-in12.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\left(-b\right) + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      5. add-sqr-sqrt0.0%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{-b} \cdot \sqrt{-b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      6. sqrt-unprod19.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      7. sqr-neg19.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\sqrt{\color{blue}{b \cdot b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      8. sqrt-prod18.1%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{b} \cdot \sqrt{b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      9. add-sqr-sqrt20.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      10. sub-neg20.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}}\right) \cdot 2} \]
    9. Applied egg-rr20.2%

      \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{-1}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
    10. Taylor expanded in a around 0 85.6%

      \[\leadsto \frac{1}{\color{blue}{\left(-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}\right)} \cdot 2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.25 \cdot 10^{-170}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 68.1% accurate, 5.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -2.4 \cdot 10^{-290}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -2.4e-290)
   (- (/ c b) (/ b a))
   (/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b)))))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -2.4e-290) {
		tmp = (c / b) - (b / a);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-2.4d-290)) then
        tmp = (c / b) - (b / a)
    else
        tmp = 1.0d0 / (2.0d0 * (((b / c) * (-0.5d0)) + (0.5d0 * (a / b))))
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -2.4e-290) {
		tmp = (c / b) - (b / a);
	} else {
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -2.4e-290:
		tmp = (c / b) - (b / a)
	else:
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))))
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -2.4e-290)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	else
		tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b)))));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -2.4e-290)
		tmp = (c / b) - (b / a);
	else
		tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-290], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-290}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -2.4000000000000001e-290

    1. Initial program 71.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative71.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified71.6%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 66.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}} \]
    6. Step-by-step derivation
      1. +-commutative66.1%

        \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
      2. mul-1-neg66.1%

        \[\leadsto \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)} \]
      3. unsub-neg66.1%

        \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]
    7. Simplified66.1%

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]

    if -2.4000000000000001e-290 < b

    1. Initial program 35.0%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative35.0%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified35.0%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr29.2%

      \[\leadsto \color{blue}{{\left(\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}\right)}^{-1}} \]
    6. Step-by-step derivation
      1. unpow-129.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}{2}}}} \]
      2. associate-/r/29.2%

        \[\leadsto \frac{1}{\color{blue}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    7. Applied egg-rr29.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}} \cdot 2}} \]
    8. Step-by-step derivation
      1. div-inv29.2%

        \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{1}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
      2. frac-2neg29.2%

        \[\leadsto \frac{1}{\left(a \cdot \color{blue}{\frac{-1}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      3. metadata-eval29.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{\color{blue}{-1}}{-\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      4. distribute-neg-in29.2%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\left(-b\right) + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}}\right) \cdot 2} \]
      5. add-sqr-sqrt1.7%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{-b} \cdot \sqrt{-b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      6. sqrt-unprod34.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      7. sqr-neg34.5%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\sqrt{\color{blue}{b \cdot b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      8. sqrt-prod31.8%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{\sqrt{b} \cdot \sqrt{b}} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      9. add-sqr-sqrt35.0%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b} + \left(-\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right)}\right) \cdot 2} \]
      10. sub-neg35.0%

        \[\leadsto \frac{1}{\left(a \cdot \frac{-1}{\color{blue}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}}\right) \cdot 2} \]
    9. Applied egg-rr35.0%

      \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \frac{-1}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\right)} \cdot 2} \]
    10. Taylor expanded in a around 0 66.2%

      \[\leadsto \frac{1}{\color{blue}{\left(-0.5 \cdot \frac{b}{c} + 0.5 \cdot \frac{a}{b}\right)} \cdot 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.4 \cdot 10^{-290}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 68.4% accurate, 9.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1e-310) {
		tmp = (c / b) - (b / a);
	} else {
		tmp = -c / b;
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-1d-310)) then
        tmp = (c / b) - (b / a)
    else
        tmp = -c / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -1e-310) {
		tmp = (c / b) - (b / a);
	} else {
		tmp = -c / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -1e-310:
		tmp = (c / b) - (b / a)
	else:
		tmp = -c / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -1e-310)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	else
		tmp = Float64(Float64(-c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -1e-310)
		tmp = (c / b) - (b / a);
	else
		tmp = -c / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -9.999999999999969e-311

    1. Initial program 71.5%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative71.5%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified71.5%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 64.8%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}} \]
    6. Step-by-step derivation
      1. +-commutative64.8%

        \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
      2. mul-1-neg64.8%

        \[\leadsto \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)} \]
      3. unsub-neg64.8%

        \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]
    7. Simplified64.8%

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]

    if -9.999999999999969e-311 < b

    1. Initial program 34.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative34.1%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified34.1%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 67.7%

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    6. Step-by-step derivation
      1. mul-1-neg67.7%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac67.7%

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    7. Simplified67.7%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 44.4% accurate, 12.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -8 \cdot 10^{-308}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{a}\\ \end{array} \end{array} \]
(FPCore (a b c) :precision binary64 (if (<= b -8e-308) (/ (- b) a) (/ 0.0 a)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -8e-308) {
		tmp = -b / a;
	} else {
		tmp = 0.0 / a;
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-8d-308)) then
        tmp = -b / a
    else
        tmp = 0.0d0 / a
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -8e-308) {
		tmp = -b / a;
	} else {
		tmp = 0.0 / a;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -8e-308:
		tmp = -b / a
	else:
		tmp = 0.0 / a
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -8e-308)
		tmp = Float64(Float64(-b) / a);
	else
		tmp = Float64(0.0 / a);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -8e-308)
		tmp = -b / a;
	else
		tmp = 0.0 / a;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -8e-308], N[((-b) / a), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -8.00000000000000026e-308

    1. Initial program 71.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative71.3%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified71.3%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 64.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/64.4%

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
      2. mul-1-neg64.4%

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified64.4%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if -8.00000000000000026e-308 < b

    1. Initial program 34.7%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative34.7%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified34.7%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr34.3%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)} \cdot \frac{0.5}{a} + \left(-\frac{\frac{b}{2}}{a}\right)} \]
    6. Step-by-step derivation
      1. fma-def29.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}, \frac{0.5}{a}, -\frac{\frac{b}{2}}{a}\right)} \]
      2. distribute-neg-frac29.7%

        \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}, \frac{0.5}{a}, \color{blue}{\frac{-\frac{b}{2}}{a}}\right) \]
    7. Simplified29.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}, \frac{0.5}{a}, \frac{-\frac{b}{2}}{a}\right)} \]
    8. Taylor expanded in a around 0 19.3%

      \[\leadsto \color{blue}{\frac{-0.5 \cdot b + 0.5 \cdot b}{a}} \]
    9. Step-by-step derivation
      1. distribute-rgt-out19.3%

        \[\leadsto \frac{\color{blue}{b \cdot \left(-0.5 + 0.5\right)}}{a} \]
      2. metadata-eval19.3%

        \[\leadsto \frac{b \cdot \color{blue}{0}}{a} \]
      3. mul0-rgt19.3%

        \[\leadsto \frac{\color{blue}{0}}{a} \]
    10. Simplified19.3%

      \[\leadsto \color{blue}{\frac{0}{a}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification43.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8 \cdot 10^{-308}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 68.1% accurate, 12.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 4.7 \cdot 10^{-305}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b 4.7e-305) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= 4.7e-305) {
		tmp = -b / a;
	} else {
		tmp = -c / b;
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= 4.7d-305) then
        tmp = -b / a
    else
        tmp = -c / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= 4.7e-305) {
		tmp = -b / a;
	} else {
		tmp = -c / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= 4.7e-305:
		tmp = -b / a
	else:
		tmp = -c / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= 4.7e-305)
		tmp = Float64(Float64(-b) / a);
	else
		tmp = Float64(Float64(-c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= 4.7e-305)
		tmp = -b / a;
	else
		tmp = -c / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, 4.7e-305], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.7 \cdot 10^{-305}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 4.6999999999999996e-305

    1. Initial program 71.7%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative71.7%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified71.7%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 63.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/63.6%

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
      2. mul-1-neg63.6%

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified63.6%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if 4.6999999999999996e-305 < b

    1. Initial program 33.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Step-by-step derivation
      1. *-commutative33.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified33.6%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 68.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    6. Step-by-step derivation
      1. mul-1-neg68.3%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac68.3%

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    7. Simplified68.3%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 4.7 \cdot 10^{-305}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 11.7% accurate, 38.7× speedup?

\[\begin{array}{l} \\ \frac{0}{a} \end{array} \]
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
	return 0.0 / a;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
	return 0.0 / a;
}
def code(a, b, c):
	return 0.0 / a
function code(a, b, c)
	return Float64(0.0 / a)
end
function tmp = code(a, b, c)
	tmp = 0.0 / a;
end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{0}{a}
\end{array}
Derivation
  1. Initial program 54.6%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
  2. Step-by-step derivation
    1. *-commutative54.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Simplified54.6%

    \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
  4. Add Preprocessing
  5. Applied egg-rr54.4%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)} \cdot \frac{0.5}{a} + \left(-\frac{\frac{b}{2}}{a}\right)} \]
  6. Step-by-step derivation
    1. fma-def52.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}, \frac{0.5}{a}, -\frac{\frac{b}{2}}{a}\right)} \]
    2. distribute-neg-frac52.3%

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}, \frac{0.5}{a}, \color{blue}{\frac{-\frac{b}{2}}{a}}\right) \]
  7. Simplified52.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}, \frac{0.5}{a}, \frac{-\frac{b}{2}}{a}\right)} \]
  8. Taylor expanded in a around 0 10.4%

    \[\leadsto \color{blue}{\frac{-0.5 \cdot b + 0.5 \cdot b}{a}} \]
  9. Step-by-step derivation
    1. distribute-rgt-out10.4%

      \[\leadsto \frac{\color{blue}{b \cdot \left(-0.5 + 0.5\right)}}{a} \]
    2. metadata-eval10.4%

      \[\leadsto \frac{b \cdot \color{blue}{0}}{a} \]
    3. mul0-rgt10.4%

      \[\leadsto \frac{\color{blue}{0}}{a} \]
  10. Simplified10.4%

    \[\leadsto \color{blue}{\frac{0}{a}} \]
  11. Final simplification10.4%

    \[\leadsto \frac{0}{a} \]
  12. Add Preprocessing

Reproduce

?
herbie shell --seed 2024017 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))