Quadratic roots, full range

Percentage Accurate: 52.9% → 85.5%
Time: 19.0s
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: 52.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: 85.5% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-112}:\\ \;\;\;\;\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 -5e+153)
   (- (/ c b) (/ b a))
   (if (<= b 5e-112)
     (/ (- (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 <= -5e+153) {
		tmp = (c / b) - (b / a);
	} else if (b <= 5e-112) {
		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 <= (-5d+153)) then
        tmp = (c / b) - (b / a)
    else if (b <= 5d-112) 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 <= -5e+153) {
		tmp = (c / b) - (b / a);
	} else if (b <= 5e-112) {
		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 <= -5e+153:
		tmp = (c / b) - (b / a)
	elif b <= 5e-112:
		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 <= -5e+153)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= 5e-112)
		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 <= -5e+153)
		tmp = (c / b) - (b / a);
	elseif (b <= 5e-112)
		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, -5e+153], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e-112], 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 -5 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 5 \cdot 10^{-112}:\\
\;\;\;\;\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 < -5.00000000000000018e153

    1. Initial program 45.8%

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

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

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

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

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

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

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

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

    if -5.00000000000000018e153 < b < 5.00000000000000044e-112

    1. Initial program 82.9%

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

    if 5.00000000000000044e-112 < 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{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 86.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-112}:\\ \;\;\;\;\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: 80.2% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 67.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. *-commutative67.9%

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

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

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

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

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

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

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

    if -4.30000000000000013e-44 < b < 1.35e-116

    1. Initial program 78.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. *-commutative78.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{{\left({\left(\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)\right)}^{0.25}\right)}^{2}} - b\right) \]
    10. Taylor expanded in a around inf 33.1%

      \[\leadsto \frac{0.5}{a} \cdot \color{blue}{\left({\left(e^{0.25 \cdot \left(\log \left(-4 \cdot c\right) + -1 \cdot \log \left(\frac{1}{a}\right)\right)}\right)}^{2} - b\right)} \]
    11. Step-by-step derivation
      1. *-commutative33.1%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left(e^{\color{blue}{\left(\log \left(-4 \cdot c\right) + -1 \cdot \log \left(\frac{1}{a}\right)\right) \cdot 0.25}}\right)}^{2} - b\right) \]
      2. exp-prod29.1%

        \[\leadsto \frac{0.5}{a} \cdot \left({\color{blue}{\left({\left(e^{\log \left(-4 \cdot c\right) + -1 \cdot \log \left(\frac{1}{a}\right)}\right)}^{0.25}\right)}}^{2} - b\right) \]
      3. +-commutative29.1%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left({\left(e^{\color{blue}{-1 \cdot \log \left(\frac{1}{a}\right) + \log \left(-4 \cdot c\right)}}\right)}^{0.25}\right)}^{2} - b\right) \]
      4. mul-1-neg29.1%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left({\left(e^{\color{blue}{\left(-\log \left(\frac{1}{a}\right)\right)} + \log \left(-4 \cdot c\right)}\right)}^{0.25}\right)}^{2} - b\right) \]
      5. log-rec29.1%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left({\left(e^{\left(-\color{blue}{\left(-\log a\right)}\right) + \log \left(-4 \cdot c\right)}\right)}^{0.25}\right)}^{2} - b\right) \]
      6. remove-double-neg29.1%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left({\left(e^{\color{blue}{\log a} + \log \left(-4 \cdot c\right)}\right)}^{0.25}\right)}^{2} - b\right) \]
      7. *-commutative29.1%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left({\left(e^{\log a + \log \color{blue}{\left(c \cdot -4\right)}}\right)}^{0.25}\right)}^{2} - b\right) \]
      8. log-prod66.5%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left({\left(e^{\color{blue}{\log \left(a \cdot \left(c \cdot -4\right)\right)}}\right)}^{0.25}\right)}^{2} - b\right) \]
      9. rem-exp-log70.2%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left({\color{blue}{\left(a \cdot \left(c \cdot -4\right)\right)}}^{0.25}\right)}^{2} - b\right) \]
      10. unpow270.2%

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{{\left(a \cdot \left(c \cdot -4\right)\right)}^{0.25} \cdot {\left(a \cdot \left(c \cdot -4\right)\right)}^{0.25}} - b\right) \]
      11. pow-sqr70.5%

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{{\left(a \cdot \left(c \cdot -4\right)\right)}^{\left(2 \cdot 0.25\right)}} - b\right) \]
      12. metadata-eval70.5%

        \[\leadsto \frac{0.5}{a} \cdot \left({\left(a \cdot \left(c \cdot -4\right)\right)}^{\color{blue}{0.5}} - b\right) \]
      13. unpow1/270.5%

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

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

    if 1.35e-116 < 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{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 86.7%

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

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

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

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

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

Alternative 3: 80.5% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 67.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. *-commutative67.9%

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

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

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

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

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

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

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

    if -7.2000000000000004e-42 < b < 6.1999999999999995e-112

    1. Initial program 78.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. *-commutative78.2%

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + {\color{blue}{\left({\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{\left(\frac{0.5}{2}\right)}\right)}}^{2}}{a \cdot 2} \]
      5. sub-neg77.9%

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

        \[\leadsto \frac{\left(-b\right) + {\left({\color{blue}{\left(\left(-\left(4 \cdot a\right) \cdot c\right) + b \cdot b\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
      7. distribute-lft-neg-in77.9%

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + {\left({\left(a \cdot \color{blue}{\left(c \cdot -4\right)} + b \cdot b\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
      13. fma-undefine77.9%

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

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

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

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

      \[\leadsto \frac{\left(-b\right) + {\color{blue}{\left({\left(-4 \cdot \left(a \cdot c\right)\right)}^{0.25}\right)}}^{2}}{a \cdot 2} \]
    8. Step-by-step derivation
      1. associate-*r*70.2%

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

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

      \[\leadsto \frac{\left(-b\right) + {\color{blue}{\left({\left(\left(a \cdot -4\right) \cdot c\right)}^{0.25}\right)}}^{2}}{a \cdot 2} \]
    10. Step-by-step derivation
      1. frac-2neg70.2%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(-b\right) - {\left({\left(\left(a \cdot -4\right) \cdot c\right)}^{0.25}\right)}^{2}\right)} \cdot \frac{1}{-a \cdot 2} \]
      10. add-sqr-sqrt43.1%

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

        \[\leadsto \left(\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} - {\left({\left(\left(a \cdot -4\right) \cdot c\right)}^{0.25}\right)}^{2}\right) \cdot \frac{1}{-a \cdot 2} \]
      12. sqr-neg67.9%

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

        \[\leadsto \left(\color{blue}{\sqrt{b} \cdot \sqrt{b}} - {\left({\left(\left(a \cdot -4\right) \cdot c\right)}^{0.25}\right)}^{2}\right) \cdot \frac{1}{-a \cdot 2} \]
      14. add-sqr-sqrt70.2%

        \[\leadsto \left(\color{blue}{b} - {\left({\left(\left(a \cdot -4\right) \cdot c\right)}^{0.25}\right)}^{2}\right) \cdot \frac{1}{-a \cdot 2} \]
      15. pow-pow70.5%

        \[\leadsto \left(b - \color{blue}{{\left(\left(a \cdot -4\right) \cdot c\right)}^{\left(0.25 \cdot 2\right)}}\right) \cdot \frac{1}{-a \cdot 2} \]
      16. metadata-eval70.5%

        \[\leadsto \left(b - {\left(\left(a \cdot -4\right) \cdot c\right)}^{\color{blue}{0.5}}\right) \cdot \frac{1}{-a \cdot 2} \]
      17. pow1/270.5%

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

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

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

      \[\leadsto \color{blue}{\left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{1}{a \cdot -2}} \]
    12. Step-by-step derivation
      1. associate-*r/70.5%

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

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

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

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

    if 6.1999999999999995e-112 < 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{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 86.7%

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

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

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

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

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

Alternative 4: 66.8% accurate, 9.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\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 < -5.00000000000023e-311

    1. Initial program 73.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. *-commutative73.3%

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

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

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

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

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

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

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

    if -5.00000000000023e-311 < b

    1. Initial program 26.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. *-commutative26.9%

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

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

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

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

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

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

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

Alternative 5: 42.5% accurate, 12.9× speedup?

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

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

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


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

    1. Initial program 64.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. *-commutative64.1%

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

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

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

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

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

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

    if 1.3e29 < b

    1. Initial program 11.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. *-commutative11.0%

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

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

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

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

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

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

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

Alternative 6: 66.6% accurate, 12.9× speedup?

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

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

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


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

    1. Initial program 73.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. *-commutative73.3%

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

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

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

        \[\leadsto \color{blue}{-\frac{b}{a}} \]
      2. distribute-neg-frac268.1%

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

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

    if -5.00000000000023e-311 < b

    1. Initial program 26.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. *-commutative26.9%

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

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

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

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

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

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

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

Alternative 7: 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 49.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. *-commutative49.4%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{b}{a}} \]
  9. Final simplification2.4%

    \[\leadsto \frac{b}{a} \]
  10. Add Preprocessing

Alternative 8: 10.7% 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 49.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. *-commutative49.4%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{c}{b}} \]
  9. Final simplification12.5%

    \[\leadsto \frac{c}{b} \]
  10. Add Preprocessing

Reproduce

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