Quadratic roots, full range

Percentage Accurate: 64.2% → 89.2%
Time: 13.6s
Alternatives: 9
Speedup: 9.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 64.2% accurate, 1.0× speedup?

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

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

Alternative 1: 89.2% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;b \leq 2 \cdot 10^{+89}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\

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


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

    1. Initial program 36.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. *-commutative36.8%

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + \left(\color{blue}{\frac{a \cdot c}{b} \cdot 2} - b\right)}{a \cdot 2} \]
      5. associate-/l*99.9%

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

        \[\leadsto \frac{\left(-b\right) + \left(\color{blue}{a \cdot \left(\frac{c}{b} \cdot 2\right)} - b\right)}{a \cdot 2} \]
      7. fma-neg99.9%

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

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

    if -2e156 < b < 1.99999999999999999e89

    1. Initial program 84.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. *-commutative84.3%

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

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

    if 1.99999999999999999e89 < b

    1. Initial program 27.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. *-commutative27.6%

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr25.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-neg25.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--27.6%

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

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

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

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

Alternative 2: 78.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c}{b} - \frac{b}{a}\\ t_1 := \frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\ \mathbf{if}\;b \leq -1.75 \cdot 10^{-34}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;b \leq -3.7 \cdot 10^{-74}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;b \leq -2.1 \cdot 10^{-102}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{-146}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(b - b\right)\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (- (/ c b) (/ b a)))
        (t_1 (* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))))
   (if (<= b -1.75e-34)
     t_0
     (if (<= b -3.7e-74)
       t_1
       (if (<= b -2.1e-102)
         t_0
         (if (<= b 1.5e-146) t_1 (* (/ 0.5 a) (- b b))))))))
double code(double a, double b, double c) {
	double t_0 = (c / b) - (b / a);
	double t_1 = (-0.5 / a) * (b - sqrt((a * (c * -4.0))));
	double tmp;
	if (b <= -1.75e-34) {
		tmp = t_0;
	} else if (b <= -3.7e-74) {
		tmp = t_1;
	} else if (b <= -2.1e-102) {
		tmp = t_0;
	} else if (b <= 1.5e-146) {
		tmp = t_1;
	} else {
		tmp = (0.5 / a) * (b - 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (c / b) - (b / a)
    t_1 = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.0d0)))))
    if (b <= (-1.75d-34)) then
        tmp = t_0
    else if (b <= (-3.7d-74)) then
        tmp = t_1
    else if (b <= (-2.1d-102)) then
        tmp = t_0
    else if (b <= 1.5d-146) then
        tmp = t_1
    else
        tmp = (0.5d0 / a) * (b - b)
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double t_0 = (c / b) - (b / a);
	double t_1 = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
	double tmp;
	if (b <= -1.75e-34) {
		tmp = t_0;
	} else if (b <= -3.7e-74) {
		tmp = t_1;
	} else if (b <= -2.1e-102) {
		tmp = t_0;
	} else if (b <= 1.5e-146) {
		tmp = t_1;
	} else {
		tmp = (0.5 / a) * (b - b);
	}
	return tmp;
}
def code(a, b, c):
	t_0 = (c / b) - (b / a)
	t_1 = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0))))
	tmp = 0
	if b <= -1.75e-34:
		tmp = t_0
	elif b <= -3.7e-74:
		tmp = t_1
	elif b <= -2.1e-102:
		tmp = t_0
	elif b <= 1.5e-146:
		tmp = t_1
	else:
		tmp = (0.5 / a) * (b - b)
	return tmp
function code(a, b, c)
	t_0 = Float64(Float64(c / b) - Float64(b / a))
	t_1 = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0)))))
	tmp = 0.0
	if (b <= -1.75e-34)
		tmp = t_0;
	elseif (b <= -3.7e-74)
		tmp = t_1;
	elseif (b <= -2.1e-102)
		tmp = t_0;
	elseif (b <= 1.5e-146)
		tmp = t_1;
	else
		tmp = Float64(Float64(0.5 / a) * Float64(b - b));
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	t_0 = (c / b) - (b / a);
	t_1 = (-0.5 / a) * (b - sqrt((a * (c * -4.0))));
	tmp = 0.0;
	if (b <= -1.75e-34)
		tmp = t_0;
	elseif (b <= -3.7e-74)
		tmp = t_1;
	elseif (b <= -2.1e-102)
		tmp = t_0;
	elseif (b <= 1.5e-146)
		tmp = t_1;
	else
		tmp = (0.5 / a) * (b - b);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.75e-34], t$95$0, If[LessEqual[b, -3.7e-74], t$95$1, If[LessEqual[b, -2.1e-102], t$95$0, If[LessEqual[b, 1.5e-146], t$95$1, N[(N[(0.5 / a), $MachinePrecision] * N[(b - b), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := \frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{if}\;b \leq -1.75 \cdot 10^{-34}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;b \leq -3.7 \cdot 10^{-74}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;b \leq -2.1 \cdot 10^{-102}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;b \leq 1.5 \cdot 10^{-146}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -1.75e-34 or -3.69999999999999994e-74 < b < -2.1e-102

    1. Initial program 65.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. *-commutative65.2%

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

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

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

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

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

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

    if -1.75e-34 < b < -3.69999999999999994e-74 or -2.1e-102 < b < 1.50000000000000009e-146

    1. Initial program 80.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. *-commutative80.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \left(-\frac{\color{blue}{0.5}}{a}\right) \]
    9. Applied egg-rr79.3%

      \[\leadsto \color{blue}{\left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}} \]
    10. Step-by-step derivation
      1. *-commutative79.3%

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

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

    if 1.50000000000000009e-146 < b

    1. Initial program 51.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. *-commutative51.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.75 \cdot 10^{-34}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.7 \cdot 10^{-74}:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\ \mathbf{elif}\;b \leq -2.1 \cdot 10^{-102}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{-146}:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(b - b\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 89.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{+156}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{b} \cdot 2, -b\right) - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.2 \cdot 10^{+88}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(b - b\right)\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -2e+156)
   (/ (- (fma a (* (/ c b) 2.0) (- b)) b) (* a 2.0))
   (if (<= b 3.2e+88)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
     (* (/ 0.5 a) (- b b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -2e+156) {
		tmp = (fma(a, ((c / b) * 2.0), -b) - b) / (a * 2.0);
	} else if (b <= 3.2e+88) {
		tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
	} else {
		tmp = (0.5 / a) * (b - b);
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -2e+156)
		tmp = Float64(Float64(fma(a, Float64(Float64(c / b) * 2.0), Float64(-b)) - b) / Float64(a * 2.0));
	elseif (b <= 3.2e+88)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(Float64(0.5 / a) * Float64(b - b));
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -2e+156], N[(N[(N[(a * N[(N[(c / b), $MachinePrecision] * 2.0), $MachinePrecision] + (-b)), $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.2e+88], 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[(N[(0.5 / a), $MachinePrecision] * N[(b - b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 36.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. *-commutative36.8%

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + \left(\color{blue}{\frac{a \cdot c}{b} \cdot 2} - b\right)}{a \cdot 2} \]
      5. associate-/l*99.9%

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

        \[\leadsto \frac{\left(-b\right) + \left(\color{blue}{a \cdot \left(\frac{c}{b} \cdot 2\right)} - b\right)}{a \cdot 2} \]
      7. fma-neg99.9%

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

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

    if -2e156 < b < 3.1999999999999999e88

    1. Initial program 84.3%

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

    if 3.1999999999999999e88 < b

    1. Initial program 27.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. *-commutative27.6%

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr25.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-neg25.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--27.6%

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

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

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

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

Alternative 4: 65.8% accurate, 9.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -1.999999999999994e-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. Simplified69.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 67.1%

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

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

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

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

    if -1.999999999999994e-310 < b

    1. Initial program 55.7%

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

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

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

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

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

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

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

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

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

Alternative 5: 66.0% accurate, 9.7× speedup?

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

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

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


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

    1. Initial program 69.7%

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

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

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

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

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

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

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

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

    if -2.35000000000000006e-293 < b

    1. Initial program 56.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. *-commutative56.0%

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

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

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

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

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

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

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

Alternative 6: 45.7% accurate, 12.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \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 < -1.999999999999994e-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. Simplified69.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 67.1%

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

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

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

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

    if -1.999999999999994e-310 < b

    1. Initial program 55.7%

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

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

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

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

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

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

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

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

Alternative 7: 12.6% accurate, 29.0× 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(-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 63.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. *-commutative63.6%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{c}{-b}} \]
  8. Final simplification14.2%

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

Alternative 8: 2.4% 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 63.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. *-commutative63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{b + \mathsf{hypot}\left(\sqrt{a \cdot \left(c \cdot -4\right)}, b\right)}{a \cdot 2}} \]
  10. Taylor expanded in b around inf 2.3%

    \[\leadsto \color{blue}{\frac{b}{a}} \]
  11. Final simplification2.3%

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

Alternative 9: 11.3% 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 63.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. *-commutative63.6%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]
  8. Taylor expanded in c around inf 12.7%

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

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

Reproduce

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