Quadratic roots, medium range

Percentage Accurate: 30.7% → 99.6%
Time: 8.2s
Alternatives: 4
Speedup: 29.0×

Specification

?
\[\left(\left(1.1102230246251565 \cdot 10^{-16} < a \land a < 9007199254740992\right) \land \left(1.1102230246251565 \cdot 10^{-16} < b \land b < 9007199254740992\right)\right) \land \left(1.1102230246251565 \cdot 10^{-16} < c \land c < 9007199254740992\right)\]
\[\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 4 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: 30.7% 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: 99.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \frac{\frac{\left(-2 \cdot a\right) \cdot c}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (/ (* (* -2.0 a) c) a) (+ b (sqrt (fma a (* c -4.0) (* b b))))))
double code(double a, double b, double c) {
	return (((-2.0 * a) * c) / a) / (b + sqrt(fma(a, (c * -4.0), (b * b))));
}
function code(a, b, c)
	return Float64(Float64(Float64(Float64(-2.0 * a) * c) / a) / Float64(b + sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))))
end
code[a_, b_, c_] := N[(N[(N[(N[(-2.0 * a), $MachinePrecision] * c), $MachinePrecision] / a), $MachinePrecision] / N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{\left(-2 \cdot a\right) \cdot c}{a}}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}
\end{array}
Derivation
  1. Initial program 29.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. neg-sub029.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(4 \cdot \left(c \cdot a\right)\right) \cdot -0.5}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right) \cdot a}} \]
  12. Step-by-step derivation
    1. associate-/l/99.6%

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

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

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

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

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

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

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

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

Alternative 2: 99.3% accurate, 1.0× speedup?

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

\\
\frac{4 \cdot \left(a \cdot c\right)}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}} \cdot \frac{-0.5}{a}
\end{array}
Derivation
  1. Initial program 29.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. neg-sub029.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 91.1% accurate, 1.0× speedup?

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

\\
\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}
\end{array}
Derivation
  1. Initial program 29.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. neg-sub029.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + -1 \cdot \frac{c}{b}} \]
  8. Step-by-step derivation
    1. distribute-lft-out91.2%

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

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

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

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

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

      \[\leadsto -\left(\frac{c}{b} + \color{blue}{\frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}}\right) \]
  9. Simplified91.2%

    \[\leadsto \color{blue}{-\left(\frac{c}{b} + \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}\right)} \]
  10. Final simplification91.2%

    \[\leadsto \frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}} \]

Alternative 4: 81.8% 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 29.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. neg-sub029.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-c}}{b} \]
  6. Simplified82.3%

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

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

Reproduce

?
herbie shell --seed 2023200 
(FPCore (a b c)
  :name "Quadratic roots, medium range"
  :precision binary64
  :pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))