Average Error: 43.6 → 0.2
Time: 15.3s
Precision: binary64
Cost: 7296
\[\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)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\frac{c}{\left(-\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right) - b} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (/ c (- (- (sqrt (+ (* b b) (* a (* c -3.0))))) b)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
	return c / (-sqrt(((b * b) + (a * (c * -3.0)))) - b);
}
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
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = c / (-sqrt(((b * b) + (a * (c * (-3.0d0))))) - b)
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);
}
public static double code(double a, double b, double c) {
	return c / (-Math.sqrt(((b * b) + (a * (c * -3.0)))) - b);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c):
	return c / (-math.sqrt(((b * b) + (a * (c * -3.0)))) - b)
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 code(a, b, c)
	return Float64(c / Float64(Float64(-sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -3.0))))) - b))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
end
function tmp = code(a, b, c)
	tmp = c / (-sqrt(((b * b) + (a * (c * -3.0)))) - b);
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]
code[a_, b_, c_] := N[(c / N[((-N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) - b), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{c}{\left(-\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}\right) - b}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 43.6

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Simplified43.6

    \[\leadsto \color{blue}{\left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{-0.3333333333333333}{a}} \]
    Proof

    [Start]43.6

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

    remove-double-neg [<=]43.6

    \[ \frac{\left(-b\right) + \color{blue}{\left(-\left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)\right)}}{3 \cdot a} \]

    sub-neg [<=]43.6

    \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a} \]

    div-sub [=>]43.9

    \[ \color{blue}{\frac{-b}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}} \]

    neg-mul-1 [=>]43.9

    \[ \frac{\color{blue}{-1 \cdot b}}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]

    associate-*l/ [<=]43.7

    \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot b} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]

    distribute-frac-neg [=>]43.7

    \[ \frac{-1}{3 \cdot a} \cdot b - \color{blue}{\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)} \]

    fma-neg [=>]42.8

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

    /-rgt-identity [<=]42.8

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

    metadata-eval [<=]42.8

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

    associate-/l* [<=]42.8

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

    *-commutative [<=]42.8

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

    neg-mul-1 [<=]42.8

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

    fma-neg [<=]43.7

    \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)} \]

    neg-mul-1 [=>]43.7

    \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{-1 \cdot \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}} \]
  3. Applied egg-rr43.0

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

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

    [Start]43.0

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

    associate-/r* [=>]43.0

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

    neg-sub0 [=>]43.0

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

    +-commutative [=>]43.0

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

    associate--r+ [=>]43.0

    \[ \frac{\frac{-\left(b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}{a \cdot -3}}{\color{blue}{\left(0 - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) - b}} \]

    neg-sub0 [<=]43.0

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

    \[\leadsto \frac{\color{blue}{c}}{\left(-\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) - b} \]
  6. Applied egg-rr0.2

    \[\leadsto \frac{c}{\left(-\sqrt{\color{blue}{b \cdot b + a \cdot \left(c \cdot -3\right)}}\right) - b} \]
  7. Final simplification0.2

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

Alternatives

Alternative 1
Error5.7
Cost832
\[\frac{c}{1.5 \cdot \frac{c \cdot a}{b} + b \cdot -2} \]
Alternative 2
Error12.2
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce

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