?

Average Error: 52.5 → 0.1
Time: 13.2s
Precision: binary64
Cost: 7296

?

\[\left(\left(4.930380657631324 \cdot 10^{-32} < a \land a < 2.028240960365167 \cdot 10^{+31}\right) \land \left(4.930380657631324 \cdot 10^{-32} < b \land b < 2.028240960365167 \cdot 10^{+31}\right)\right) \land \left(4.930380657631324 \cdot 10^{-32} < c \land c < 2.028240960365167 \cdot 10^{+31}\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\frac{-c}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (/ (- c) (+ b (sqrt (+ (* b b) (* a (* c -3.0)))))))
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 / (b + sqrt(((b * b) + (a * (c * -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 = (-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 / (b + sqrt(((b * b) + (a * (c * (-3.0d0))))))
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 / (b + Math.sqrt(((b * b) + (a * (c * -3.0)))));
}
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 / (b + math.sqrt(((b * b) + (a * (c * -3.0)))))
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(Float64(-c) / Float64(b + sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -3.0))))))
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 / (b + sqrt(((b * b) + (a * (c * -3.0)))));
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[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\frac{-c}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)}}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 52.5

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

    \[\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]52.5

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

    remove-double-neg [<=]52.5

    \[ \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 [<=]52.5

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

    div-sub [=>]52.6

    \[ \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 [=>]52.6

    \[ \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/ [<=]52.4

    \[ \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 [=>]52.4

    \[ \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 [=>]51.6

    \[ \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 [<=]51.6

    \[ \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 [<=]51.6

    \[ \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* [<=]51.6

    \[ \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 [<=]51.6

    \[ \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 [<=]51.6

    \[ \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 [<=]52.4

    \[ \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 [=>]52.4

    \[ \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-rr52.2

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

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

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

    [Start]52.2

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

    distribute-lft-neg-out [=>]52.2

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

    associate-*r/ [=>]52.2

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

    *-rgt-identity [=>]52.2

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

    distribute-neg-frac [=>]52.2

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

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

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

    [Start]0.6

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

    *-commutative [=>]0.6

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

    distribute-rgt-neg-out [=>]0.6

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

    associate-/r* [=>]0.6

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

    associate-*l/ [=>]0.6

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

    associate-/l/ [<=]0.6

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

    associate-*l/ [<=]0.6

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

    associate-/r* [<=]0.4

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

    associate-*l/ [=>]0.5

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

    associate-*r/ [<=]0.4

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

    associate-*l/ [=>]0.2

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

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

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

Alternatives

Alternative 1
Error3.0
Cost896
\[\frac{-c}{b + \left(b + -1.5 \cdot \frac{c \cdot a}{b}\right)} \]
Alternative 2
Error3.0
Cost896
\[\frac{-c}{-1.5 \cdot \frac{c \cdot a}{b} + b \cdot 2} \]
Alternative 3
Error3.2
Cost832
\[\frac{1}{-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}} \]
Alternative 4
Error6.4
Cost320
\[c \cdot \frac{-0.5}{b} \]
Alternative 5
Error6.2
Cost320
\[\frac{c \cdot -0.5}{b} \]

Error

Reproduce?

herbie shell --seed 2023083 
(FPCore (a b c)
  :name "Cubic critical, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))