Cubic critical, medium range

Percentage Accurate: 31.6% → 99.0%
Time: 10.8s
Alternatives: 5
Speedup: 2.9×

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

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \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: 31.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.0% accurate, 0.7× speedup?

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

\\
\left(0.3333333333333333 \cdot \frac{c \cdot \left(3 \cdot a\right)}{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} + b}\right) \cdot \frac{-1}{a}
\end{array}
Derivation
  1. Initial program 31.2%

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

    \[\leadsto \color{blue}{\frac{-1}{a} \cdot \left(\left(b - \sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)}\right) \cdot 0.3333333333333333\right)} \]
  4. Step-by-step derivation
    1. lift-fma.f64N/A

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

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\color{blue}{b \cdot b + \left(-3 \cdot c\right) \cdot a}}\right) \cdot \frac{1}{3}\right) \]
    3. lift-*.f64N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\color{blue}{b \cdot b} + \left(-3 \cdot c\right) \cdot a}\right) \cdot \frac{1}{3}\right) \]
    4. lower-fma.f64N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\color{blue}{\mathsf{fma}\left(b, b, \left(-3 \cdot c\right) \cdot a\right)}}\right) \cdot \frac{1}{3}\right) \]
    5. lift-*.f64N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(-3 \cdot c\right)} \cdot a\right)}\right) \cdot \frac{1}{3}\right) \]
    6. associate-*l*N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\mathsf{fma}\left(b, b, \color{blue}{-3 \cdot \left(c \cdot a\right)}\right)}\right) \cdot \frac{1}{3}\right) \]
    7. lift-*.f64N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\mathsf{fma}\left(b, b, -3 \cdot \color{blue}{\left(c \cdot a\right)}\right)}\right) \cdot \frac{1}{3}\right) \]
    8. *-commutativeN/A

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot -3}\right)}\right) \cdot \frac{1}{3}\right) \]
    9. lower-*.f6431.3

      \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot -3}\right)}\right) \cdot 0.3333333333333333\right) \]
  5. Applied rewrites31.3%

    \[\leadsto \frac{-1}{a} \cdot \left(\left(b - \sqrt{\color{blue}{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)}}\right) \cdot 0.3333333333333333\right) \]
  6. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\color{blue}{\left(b - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)}\right)} \cdot \frac{1}{3}\right) \]
    2. flip--N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\color{blue}{\frac{b \cdot b - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)} \cdot \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)}}} \cdot \frac{1}{3}\right) \]
    3. lower-/.f64N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\color{blue}{\frac{b \cdot b - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)} \cdot \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)}}} \cdot \frac{1}{3}\right) \]
  7. Applied rewrites31.8%

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

    \[\leadsto \frac{-1}{a} \cdot \left(\frac{\color{blue}{3 \cdot \left(a \cdot c\right)}}{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} + b} \cdot \frac{1}{3}\right) \]
  9. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\frac{\color{blue}{\left(3 \cdot a\right) \cdot c}}{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} + b} \cdot \frac{1}{3}\right) \]
    2. lower-*.f64N/A

      \[\leadsto \frac{-1}{a} \cdot \left(\frac{\color{blue}{\left(3 \cdot a\right) \cdot c}}{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} + b} \cdot \frac{1}{3}\right) \]
    3. lower-*.f6499.0

      \[\leadsto \frac{-1}{a} \cdot \left(\frac{\color{blue}{\left(3 \cdot a\right)} \cdot c}{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} + b} \cdot 0.3333333333333333\right) \]
  10. Applied rewrites99.0%

    \[\leadsto \frac{-1}{a} \cdot \left(\frac{\color{blue}{\left(3 \cdot a\right) \cdot c}}{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} + b} \cdot 0.3333333333333333\right) \]
  11. Final simplification99.0%

    \[\leadsto \left(0.3333333333333333 \cdot \frac{c \cdot \left(3 \cdot a\right)}{\sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)} + b}\right) \cdot \frac{-1}{a} \]
  12. Add Preprocessing

Alternative 2: 91.0% accurate, 1.0× speedup?

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

\\
\frac{1}{\frac{\mathsf{fma}\left(-2, b, \left(\frac{c}{b} \cdot a\right) \cdot 1.5\right)}{c}}
\end{array}
Derivation
  1. Initial program 31.2%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Taylor expanded in b around inf

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot {b}^{2}}}}{3 \cdot a} \]
    2. unpow2N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot \color{blue}{\left(b \cdot b\right)}}}{3 \cdot a} \]
    3. associate-*r*N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot b\right) \cdot b}}}{3 \cdot a} \]
    4. lower-*.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot b\right) \cdot b}}}{3 \cdot a} \]
    5. lower-*.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot b\right)} \cdot b}}{3 \cdot a} \]
    6. +-commutativeN/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\color{blue}{\left(-3 \cdot \frac{a \cdot c}{{b}^{2}} + 1\right)} \cdot b\right) \cdot b}}{3 \cdot a} \]
    7. *-commutativeN/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\left(\color{blue}{\frac{a \cdot c}{{b}^{2}} \cdot -3} + 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    8. lower-fma.f64N/A

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{a \cdot c}{\color{blue}{b \cdot b}}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    10. associate-/r*N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\color{blue}{\frac{\frac{a \cdot c}{b}}{b}}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    11. lower-/.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\color{blue}{\frac{\frac{a \cdot c}{b}}{b}}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    12. lower-/.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\color{blue}{\frac{a \cdot c}{b}}}{b}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    13. *-commutativeN/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{\color{blue}{c \cdot a}}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    14. lower-*.f6431.2

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

    \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}{3 \cdot a} \]
  6. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{3 \cdot a}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    3. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{3 \cdot a}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    4. lower-/.f6431.2

      \[\leadsto \frac{1}{\color{blue}{\frac{3 \cdot a}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    5. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\color{blue}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    6. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\color{blue}{\sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b} + \left(-b\right)}}} \]
    7. lift-neg.f64N/A

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b} + \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
    8. unsub-negN/A

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

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\color{blue}{\sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b} - b}}} \]
  7. Applied rewrites31.2%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{-2 \cdot b + \frac{3}{2} \cdot \frac{a \cdot c}{b}}{c}}} \]
  9. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{-2 \cdot b + \frac{3}{2} \cdot \frac{a \cdot c}{b}}{c}}} \]
    2. lower-fma.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{fma}\left(-2, b, \frac{3}{2} \cdot \frac{a \cdot c}{b}\right)}}{c}} \]
    3. lower-*.f64N/A

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

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(-2, b, \frac{3}{2} \cdot \color{blue}{\left(a \cdot \frac{c}{b}\right)}\right)}{c}} \]
    5. lower-*.f64N/A

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(-2, b, \frac{3}{2} \cdot \color{blue}{\left(a \cdot \frac{c}{b}\right)}\right)}{c}} \]
    6. lower-/.f6490.6

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(-2, b, 1.5 \cdot \left(a \cdot \color{blue}{\frac{c}{b}}\right)\right)}{c}} \]
  10. Applied rewrites90.6%

    \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{fma}\left(-2, b, 1.5 \cdot \left(a \cdot \frac{c}{b}\right)\right)}{c}}} \]
  11. Final simplification90.6%

    \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(-2, b, \left(\frac{c}{b} \cdot a\right) \cdot 1.5\right)}{c}} \]
  12. Add Preprocessing

Alternative 3: 91.0% accurate, 1.1× speedup?

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

\\
\frac{1}{\mathsf{fma}\left(\frac{b}{c}, -2, \frac{a}{b} \cdot 1.5\right)}
\end{array}
Derivation
  1. Initial program 31.2%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Taylor expanded in b around inf

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot {b}^{2}}}}{3 \cdot a} \]
    2. unpow2N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot \color{blue}{\left(b \cdot b\right)}}}{3 \cdot a} \]
    3. associate-*r*N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot b\right) \cdot b}}}{3 \cdot a} \]
    4. lower-*.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot b\right) \cdot b}}}{3 \cdot a} \]
    5. lower-*.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\left(1 + -3 \cdot \frac{a \cdot c}{{b}^{2}}\right) \cdot b\right)} \cdot b}}{3 \cdot a} \]
    6. +-commutativeN/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\color{blue}{\left(-3 \cdot \frac{a \cdot c}{{b}^{2}} + 1\right)} \cdot b\right) \cdot b}}{3 \cdot a} \]
    7. *-commutativeN/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\left(\color{blue}{\frac{a \cdot c}{{b}^{2}} \cdot -3} + 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    8. lower-fma.f64N/A

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{a \cdot c}{\color{blue}{b \cdot b}}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    10. associate-/r*N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\color{blue}{\frac{\frac{a \cdot c}{b}}{b}}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    11. lower-/.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\color{blue}{\frac{\frac{a \cdot c}{b}}{b}}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    12. lower-/.f64N/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\color{blue}{\frac{a \cdot c}{b}}}{b}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    13. *-commutativeN/A

      \[\leadsto \frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{\color{blue}{c \cdot a}}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a} \]
    14. lower-*.f6431.2

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

    \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}{3 \cdot a} \]
  6. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}{3 \cdot a}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{3 \cdot a}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    3. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{3 \cdot a}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    4. lower-/.f6431.2

      \[\leadsto \frac{1}{\color{blue}{\frac{3 \cdot a}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    5. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\color{blue}{\left(-b\right) + \sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b}}}} \]
    6. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\color{blue}{\sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b} + \left(-b\right)}}} \]
    7. lift-neg.f64N/A

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b} + \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
    8. unsub-negN/A

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

      \[\leadsto \frac{1}{\frac{3 \cdot a}{\color{blue}{\sqrt{\left(\mathsf{fma}\left(\frac{\frac{c \cdot a}{b}}{b}, -3, 1\right) \cdot b\right) \cdot b} - b}}} \]
  7. Applied rewrites31.2%

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

    \[\leadsto \frac{1}{\color{blue}{-2 \cdot \frac{b}{c} + \frac{3}{2} \cdot \frac{a}{b}}} \]
  9. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{b}{c} \cdot -2} + \frac{3}{2} \cdot \frac{a}{b}} \]
    2. lower-fma.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{b}{c}, -2, \frac{3}{2} \cdot \frac{a}{b}\right)}} \]
    3. lower-/.f64N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\frac{b}{c}}, -2, \frac{3}{2} \cdot \frac{a}{b}\right)} \]
    4. lower-*.f64N/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{b}{c}, -2, \color{blue}{\frac{3}{2} \cdot \frac{a}{b}}\right)} \]
    5. lower-/.f6490.5

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{b}{c}, -2, 1.5 \cdot \color{blue}{\frac{a}{b}}\right)} \]
  10. Applied rewrites90.5%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{b}{c}, -2, 1.5 \cdot \frac{a}{b}\right)}} \]
  11. Final simplification90.5%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{b}{c}, -2, \frac{a}{b} \cdot 1.5\right)} \]
  12. Add Preprocessing

Alternative 4: 81.2% accurate, 2.9× speedup?

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

\\
-0.5 \cdot \frac{c}{b}
\end{array}
Derivation
  1. Initial program 31.2%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-1}{2}} \]
    2. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-1}{2}} \]
    3. lower-/.f6481.3

      \[\leadsto \color{blue}{\frac{c}{b}} \cdot -0.5 \]
  5. Applied rewrites81.3%

    \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
  6. Final simplification81.3%

    \[\leadsto -0.5 \cdot \frac{c}{b} \]
  7. Add Preprocessing

Alternative 5: 81.0% accurate, 2.9× speedup?

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

\\
\frac{-0.5}{b} \cdot c
\end{array}
Derivation
  1. Initial program 31.2%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Taylor expanded in c around 0

    \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-1}{2}} \]
    2. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-1}{2}} \]
    3. lower-/.f6481.3

      \[\leadsto \color{blue}{\frac{c}{b}} \cdot -0.5 \]
  5. Applied rewrites81.3%

    \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
  6. Step-by-step derivation
    1. Applied rewrites81.0%

      \[\leadsto c \cdot \color{blue}{\frac{-0.5}{b}} \]
    2. Final simplification81.0%

      \[\leadsto \frac{-0.5}{b} \cdot c \]
    3. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2024278 
    (FPCore (a b c)
      :name "Cubic critical, 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) (* (* 3.0 a) c)))) (* 3.0 a)))