Quadratic roots, full range

Percentage Accurate: 51.9% → 86.6%
Time: 11.2s
Alternatives: 8
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 8 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.9% 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: 86.6% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+135}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 1.05 \cdot 10^{-72}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \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 < -1.99999999999999992e135

    1. Initial program 47.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. *-commutative47.4%

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

      \[\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.6%

      \[\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.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right) \cdot \left(-b\right)} \]
    8. Taylor expanded in a around inf 90.7%

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

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

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

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

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

    if -1.99999999999999992e135 < b < 1.05e-72

    1. Initial program 82.1%

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

    if 1.05e-72 < b

    1. Initial program 17.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. *-commutative17.9%

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

      \[\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 85.2%

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

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

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

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

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

Alternative 2: 81.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.25 \cdot 10^{-67}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.5 \cdot 10^{-73}:\\ \;\;\;\;\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 -1.25e-67)
   (- (/ c b) (/ b a))
   (if (<= b 6.5e-73)
     (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
     (/ c (- b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.25e-67) {
		tmp = (c / b) - (b / a);
	} else if (b <= 6.5e-73) {
		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 <= (-1.25d-67)) then
        tmp = (c / b) - (b / a)
    else if (b <= 6.5d-73) 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 <= -1.25e-67) {
		tmp = (c / b) - (b / a);
	} else if (b <= 6.5e-73) {
		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 <= -1.25e-67:
		tmp = (c / b) - (b / a)
	elif b <= 6.5e-73:
		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 <= -1.25e-67)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= 6.5e-73)
		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 <= -1.25e-67)
		tmp = (c / b) - (b / a);
	elseif (b <= 6.5e-73)
		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, -1.25e-67], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.5e-73], 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 -1.25 \cdot 10^{-67}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 6.5 \cdot 10^{-73}:\\
\;\;\;\;\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 < -1.25e-67

    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 80.8%

      \[\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-neg80.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right) \cdot \left(-b\right)} \]
    8. Taylor expanded in a around inf 81.6%

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

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

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

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

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

    if -1.25e-67 < b < 6.4999999999999999e-73

    1. Initial program 81.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. *-commutative81.0%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified81.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 a around inf 74.9%

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

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

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

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

    if 6.4999999999999999e-73 < b

    1. Initial program 17.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. *-commutative17.9%

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

      \[\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 85.2%

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

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

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

      \[\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 -1.25 \cdot 10^{-67}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.5 \cdot 10^{-73}:\\ \;\;\;\;\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: 81.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -5.6 \cdot 10^{-68}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-70}:\\ \;\;\;\;\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 -5.6e-68)
   (- (/ c b) (/ b a))
   (if (<= b 1.9e-70)
     (* (- b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
     (/ c (- b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.6e-68) {
		tmp = (c / b) - (b / a);
	} else if (b <= 1.9e-70) {
		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 <= (-5.6d-68)) then
        tmp = (c / b) - (b / a)
    else if (b <= 1.9d-70) 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 <= -5.6e-68) {
		tmp = (c / b) - (b / a);
	} else if (b <= 1.9e-70) {
		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 <= -5.6e-68:
		tmp = (c / b) - (b / a)
	elif b <= 1.9e-70:
		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 <= -5.6e-68)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= 1.9e-70)
		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 <= -5.6e-68)
		tmp = (c / b) - (b / a);
	elseif (b <= 1.9e-70)
		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, -5.6e-68], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.9e-70], 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 -5.6 \cdot 10^{-68}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 1.9 \cdot 10^{-70}:\\
\;\;\;\;\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 < -5.6000000000000002e-68

    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 80.8%

      \[\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-neg80.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right) \cdot \left(-b\right)} \]
    8. Taylor expanded in a around inf 81.6%

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

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

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

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

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

    if -5.6000000000000002e-68 < b < 1.8999999999999999e-70

    1. Initial program 81.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. *-commutative81.0%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified81.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 a around inf 74.9%

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

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

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

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

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

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

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

        \[\leadsto \frac{{\color{blue}{\left({\left(a \cdot \left(c \cdot -4\right)\right)}^{\left(\frac{3}{2}\right)}\right)}}^{0.3333333333333333} - b}{a \cdot 2} \]
      5. metadata-eval47.5%

        \[\leadsto \frac{{\left({\left(a \cdot \left(c \cdot -4\right)\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} - b}{a \cdot 2} \]
    9. Applied egg-rr47.5%

      \[\leadsto \frac{\color{blue}{{\left({\left(a \cdot \left(c \cdot -4\right)\right)}^{1.5}\right)}^{0.3333333333333333}} - b}{a \cdot 2} \]
    10. Step-by-step derivation
      1. unpow1/350.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{\color{blue}{-0.5}}{a} \]
    15. Simplified74.8%

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

    if 1.8999999999999999e-70 < b

    1. Initial program 17.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. *-commutative17.9%

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

      \[\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 85.2%

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

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

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

      \[\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 -5.6 \cdot 10^{-68}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-70}:\\ \;\;\;\;\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: 68.5% accurate, 9.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -4 \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 -4e-310) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
		tmp = (c / b) - (b / a);
	} else {
		tmp = c / -b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -4e-310:
		tmp = (c / b) - (b / a)
	else:
		tmp = c / -b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -4e-310)
		tmp = Float64(Float64(c / b) - 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 <= -4e-310)
		tmp = (c / b) - (b / a);
	else
		tmp = c / -b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \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 < -3.999999999999988e-310

    1. Initial program 69.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. *-commutative69.9%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified70.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 62.6%

      \[\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-neg62.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right) \cdot \left(-b\right)} \]
    8. Taylor expanded in a around inf 65.6%

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

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

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

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

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

    if -3.999999999999988e-310 < b

    1. Initial program 33.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. *-commutative33.9%

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

      \[\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 66.2%

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

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

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

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

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

Alternative 5: 68.3% accurate, 12.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \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 < -3.999999999999988e-310

    1. Initial program 69.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. *-commutative69.9%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified70.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 65.1%

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

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

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

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

    if -3.999999999999988e-310 < b

    1. Initial program 33.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. *-commutative33.9%

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

      \[\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 66.2%

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

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

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

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

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

Alternative 6: 43.1% accurate, 12.9× speedup?

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

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

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


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

    1. Initial program 69.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. *-commutative69.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified69.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 b around -inf 50.6%

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

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

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

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

    if 2.85000000000000001e-24 < b

    1. Initial program 17.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. *-commutative17.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified17.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 b around -inf 2.4%

      \[\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-neg2.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right) \cdot \left(-b\right)} \]
    8. Taylor expanded in a around inf 24.3%

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

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

Alternative 7: 10.9% 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 52.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. *-commutative52.3%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Simplified52.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 33.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-neg33.0%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\frac{1}{a} - \frac{c}{{b}^{2}}\right) \cdot \left(-b\right)} \]
  8. Taylor expanded in a around inf 10.2%

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

Alternative 8: 2.5% 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 52.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. *-commutative52.3%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Simplified52.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 34.6%

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

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

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

    \[\leadsto \color{blue}{\frac{-b}{a}} \]
  8. Step-by-step derivation
    1. div-inv34.5%

      \[\leadsto \color{blue}{\left(-b\right) \cdot \frac{1}{a}} \]
    2. add-sqr-sqrt33.2%

      \[\leadsto \color{blue}{\left(\sqrt{-b} \cdot \sqrt{-b}\right)} \cdot \frac{1}{a} \]
    3. sqrt-unprod24.7%

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

      \[\leadsto \sqrt{\color{blue}{b \cdot b}} \cdot \frac{1}{a} \]
    5. sqrt-prod1.7%

      \[\leadsto \color{blue}{\left(\sqrt{b} \cdot \sqrt{b}\right)} \cdot \frac{1}{a} \]
    6. add-sqr-sqrt2.6%

      \[\leadsto \color{blue}{b} \cdot \frac{1}{a} \]
  9. Applied egg-rr2.6%

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

      \[\leadsto \color{blue}{\frac{b \cdot 1}{a}} \]
    2. *-rgt-identity2.6%

      \[\leadsto \frac{\color{blue}{b}}{a} \]
  11. Simplified2.6%

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

Reproduce

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