Quadratic roots, wide range

Percentage Accurate: 17.4% → 99.3%
Time: 10.2s
Alternatives: 5
Speedup: 29.0×

Specification

?
\[\left(\left(4.930380657631324 \cdot 10^{-32} < a \land a < 2.028240960365167 \cdot 10^{+31}\right) \land \left(4.930380657631324 \cdot 10^{-32} < b \land b < 2.028240960365167 \cdot 10^{+31}\right)\right) \land \left(4.930380657631324 \cdot 10^{-32} < c \land c < 2.028240960365167 \cdot 10^{+31}\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 5 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: 17.4% 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.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot \left(a \cdot 4\right)\\ \frac{\left({\left(-b\right)}^{2} - b \cdot b\right) + t_0}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - t_0}\right)} \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (* c (* a 4.0))))
   (/
    (+ (- (pow (- b) 2.0) (* b b)) t_0)
    (* (* 2.0 a) (- (- b) (sqrt (- (* b b) t_0)))))))
double code(double a, double b, double c) {
	double t_0 = c * (a * 4.0);
	return ((pow(-b, 2.0) - (b * b)) + t_0) / ((2.0 * a) * (-b - sqrt(((b * b) - t_0))));
}
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
    t_0 = c * (a * 4.0d0)
    code = (((-b ** 2.0d0) - (b * b)) + t_0) / ((2.0d0 * a) * (-b - sqrt(((b * b) - t_0))))
end function
public static double code(double a, double b, double c) {
	double t_0 = c * (a * 4.0);
	return ((Math.pow(-b, 2.0) - (b * b)) + t_0) / ((2.0 * a) * (-b - Math.sqrt(((b * b) - t_0))));
}
def code(a, b, c):
	t_0 = c * (a * 4.0)
	return ((math.pow(-b, 2.0) - (b * b)) + t_0) / ((2.0 * a) * (-b - math.sqrt(((b * b) - t_0))))
function code(a, b, c)
	t_0 = Float64(c * Float64(a * 4.0))
	return Float64(Float64(Float64((Float64(-b) ^ 2.0) - Float64(b * b)) + t_0) / Float64(Float64(2.0 * a) * Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - t_0)))))
end
function tmp = code(a, b, c)
	t_0 = c * (a * 4.0);
	tmp = (((-b ^ 2.0) - (b * b)) + t_0) / ((2.0 * a) * (-b - sqrt(((b * b) - t_0))));
end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[Power[(-b), 2.0], $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] / N[(N[(2.0 * a), $MachinePrecision] * N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 4\right)\\
\frac{\left({\left(-b\right)}^{2} - b \cdot b\right) + t_0}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - t_0}\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 17.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. flip-+17.2%

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

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

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{\frac{{\left(-b\right)}^{2} - \left(b \cdot b - c \cdot \left(a \cdot 4\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}}{2 \cdot a} \]
  4. Step-by-step derivation
    1. *-un-lft-identity17.7%

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

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

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

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

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

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

Alternative 2: 99.4% accurate, 1.0× speedup?

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

\\
\frac{\frac{4 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{2 \cdot a}
\end{array}
Derivation
  1. Initial program 17.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. flip-+17.2%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 95.5% accurate, 1.0× speedup?

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

\\
\frac{-c}{b} - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}
\end{array}
Derivation
  1. Initial program 17.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. neg-sub017.2%

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

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

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

      \[\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/17.1%

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

      \[\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*17.1%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b} - \frac{{c}^{2} \cdot a}{{b}^{3}}} \]
    4. associate-*r/95.2%

      \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} - \frac{{c}^{2} \cdot a}{{b}^{3}} \]
    5. neg-mul-195.2%

      \[\leadsto \frac{\color{blue}{-c}}{b} - \frac{{c}^{2} \cdot a}{{b}^{3}} \]
    6. unpow295.2%

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

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

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

    \[\leadsto \frac{-c}{b} - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}} \]

Alternative 4: 95.1% accurate, 5.5× speedup?

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

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

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

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

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

      \[\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/17.1%

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

      \[\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*17.1%

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

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

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

    \[\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 a around 0 11.9%

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

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

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

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

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

      \[\leadsto \frac{b \cdot b - \left(b + \color{blue}{-2 \cdot \frac{c}{\frac{b}{a}}}\right) \cdot \left(b + \frac{c}{\frac{b}{a}} \cdot -2\right)}{b + \left(b + \frac{c}{\frac{b}{a}} \cdot -2\right)} \cdot \frac{-0.5}{a} \]
    3. associate-/r/11.8%

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

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

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

      \[\leadsto \frac{b \cdot b - \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right) \cdot \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)}{b + \left(b + \color{blue}{-2 \cdot \frac{c}{\frac{b}{a}}}\right)} \cdot \frac{-0.5}{a} \]
    7. associate-/r/11.8%

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

    \[\leadsto \color{blue}{\frac{b \cdot b - \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right) \cdot \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)}{b + \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)}} \cdot \frac{-0.5}{a} \]
  9. Step-by-step derivation
    1. difference-of-squares11.9%

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

      \[\leadsto \frac{\left(b + \left(b + -2 \cdot \color{blue}{\frac{c \cdot a}{b}}\right)\right) \cdot \left(b - \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)\right)}{b + \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)} \cdot \frac{-0.5}{a} \]
    3. associate-*r/11.9%

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

      \[\leadsto \frac{\left(b + \left(b + \frac{\color{blue}{\left(-2 \cdot c\right) \cdot a}}{b}\right)\right) \cdot \left(b - \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)\right)}{b + \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)} \cdot \frac{-0.5}{a} \]
    5. associate--r+90.3%

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

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

      \[\leadsto \frac{\left(b + \left(b + \frac{\left(-2 \cdot c\right) \cdot a}{b}\right)\right) \cdot \left(0 - -2 \cdot \color{blue}{\frac{c \cdot a}{b}}\right)}{b + \left(b + -2 \cdot \left(\frac{c}{b} \cdot a\right)\right)} \cdot \frac{-0.5}{a} \]
    8. neg-sub090.1%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(b + \left(b + \frac{\left(-2 \cdot c\right) \cdot a}{b}\right)\right) \cdot \left(2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{b + \left(b + \frac{\left(-2 \cdot c\right) \cdot a}{b}\right)}} \cdot \frac{-0.5}{a} \]
  11. Taylor expanded in b around inf 94.8%

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

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

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

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

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

Alternative 5: 90.7% 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 17.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. neg-sub017.2%

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

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

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

      \[\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/17.1%

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

      \[\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*17.1%

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

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

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

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

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

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

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

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

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

Reproduce

?
herbie shell --seed 2023178 
(FPCore (a b c)
  :name "Quadratic roots, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))