Quadratic roots, narrow range

Percentage Accurate: 55.7% → 90.6%
Time: 16.4s
Alternatives: 7
Speedup: 29.0×

Specification

?
\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\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 7 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: 55.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: 90.6% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := {\left(a \cdot c\right)}^{4}\\
-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(\left(-0.25 \cdot \frac{16 \cdot t\_0 + 4 \cdot t\_0}{a \cdot {b}^{7}} - \frac{a \cdot {c}^{2}}{{b}^{3}}\right) - \frac{c}{b}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 55.4%

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

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

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

    \[\leadsto \color{blue}{-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.25 \cdot \frac{16 \cdot \left({a}^{4} \cdot {c}^{4}\right) + {\left(-2 \cdot \left({a}^{2} \cdot {c}^{2}\right)\right)}^{2}}{a \cdot {b}^{7}}\right)\right)} \]
  6. Step-by-step derivation
    1. *-commutative91.0%

      \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.25 \cdot \frac{16 \cdot \left({a}^{4} \cdot {c}^{4}\right) + {\color{blue}{\left(\left({a}^{2} \cdot {c}^{2}\right) \cdot -2\right)}}^{2}}{a \cdot {b}^{7}}\right)\right) \]
    2. unpow-prod-down91.0%

      \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.25 \cdot \frac{16 \cdot \left({a}^{4} \cdot {c}^{4}\right) + \color{blue}{{\left({a}^{2} \cdot {c}^{2}\right)}^{2} \cdot {-2}^{2}}}{a \cdot {b}^{7}}\right)\right) \]
    3. pow-prod-down91.0%

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

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

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

      \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.25 \cdot \frac{16 \cdot \left({a}^{4} \cdot {c}^{4}\right) + {\left(a \cdot c\right)}^{4} \cdot \color{blue}{4}}{a \cdot {b}^{7}}\right)\right) \]
  7. Applied egg-rr91.0%

    \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.25 \cdot \frac{16 \cdot \left({a}^{4} \cdot {c}^{4}\right) + \color{blue}{{\left(a \cdot c\right)}^{4} \cdot 4}}{a \cdot {b}^{7}}\right)\right) \]
  8. Step-by-step derivation
    1. pow-prod-down91.0%

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

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

      \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.25 \cdot \frac{16 \cdot \color{blue}{{\left({\left(a \cdot c\right)}^{2}\right)}^{2}} + {\left(a \cdot c\right)}^{4} \cdot 4}{a \cdot {b}^{7}}\right)\right) \]
  9. Applied egg-rr91.0%

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

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

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

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

    \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-1 \cdot \frac{c}{b} + \left(-1 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.25 \cdot \frac{16 \cdot \color{blue}{{\left(a \cdot c\right)}^{4}} + {\left(a \cdot c\right)}^{4} \cdot 4}{a \cdot {b}^{7}}\right)\right) \]
  12. Final simplification91.0%

    \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(\left(-0.25 \cdot \frac{16 \cdot {\left(a \cdot c\right)}^{4} + 4 \cdot {\left(a \cdot c\right)}^{4}}{a \cdot {b}^{7}} - \frac{a \cdot {c}^{2}}{{b}^{3}}\right) - \frac{c}{b}\right) \]
  13. Add Preprocessing

Alternative 2: 87.5% accurate, 0.2× speedup?

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

\\
-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} - \left(\frac{c}{b} + \frac{a \cdot {c}^{2}}{{b}^{3}}\right)
\end{array}
Derivation
  1. Initial program 55.4%

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

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

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

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

    \[\leadsto -2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} - \left(\frac{c}{b} + \frac{a \cdot {c}^{2}}{{b}^{3}}\right) \]
  7. Add Preprocessing

Alternative 3: 87.3% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{a \cdot c}{b}\\
\frac{-4 \cdot \frac{{c}^{3} \cdot {a}^{3}}{{b}^{5}} + \left(-2 \cdot t\_0 + -2 \cdot \left(t\_0 \cdot \frac{a \cdot c}{{b}^{2}}\right)\right)}{a \cdot 2}
\end{array}
\end{array}
Derivation
  1. Initial program 55.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-4 \cdot \frac{{a}^{3} \cdot {c}^{3}}{{b}^{5}} + \left(-2 \cdot \frac{a \cdot c}{b} + -2 \cdot \left(\frac{a \cdot \color{blue}{c}}{\sqrt{{b}^{3}}} \cdot \sqrt{\frac{{a}^{2} \cdot {c}^{2}}{{b}^{3}}}\right)\right)}{a \cdot 2} \]
    10. rem-cbrt-cube87.7%

      \[\leadsto \frac{-4 \cdot \frac{{a}^{3} \cdot {c}^{3}}{{b}^{5}} + \left(-2 \cdot \frac{a \cdot c}{b} + -2 \cdot \left(\frac{\color{blue}{\sqrt[3]{{a}^{3}}} \cdot c}{\sqrt{{b}^{3}}} \cdot \sqrt{\frac{{a}^{2} \cdot {c}^{2}}{{b}^{3}}}\right)\right)}{a \cdot 2} \]
    11. rem-cbrt-cube87.7%

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

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

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

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

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

    \[\leadsto \frac{-4 \cdot \frac{{c}^{3} \cdot {a}^{3}}{{b}^{5}} + \left(-2 \cdot \frac{a \cdot c}{b} + -2 \cdot \left(\frac{a \cdot c}{b} \cdot \frac{a \cdot c}{{b}^{2}}\right)\right)}{a \cdot 2} \]
  9. Add Preprocessing

Alternative 4: 85.2% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2} \leq -0.00075:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -7.5000000000000002e-4

    1. Initial program 76.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. *-commutative76.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.5000000000000002e-4 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))

    1. Initial program 39.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. *-commutative39.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto -1 \cdot \left(\frac{c}{b} + a \cdot \color{blue}{\left(\frac{c}{b} \cdot \frac{c}{{b}^{2}}\right)}\right) \]
    10. Step-by-step derivation
      1. associate-*l/93.4%

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

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

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

Alternative 5: 85.1% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.00075:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -7.5000000000000002e-4

    1. Initial program 76.8%

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

    if -7.5000000000000002e-4 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))

    1. Initial program 39.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. *-commutative39.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto -1 \cdot \left(\frac{c}{b} + a \cdot \color{blue}{\left(\frac{c}{b} \cdot \frac{c}{{b}^{2}}\right)}\right) \]
    10. Step-by-step derivation
      1. associate-*l/93.4%

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

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

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

Alternative 6: 81.3% accurate, 1.0× speedup?

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

\\
a \cdot \frac{\frac{c}{{b}^{2}} \cdot \left(-c\right)}{b} - \frac{c}{b}
\end{array}
Derivation
  1. Initial program 55.4%

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

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

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

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

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

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

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

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

      \[\leadsto -1 \cdot \left(\frac{c}{b} + a \cdot \frac{c \cdot c}{\color{blue}{b \cdot \left(b \cdot b\right)}}\right) \]
    3. times-frac82.0%

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

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

    \[\leadsto -1 \cdot \left(\frac{c}{b} + a \cdot \color{blue}{\left(\frac{c}{b} \cdot \frac{c}{{b}^{2}}\right)}\right) \]
  10. Step-by-step derivation
    1. associate-*l/82.0%

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

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

    \[\leadsto a \cdot \frac{\frac{c}{{b}^{2}} \cdot \left(-c\right)}{b} - \frac{c}{b} \]
  13. Add Preprocessing

Alternative 7: 64.2% 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(c / Float64(-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 55.4%

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

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

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

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

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

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

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

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

Reproduce

?
herbie shell --seed 2024050 
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))