Cubic critical, medium range

Percentage Accurate: 31.2% → 99.3%
Time: 9.8s
Alternatives: 6
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 6 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.2% 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.3% accurate, 0.2× speedup?

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

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

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{3}}}{\frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}} \]
    8. lower-/.f6433.6

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

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

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

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

      \[\leadsto \frac{\frac{1}{3}}{\frac{a}{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}}} \]
    13. lower--.f6433.6

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

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

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

    \[\leadsto {\color{blue}{\left(\frac{1}{c}\right)}}^{-1} \cdot {\left(\left(-b\right) - \sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)}\right)}^{-1} \]
  7. Step-by-step derivation
    1. lower-/.f6499.4

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

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

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

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

      \[\leadsto {\left(\frac{1}{c}\right)}^{-1} \cdot \color{blue}{{\left(\left(-b\right) - \sqrt{\mathsf{fma}\left(-3 \cdot c, a, b \cdot b\right)}\right)}^{-1}} \]
    4. pow-prod-downN/A

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

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

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

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

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

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

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

Alternative 2: 99.1% accurate, 0.8× speedup?

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

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

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{3}}}{\frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}} \]
    8. lower-/.f6433.6

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

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

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

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

      \[\leadsto \frac{\frac{1}{3}}{\frac{a}{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}}} \]
    13. lower--.f6433.6

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

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

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

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

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

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

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

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

Alternative 3: 99.1% accurate, 0.8× speedup?

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

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

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{3}}}{\frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}} \]
    8. lower-/.f6433.6

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

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

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

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

      \[\leadsto \frac{\frac{1}{3}}{\frac{a}{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}}} \]
    13. lower--.f6433.6

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 90.7% accurate, 1.0× speedup?

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

\\
\frac{0.3333333333333333}{\mathsf{fma}\left(\frac{a}{b \cdot b}, 0.5, \frac{-0.6666666666666666}{c}\right) \cdot b}
\end{array}
Derivation
  1. Initial program 33.6%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{3}}}{\frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}} \]
    8. lower-/.f6433.6

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

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

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

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

      \[\leadsto \frac{\frac{1}{3}}{\frac{a}{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}}} \]
    13. lower--.f6433.6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{0.3333333333333333}{\mathsf{fma}\left(\frac{a}{b \cdot b}, 0.5, \color{blue}{\frac{-0.6666666666666666}{c}}\right) \cdot b} \]
  7. Applied rewrites90.6%

    \[\leadsto \frac{0.3333333333333333}{\color{blue}{\mathsf{fma}\left(\frac{a}{b \cdot b}, 0.5, \frac{-0.6666666666666666}{c}\right) \cdot b}} \]
  8. Add Preprocessing

Alternative 5: 90.7% accurate, 1.1× speedup?

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

\\
\frac{0.3333333333333333}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.6666666666666666\right)}
\end{array}
Derivation
  1. Initial program 33.6%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{3}}}{\frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}} \]
    8. lower-/.f6433.6

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

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

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

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

      \[\leadsto \frac{\frac{1}{3}}{\frac{a}{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}}} \]
    13. lower--.f6433.6

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{0.3333333333333333}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \color{blue}{\frac{b}{c}} \cdot -0.6666666666666666\right)} \]
  7. Applied rewrites90.6%

    \[\leadsto \frac{0.3333333333333333}{\color{blue}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.6666666666666666\right)}} \]
  8. Add Preprocessing

Alternative 6: 81.4% 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 33.6%

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

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

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

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

    \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2024307 
(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)))