Quadratic roots, full range

Percentage Accurate: 51.2% → 85.8%
Time: 11.5s
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.2% 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.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -3.5 \cdot 10^{+157}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 1.26 \cdot 10^{-61}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -3.5e+157)
   (- (/ b a))
   (if (<= b 1.26e-61)
     (/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
     (/ c (- b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -3.5e+157) {
		tmp = -(b / a);
	} else if (b <= 1.26e-61) {
		tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
	} 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 <= (-3.5d+157)) then
        tmp = -(b / a)
    else if (b <= 1.26d-61) then
        tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
    else
        tmp = c / -b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -3.5e+157) {
		tmp = -(b / a);
	} else if (b <= 1.26e-61) {
		tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
	} else {
		tmp = c / -b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -3.5e+157:
		tmp = -(b / a)
	elif b <= 1.26e-61:
		tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0)
	else:
		tmp = c / -b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -3.5e+157)
		tmp = Float64(-Float64(b / a));
	elseif (b <= 1.26e-61)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(c / Float64(-b));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -3.5e+157)
		tmp = -(b / a);
	elseif (b <= 1.26e-61)
		tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
	else
		tmp = c / -b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -3.5e+157], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 1.26e-61], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{+157}:\\
\;\;\;\;-\frac{b}{a}\\

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

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


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

    1. Initial program 23.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. *-commutative23.5%

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

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

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

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

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

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

    if -3.50000000000000002e157 < b < 1.2599999999999999e-61

    1. Initial program 79.6%

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

    if 1.2599999999999999e-61 < b

    1. Initial program 21.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. *-commutative21.6%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 83.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.5 \cdot 10^{+157}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 1.26 \cdot 10^{-61}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -9.8 \cdot 10^{-55}:\\ \;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\ \mathbf{elif}\;b \leq 9 \cdot 10^{-61}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -9.8e-55)
   (* b (+ (/ c (pow b 2.0)) (/ -1.0 a)))
   (if (<= b 9e-61) (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -9.8e-55) {
		tmp = b * ((c / pow(b, 2.0)) + (-1.0 / a));
	} else if (b <= 9e-61) {
		tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
	} 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 <= (-9.8d-55)) then
        tmp = b * ((c / (b ** 2.0d0)) + ((-1.0d0) / a))
    else if (b <= 9d-61) then
        tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
    else
        tmp = c / -b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -9.8e-55) {
		tmp = b * ((c / Math.pow(b, 2.0)) + (-1.0 / a));
	} else if (b <= 9e-61) {
		tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
	} else {
		tmp = c / -b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -9.8e-55:
		tmp = b * ((c / math.pow(b, 2.0)) + (-1.0 / a))
	elif b <= 9e-61:
		tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0)
	else:
		tmp = c / -b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -9.8e-55)
		tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a)));
	elseif (b <= 9e-61)
		tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(c / Float64(-b));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -9.8e-55)
		tmp = b * ((c / (b ^ 2.0)) + (-1.0 / a));
	elseif (b <= 9e-61)
		tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
	else
		tmp = c / -b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -9.8e-55], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9e-61], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.8 \cdot 10^{-55}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\

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

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


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

    1. Initial program 59.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. *-commutative59.2%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(b \cdot \left(-1 \cdot \frac{c}{{b}^{2}} + \frac{1}{a}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg89.0%

        \[\leadsto \color{blue}{-b \cdot \left(-1 \cdot \frac{c}{{b}^{2}} + \frac{1}{a}\right)} \]
      2. *-commutative89.0%

        \[\leadsto -\color{blue}{\left(-1 \cdot \frac{c}{{b}^{2}} + \frac{1}{a}\right) \cdot b} \]
      3. distribute-rgt-neg-in89.0%

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

        \[\leadsto \color{blue}{\left(\frac{1}{a} + -1 \cdot \frac{c}{{b}^{2}}\right)} \cdot \left(-b\right) \]
      5. mul-1-neg89.0%

        \[\leadsto \left(\frac{1}{a} + \color{blue}{\left(-\frac{c}{{b}^{2}}\right)}\right) \cdot \left(-b\right) \]
      6. unsub-neg89.0%

        \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right)} \cdot \left(-b\right) \]
    7. Simplified89.0%

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

    if -9.80000000000000071e-55 < b < 9e-61

    1. Initial program 70.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. *-commutative70.6%

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{-4 \cdot \left(a \cdot c\right)}} - b}{a \cdot 2} \]
    6. Step-by-step derivation
      1. *-commutative66.0%

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

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

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

    if 9e-61 < b

    1. Initial program 21.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. *-commutative21.6%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 83.8%

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

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

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

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

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

Alternative 3: 80.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.45 \cdot 10^{-55}:\\ \;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{-61}:\\ \;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.45e-55)
   (* b (+ (/ c (pow b 2.0)) (/ -1.0 a)))
   (if (<= b 1.8e-61)
     (* (+ b (sqrt (* a (* c -4.0)))) (/ 0.5 a))
     (/ c (- b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.45e-55) {
		tmp = b * ((c / pow(b, 2.0)) + (-1.0 / a));
	} else if (b <= 1.8e-61) {
		tmp = (b + sqrt((a * (c * -4.0)))) * (0.5 / 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 <= (-1.45d-55)) then
        tmp = b * ((c / (b ** 2.0d0)) + ((-1.0d0) / a))
    else if (b <= 1.8d-61) then
        tmp = (b + sqrt((a * (c * (-4.0d0))))) * (0.5d0 / 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 <= -1.45e-55) {
		tmp = b * ((c / Math.pow(b, 2.0)) + (-1.0 / a));
	} else if (b <= 1.8e-61) {
		tmp = (b + Math.sqrt((a * (c * -4.0)))) * (0.5 / a);
	} else {
		tmp = c / -b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -1.45e-55:
		tmp = b * ((c / math.pow(b, 2.0)) + (-1.0 / a))
	elif b <= 1.8e-61:
		tmp = (b + math.sqrt((a * (c * -4.0)))) * (0.5 / a)
	else:
		tmp = c / -b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.45e-55)
		tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a)));
	elseif (b <= 1.8e-61)
		tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) * Float64(0.5 / a));
	else
		tmp = Float64(c / Float64(-b));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -1.45e-55)
		tmp = b * ((c / (b ^ 2.0)) + (-1.0 / a));
	elseif (b <= 1.8e-61)
		tmp = (b + sqrt((a * (c * -4.0)))) * (0.5 / a);
	else
		tmp = c / -b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-55], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.8e-61], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-55}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\

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

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


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

    1. Initial program 59.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. *-commutative59.2%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(b \cdot \left(-1 \cdot \frac{c}{{b}^{2}} + \frac{1}{a}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg89.0%

        \[\leadsto \color{blue}{-b \cdot \left(-1 \cdot \frac{c}{{b}^{2}} + \frac{1}{a}\right)} \]
      2. *-commutative89.0%

        \[\leadsto -\color{blue}{\left(-1 \cdot \frac{c}{{b}^{2}} + \frac{1}{a}\right) \cdot b} \]
      3. distribute-rgt-neg-in89.0%

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

        \[\leadsto \color{blue}{\left(\frac{1}{a} + -1 \cdot \frac{c}{{b}^{2}}\right)} \cdot \left(-b\right) \]
      5. mul-1-neg89.0%

        \[\leadsto \left(\frac{1}{a} + \color{blue}{\left(-\frac{c}{{b}^{2}}\right)}\right) \cdot \left(-b\right) \]
      6. unsub-neg89.0%

        \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right)} \cdot \left(-b\right) \]
    7. Simplified89.0%

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

    if -1.45e-55 < b < 1.80000000000000007e-61

    1. Initial program 70.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. *-commutative70.6%

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{-4 \cdot \left(a \cdot c\right)}} - b}{a \cdot 2} \]
    6. Step-by-step derivation
      1. *-commutative66.0%

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}} - b}{a \cdot 2} \]
    8. Step-by-step derivation
      1. div-inv65.9%

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

        \[\leadsto \color{blue}{\log \left(e^{\sqrt{a \cdot \left(c \cdot -4\right)} - b}\right)} \cdot \frac{1}{a \cdot 2} \]
      3. add-log-exp65.9%

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

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

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

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

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

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

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

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

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

    if 1.80000000000000007e-61 < b

    1. Initial program 21.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. *-commutative21.6%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 83.8%

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

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

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

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

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

Alternative 4: 80.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -2.15 \cdot 10^{-55}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-62}:\\ \;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -2.15e-55)
   (- (/ b a))
   (if (<= b 1.2e-62)
     (* (+ b (sqrt (* a (* c -4.0)))) (/ 0.5 a))
     (/ c (- b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -2.15e-55) {
		tmp = -(b / a);
	} else if (b <= 1.2e-62) {
		tmp = (b + sqrt((a * (c * -4.0)))) * (0.5 / 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 <= (-2.15d-55)) then
        tmp = -(b / a)
    else if (b <= 1.2d-62) then
        tmp = (b + sqrt((a * (c * (-4.0d0))))) * (0.5d0 / 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 <= -2.15e-55) {
		tmp = -(b / a);
	} else if (b <= 1.2e-62) {
		tmp = (b + Math.sqrt((a * (c * -4.0)))) * (0.5 / a);
	} else {
		tmp = c / -b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -2.15e-55:
		tmp = -(b / a)
	elif b <= 1.2e-62:
		tmp = (b + math.sqrt((a * (c * -4.0)))) * (0.5 / a)
	else:
		tmp = c / -b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -2.15e-55)
		tmp = Float64(-Float64(b / a));
	elseif (b <= 1.2e-62)
		tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) * Float64(0.5 / a));
	else
		tmp = Float64(c / Float64(-b));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -2.15e-55)
		tmp = -(b / a);
	elseif (b <= 1.2e-62)
		tmp = (b + sqrt((a * (c * -4.0)))) * (0.5 / a);
	else
		tmp = c / -b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -2.15e-55], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 1.2e-62], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 59.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. *-commutative59.2%

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

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

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

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

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

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

    if -2.15000000000000005e-55 < b < 1.19999999999999992e-62

    1. Initial program 70.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. *-commutative70.6%

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{-4 \cdot \left(a \cdot c\right)}} - b}{a \cdot 2} \]
    6. Step-by-step derivation
      1. *-commutative66.0%

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}} - b}{a \cdot 2} \]
    8. Step-by-step derivation
      1. div-inv65.9%

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

        \[\leadsto \color{blue}{\log \left(e^{\sqrt{a \cdot \left(c \cdot -4\right)} - b}\right)} \cdot \frac{1}{a \cdot 2} \]
      3. add-log-exp65.9%

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

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

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

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

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

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

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

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

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

    if 1.19999999999999992e-62 < b

    1. Initial program 21.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. *-commutative21.6%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 83.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.15 \cdot 10^{-55}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-62}:\\ \;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 71.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-110}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-62}:\\ \;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(--0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.15e-110)
   (- (/ b a))
   (if (<= b 1.2e-62) (* (sqrt (* c (/ -4.0 a))) (- -0.5)) (/ c (- b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.15e-110) {
		tmp = -(b / a);
	} else if (b <= 1.2e-62) {
		tmp = sqrt((c * (-4.0 / a))) * -(-0.5);
	} 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 <= (-1.15d-110)) then
        tmp = -(b / a)
    else if (b <= 1.2d-62) then
        tmp = sqrt((c * ((-4.0d0) / a))) * -(-0.5d0)
    else
        tmp = c / -b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.15e-110) {
		tmp = -(b / a);
	} else if (b <= 1.2e-62) {
		tmp = Math.sqrt((c * (-4.0 / a))) * -(-0.5);
	} else {
		tmp = c / -b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -1.15e-110:
		tmp = -(b / a)
	elif b <= 1.2e-62:
		tmp = math.sqrt((c * (-4.0 / a))) * -(-0.5)
	else:
		tmp = c / -b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.15e-110)
		tmp = Float64(-Float64(b / a));
	elseif (b <= 1.2e-62)
		tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-(-0.5)));
	else
		tmp = Float64(c / Float64(-b));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -1.15e-110)
		tmp = -(b / a);
	elseif (b <= 1.2e-62)
		tmp = sqrt((c * (-4.0 / a))) * -(-0.5);
	else
		tmp = c / -b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -1.15e-110], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 1.2e-62], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (--0.5)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 60.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. *-commutative60.9%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified86.5%

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

    if -1.1500000000000001e-110 < b < 1.19999999999999992e-62

    1. Initial program 68.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. *-commutative68.7%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified68.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. Step-by-step derivation
      1. add-cube-cbrt68.1%

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{{\left(\sqrt[3]{4 \cdot a}\right)}^{3}} \cdot c}}{a \cdot 2} \]
    7. Taylor expanded in a around -inf 0.0%

      \[\leadsto \color{blue}{-0.5 \cdot \left(\sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}} \cdot {\left(\sqrt{-1}\right)}^{2}\right)} \]
    8. Step-by-step derivation
      1. *-commutative0.0%

        \[\leadsto -0.5 \cdot \color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}}\right)} \]
      2. unpow20.0%

        \[\leadsto -0.5 \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}}\right) \]
      3. rem-square-sqrt38.5%

        \[\leadsto -0.5 \cdot \left(\color{blue}{-1} \cdot \sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}}\right) \]
      4. associate-/l*38.5%

        \[\leadsto -0.5 \cdot \left(-1 \cdot \sqrt{\color{blue}{c \cdot \frac{{\left(\sqrt[3]{-4}\right)}^{3}}{a}}}\right) \]
      5. rem-cube-cbrt38.8%

        \[\leadsto -0.5 \cdot \left(-1 \cdot \sqrt{c \cdot \frac{\color{blue}{-4}}{a}}\right) \]
    9. Simplified38.8%

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

    if 1.19999999999999992e-62 < b

    1. Initial program 21.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. *-commutative21.6%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 83.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-110}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-62}:\\ \;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(--0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 67.5% accurate, 12.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -5e-310) (- (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -5e-310) {
		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 <= (-5d-310)) 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 <= -5e-310) {
		tmp = -(b / a);
	} else {
		tmp = c / -b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -5e-310:
		tmp = -(b / a)
	else:
		tmp = c / -b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -5e-310)
		tmp = Float64(-Float64(b / a));
	else
		tmp = Float64(c / Float64(-b));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -5e-310)
		tmp = -(b / a);
	else
		tmp = c / -b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], (-N[(b / a), $MachinePrecision]), N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 63.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. *-commutative63.5%

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

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

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

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

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

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

    if -4.999999999999985e-310 < b

    1. Initial program 32.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. *-commutative32.2%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 67.5%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
      2. mul-1-neg67.5%

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

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

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

Alternative 7: 42.2% accurate, 12.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 40000:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c) :precision binary64 (if (<= b 40000.0) (- (/ b a)) (/ c b)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= 40000.0) {
		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 <= 40000.0d0) 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 <= 40000.0) {
		tmp = -(b / a);
	} else {
		tmp = c / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= 40000.0:
		tmp = -(b / a)
	else:
		tmp = c / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= 40000.0)
		tmp = Float64(-Float64(b / a));
	else
		tmp = Float64(c / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= 40000.0)
		tmp = -(b / a);
	else
		tmp = c / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, 40000.0], (-N[(b / a), $MachinePrecision]), N[(c / b), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 40000:\\
\;\;\;\;-\frac{b}{a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 4e4

    1. Initial program 62.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. *-commutative62.2%

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

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

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

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

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

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

    if 4e4 < b

    1. Initial program 15.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. *-commutative15.1%

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

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

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

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

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

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

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

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

Alternative 8: 11.4% accurate, 38.7× speedup?

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

\\
\frac{c}{b}
\end{array}
Derivation
  1. Initial program 48.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. *-commutative48.4%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{c}{b}} \]
  9. Add Preprocessing

Alternative 9: 2.6% accurate, 38.7× speedup?

\[\begin{array}{l} \\ \frac{b}{a} \end{array} \]
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
	return b / 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 / a
end function
public static double code(double a, double b, double c) {
	return b / a;
}
def code(a, b, c):
	return b / a
function code(a, b, c)
	return Float64(b / a)
end
function tmp = code(a, b, c)
	tmp = b / a;
end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{b}{a}
\end{array}
Derivation
  1. Initial program 48.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. *-commutative48.4%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{b}{a}} \]
  9. Add Preprocessing

Reproduce

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